/* Octopus Energy Theme - Shared Stylesheet */

/* Environment Banner */
.env-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.env-banner.local {
  display: block;
  background: #eb56d2;
  color: #000;
}

.env-banner.dev {
  display: block;
  background: #5ac098;
  color: #000;
}

:root {
  /* Octopus Purple Theme */
  --octo-purple: #2c0b8e;
  --octo-purple-light: #4a1db3;
  --octo-purple-dark: #1a0654;
  --octo-pink: #eb56d2;
  --octo-pink-hover: #d43dbd;
  
  /* Dark theme colors */
  --bg: #0d004c;
  --bg-dark: #0b0b0d;
  --panel: #141417;
  --text: #ffffff;
  --text-muted: #d6d6ff;
  --text-secondary: #a9a9b5;
  
  /* UI elements */
  --chip: #1f1f24;
  --edge: rgba(255, 255, 255, 0.15);
  --edge-light: rgba(255, 255, 255, 0.3);
  
  /* Status colors */
  --off-peak: #5ac098;
  --off-peak-border: #6dd4ad;
  --smart-charge: #e879d9;
  --smart-charge-border: #f49ee8;
  --purple-highlight: rgba(139, 92, 246, 0.15);
  --purple-border: #8b5cf6;
  --error: #ef4444;
  --success: #10b981;
  --cyan: #89edf6;
  --cyan-dark: #5ac7d6;
}

/* Base styles */
* {
  box-sizing: border-box;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  margin: 0;
  padding: 0;
}

/* Layout */
.wrap {
  max-width: 1400px;
  margin: 36px auto;
  padding: 0 16px;
}

/* Typography */
h1 {
  font-size: 46px;
  margin: 0 0 18px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
}

h2 {
  font-size: 32px;
  margin: 0 0 14px;
  font-weight: 700;
  color: var(--text);
}

h3 {
  font-size: 24px;
  margin: 0 0 10px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Cards and panels */
.card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  padding: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 14px 16px;
}

/* Toolbar */
.toolbar {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

/* Buttons */
.btn {
  background: var(--chip);
  border: 1px solid var(--edge);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.2s ease;
}

.btn:hover:not(:disabled) {
  background: rgba(44, 11, 142, 0.3);
  border-color: var(--octo-purple);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.icon {
  width: 56px;
  text-align: center;
  font-size: 18px;
  padding: 10px;
}

.btn-primary {
  background: var(--octo-purple);
  border-color: var(--octo-purple);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--octo-pink);
  border-color: var(--octo-pink);
}

/* Form inputs */
input[type="date"],
input[type="number"],
input[type="text"],
select {
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
  border-color: var(--octo-pink);
  box-shadow: 0 0 0 3px rgba(218, 24, 132, 0.35);
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 2px;
  justify-content: center;
}

.chip {
  background: var(--chip);
  border: 1px solid var(--edge);
  padding: 8px 12px;
  border-radius: 999px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.chip b {
  opacity: 0.9;
}

.chip .value {
  font-weight: 800;
}

.chip.total-cost,
.chip.tariff-info {
  background: var(--octo-pink);
  border-color: var(--octo-pink);
  color: white;
  font-weight: 600;
}

.chip.total-cost b,
.chip.tariff-info b {
  opacity: 1;
  color: white;
}

.chip.lowest-rate {
  background: var(--off-peak);
  border-color: var(--off-peak-border);
  color: white;
  font-weight: 600;
}

.chip.lowest-rate b {
  opacity: 1;
  color: white;
}

.chip.highest-rate {
  background: var(--error);
  border-color: var(--error);
  color: white;
  font-weight: 600;
}

.chip.highest-rate b {
  opacity: 1;
  color: white;
}

.chip.average-rate {
  background: var(--cyan);
  border-color: var(--cyan-dark);
  color: #000;
  font-weight: 600;
}

.chip.average-rate b {
  opacity: 1;
  color: #000;
}

/* Tables */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 16px;
  overflow: hidden;
  font-size: 12px;
}

thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--edge);
  font-weight: 600;
  background-color: var(--octo-purple);
}

tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--edge);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #2c0b8e;
  color: #ffffff;
}

/* Disable hover on daily, monthly totals, and smart charging tables */
.daily-totals tbody tr:hover,
.monthly-totals tbody tr:hover,
.smart-charging tbody tr:hover {
  background: inherit;
  color: inherit;
}

/* Table row highlights */
.offpeak {
  background: rgba(90, 192, 152, 1.0) !important;
  color: #000000 !important;
}

.offpeak td {
  border-bottom: 1px solid #5441F5 !important;
}

.override {
  background: rgba(232, 121, 217, 1.0) !important;
  color: #000000 !important;
}

.override td {
  border-bottom: 1px solid #5441F5 !important;
}

.most-expensive {
  background: var(--octo-pink) !important;
  color: #ffffff !important;
}

.most-expensive td {
  border-bottom: 1px solid var(--octo-pink-hover) !important;
}

.cheapest {
  background: rgba(90, 192, 152, 1.0) !important;
  color: #000000 !important;
}

.cheapest td {
  border-bottom: 1px solid #6dd4ad !important;
}

/* Utility classes */
.mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.muted {
  color: var(--text-secondary);
}

.right {
  text-align: right;
}

.loading {
  padding: 20px;
  color: var(--text-secondary);
  text-align: center;
}

.error {
  padding: 16px;
  border: 1px solid #4a1113;
  background: #1b0c0d;
  border-radius: 12px;
  color: #fecaca;
}

.hint {
  color: var(--text-secondary);
  margin: 14px 2px 0;
  font-size: 13px;
}

/* Logo header */
.logo-header {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.logo-header img {
  max-width: 100%;
  height: auto;
}

/* Results display */
.result {
  background: rgba(255, 255, 255, 0.95);
  border: 0;
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
  color: var(--octo-purple);
}

.big {
  font-size: 28px;
  font-weight: 900;
  color: var(--octo-pink);
}

/* Content layout - side by side on desktop */
.content-layout {
  display: grid;
  grid-template-columns: minmax(400px, 600px) 1fr;
  gap: 20px;
  align-items: start;
}

.table-column {
  min-width: 0;
}

.chart-column {
  position: sticky;
  top: 20px;
}

#costChartContainer,
#energyChartContainer {
  margin: 0 !important;
}

/* Responsive design */
@media (max-width: 720px) {
  /* Stack layout on mobile */
  .content-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .chart-column {
    position: static;
  }

  .wrap {
    padding: 12px;
    margin: 12px auto;
  }
  
  h1 {
    font-size: 28px;
    margin: 0 0 12px;
    text-align: center;
  }
  
  .toolbar {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
    justify-content: center;
  }

  /* Make date input full width and centered on mobile */
  .toolbar input[type="date"] {
    order: -1;
    width: 100%;
    text-align: center;
  }

  /* Back and Refresh buttons share same row at top on mobile */
  .toolbar .btn-primary {
    order: -2;
    flex: 1;
    text-align: center;
  }

  .toolbar #refreshBtn {
    order: -2;
    flex: 1;
  }

  .toolbar .btn {
    font-size: 14px;
    padding: 8px 12px;
    text-align: center;
  }

  .toolbar .btn.icon {
    width: 48px;
    padding: 8px;
  }

  /* Month button and controls */
  .toolbar #monthBtn {
    flex: 1;
    min-width: 120px;
  }
  
  /* Chips - more compact on mobile */
  .chips {
    gap: 6px;
    margin: 10px 0;
    justify-content: center;
  }
  
  .chip {
    font-size: 12px;
    padding: 6px 10px;
  }
  
  /* Chart containers - less padding */
  #costChartContainer,
  #energyChartContainer {
    margin: 12px 0 !important;
    padding: 12px !important;
  }
  
  #costChartContainer h3,
  #energyChartContainer h3 {
    font-size: 16px;
    margin: 0 0 10px 0 !important;
  }
  
  .row {
    grid-template-columns: 1fr !important;
  }
  
  .big {
    font-size: 24px;
  }
  
  input, select {
    padding: 12px;
    font-size: 14px;
  }
  
  /* Center date input */
  input[type="date"] {
    text-align: center;
  }
  
  /* Table - smaller on mobile */
  table {
    font-size: 11px;
  }
  
  thead th {
    font-size: 10px;
    padding: 6px 8px;
  }
  
  tbody td {
    padding: 5px 8px;
  }
  
  /* Logo */
  .logo-header {
    margin-bottom: 12px;
  }

  .logo-header img {
    max-width: 60%;
  }

  /* Daily totals - hide tariff column and stack charts */
  .daily-totals div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Make Smart Slots column narrower on mobile */
  .daily-totals #table th:nth-child(7),
  .daily-totals #table td:nth-child(7) {
    width: 40px;
    padding: 5px 4px;
  }

  /* Monthly totals - narrow Smart Slots */
  .monthly-totals #table th:nth-child(7),
  .monthly-totals #table td:nth-child(7) {
    width: 40px;
    padding: 5px 4px;
  }

  /* Yearly totals - narrow Smart Slots */
  .yearly-totals #table th:nth-child(7),
  .yearly-totals #table td:nth-child(7) {
    width: 40px;
    padding: 5px 4px;
  }

  /* Smart charging page date inputs */
  .smart-charging .toolbar input[type="date"] {
    width: auto;
    flex: 1;
    min-width: 100px;
    order: 0;
  }

  .smart-charging .toolbar label {
    order: 0;
    font-size: 13px;
  }

  .smart-charging .toolbar > div[style*="display: flex"] {
    order: 0;
    flex: 1 1 auto;
    min-width: 140px;
  }

  /* Download button before refresh */
  .smart-charging .toolbar #downloadBtn {
    order: 998;
    width: 100%;
  }

  /* Agile comparison panel - stack on mobile */
  #agileComparisonPanel {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  #agileComparisonPanel span {
    margin-left: 0 !important;
  }

  /* Chart containers stack on mobile */
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}

/* Timeline page layout */
.timeline .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
}

/* Mobile: center the toolbar */
@media (max-width: 767px) {
  .timeline .toolbar {
    justify-content: center;
  }

  /* Force agile checkbox to its own row and keep checkbox+text together */
  .timeline .toolbar #agileComparisonPanel {
    width: 100% !important;
    order: 10;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .timeline .toolbar #agileComparisonPanel label {
    font-size: 13px;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Center the Energy button on mobile */
  .timeline .toolbar #toggleEnergyBtn {
    margin-left: 0;
    width: 100%;
  }
}

/* Row 1: Date navigation controls */
.timeline .toolbar #prevBtn {
  order: 0;
}

.timeline .toolbar #dateInput {
  order: 1;
  flex: 0 0 auto;
  width: 160px;
  text-align: center;
}

.timeline .toolbar #nextBtn {
  order: 2;
}

.timeline .toolbar #calendarBtn {
  order: 3;
}

.timeline .toolbar #agileComparisonPanel {
  order: 4;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Spacer to push Energy button to the right */
.timeline .toolbar #calendarBtn::after {
  content: '';
  flex: 1;
  order: 5;
}

/* Toggle energy button right-aligned on same row */
.timeline .toolbar #toggleEnergyBtn {
  order: 6;
  flex: 0 0 auto;
  margin-left: auto;
}

/* Daily totals page layout */
.daily-totals .toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

/* Mobile: center the toolbar */
@media (max-width: 767px) {
  .daily-totals .toolbar {
    justify-content: center;
  }
}

/* Monthly totals page layout */
.monthly-totals .toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

/* Mobile: center the toolbar */
@media (max-width: 767px) {
  .monthly-totals .toolbar {
    justify-content: center;
  }
}

/* Smart charging page layout */
.smart-charging .toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

.smart-charging .toolbar #downloadBtn {
  margin-left: auto;
}

/* Mobile: center the toolbar */
@media (max-width: 767px) {
  .smart-charging .toolbar {
    justify-content: center;
  }

  .smart-charging .toolbar #downloadBtn {
    margin-left: 0;
  }
}

/* Tariff rates page layout - same as smart charging */
body:not(.smart-charging) .toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

body:not(.smart-charging) .toolbar #downloadBtn {
  margin-left: auto;
}

/* Mobile: center the toolbar */
@media (max-width: 767px) {
  body:not(.smart-charging) .toolbar {
    justify-content: center;
  }

  body:not(.smart-charging) .toolbar #downloadBtn {
    margin-left: 0;
  }
}

/* Grid layouts */
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Code elements */
code {
  background: var(--chip);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 13px;
}

/* Agile comparison columns */
.agile-col {
  background: rgba(235, 86, 210, 0.1) !important;
  border-left: 2px solid rgba(235, 86, 210, 0.3) !important;
  border-bottom: 1px solid #5441F5 !important;
}

/* Alternating date rows for smart charging table */
.smart-charging tbody tr.alt-date {
  background: #e879d9 !important;
  color: #000000 !important;
}

.smart-charging tbody tr.alt-date:hover {
  background: #e879d9 !important;
  color: #000000 !important;
}

.smart-charging tbody tr.alt-date td.muted {
  color: #000000 !important;
  opacity: 0.8;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 10000;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  animation: fadeIn 0.2s;
  overflow: hidden;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.modal-content {
  background: var(--panel, #141417);
  border: 1px solid var(--edge, rgba(255, 255, 255, 0.15));
  border-radius: 12px;
  padding: 30px;
  max-width: 500px;
  width: calc(100% - 40px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.3s;
  position: relative;
}

@media (max-width: 768px) {
  .modal-content {
    padding: 24px 20px;
    width: calc(100% - 40px);
    max-width: 400px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.modal-icon {
  font-size: 48px;
  margin-right: 15px;
}

.modal-icon.success {
  color: var(--octo-pink, #eb56d2);
}

.modal-icon.info {
  color: var(--octo-blue, #00bcd4);
}

.modal-icon.error {
  color: #e74c3c;
}

.modal-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text, #ffffff);
}

.modal-body {
  margin-bottom: 20px;
  line-height: 1.6;
  color: var(--text-muted, #d6d6ff);
  white-space: pre-line;
}

.modal-footer {
  text-align: right;
}

.modal-footer .btn-primary {
  background: var(--octo-purple);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-footer .btn-primary:hover {
  background: var(--octo-pink);
}

.modal-footer .btn-secondary {
  background: var(--edge, #333);
  color: var(--text, #fff);
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-footer .btn-secondary:hover {
  background: var(--edge-hover, #444);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
