/* ===== Theme ===== */
:root {
  --left-w: 240px;
  --left-w-collapsed: 56px;
  --right-w: 260px;
  --right-w-collapsed: 0px;

  --card-bg: #0b1020;
  --text: #f0f0f0;
  --accent: #ffb347;
  --blue-accent: #76a8ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #232526 0%, #414345 100%);
}

/* ===== Sidebars ===== */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--left-w);
  background: #232526;
  color: #fff;
  padding: 1rem;
  overflow-y: auto;
  border-right: 2px solid #444;
  z-index: 900;
}
.sidebar.right {
  right: 0;
  left: auto;
  width: var(--right-w);
  border-right: none;
  border-left: 2px solid #444;
}
#left-sidebar.collapsed { width: var(--left-w-collapsed); }
#right-sidebar.collapsed { width: var(--right-w-collapsed); }

.sidebar h3 { color: var(--accent); margin: 0 0 .5rem; }
.sidebar .muted { opacity: .7; margin: .25rem 0 1rem; }
.sidebar a {
  color: #fff;
  text-decoration: none;
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
}
.sidebar a:hover { background: var(--accent); color: #232526; }
.panel-box { background: #1b2437; border: 1px solid #2b3550; border-radius: 10px; padding: .75rem; }

/* Toggles */
.sidebar-toggle {
  position: fixed; top: 10px; z-index: 1000;
  background: #101522; color: #ffd769;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px; padding: 6px 10px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.sidebar-toggle.left { left: 80px; }
.sidebar-toggle.right { right: 10px; }

/* ===== Grid ===== */
.dashboard {
  margin-left: var(--left-w);
  margin-right: var(--right-w);
  padding: 2rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
body.left-collapsed .dashboard { margin-left: var(--left-w-collapsed); }
body.right-collapsed .dashboard { margin-right: var(--right-w-collapsed); }

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
    margin: 0;
    padding: 1rem;
  }
  #left-sidebar, #right-sidebar { width: 0; }
}

/* Make every direct child of .dashboard span the full grid width */
.dashboard > * { grid-column: 1 / -1 !important; }
/* Optional utility to make a card half width again */
.dashboard > .half { grid-column: span 1 !important; }

/* ===== Widgets ===== */
.widget {
  background-color: #171945;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  transition: box-shadow 0.3s ease, transform .2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.widget:hover { box-shadow: 0 4px 16px #ffb34799; transform: translateY(-2px) scale(1.01); }
.widget.wide { grid-column: 1 / -1; }

.widget h4 {
  color: var(--accent);
  margin: 0 0 .6rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}
#electric-widget h4 { color: #2f7dd3; }
#tgas-widget h4,
#gas-widget h4 { color: var(--accent); }

.widget .muted { opacity: .8; }
.widget .center { display: grid; place-items: center; min-height: 120px; }
.big-emoji { font-size: 2.25rem; }

/* Notes */
.notes {
  width: 100%;
  background: #232a39;
  color: #e6ecff;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 10px;
}

/* Status pills */
.status-row { display: flex; flex-wrap: wrap; gap: 10px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: #1b2437; color: #e2e8f0;
  border: 1px solid rgba(148,163,184,.25);
  border-radius: 999px; padding: 6px 10px; font-weight: 600; font-size: .85rem;
}
.status-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: #64748b; }
.status-pill.none { border-color: #22c55e66; }
.status-pill.none .dot { background: #22c55e; }
.status-pill.minor { border-color: #f59e0b66; }
.status-pill.minor .dot { background: #f59e0b; }
.status-pill.major { border-color: #f9731666; }
.status-pill.major .dot { background: #f97316; }
.status-pill.critical { border-color: #ef444466; }
.status-pill.critical .dot { background: #ef4444; }

/* Footer */
.site-footer { position: sticky; bottom: 0; margin: 1rem; text-align: center; opacity: .75; }

/* Canvas */
canvas { display: block; margin-bottom: 16px; max-width: 100%; }

/* Toggle */
.widget-toggle {
  display: flex; align-items: center; justify-content: flex-end; margin-bottom: 1rem;
  color: #a2a9b4; font-size: .95rem;
}
.toggle-switch { position: relative; width: 40px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc; transition: 0.4s; border-radius: 20px; pointer-events: none;
}
.slider:before {
  position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px;
  background-color: white; transition: 0.4s; border-radius: 50%;
}
input:checked + .slider { background-color: #4CAF50; }
input:checked + .slider:before { transform: translateX(20px); }

/* =========================================
   Other-Site Theme Override (drop in)
   ========================================= */
:root {
  --bg-1: #1f232a;
  --bg-2: #2a2f36;

  --surface-1: #1d232b;
  --surface-2: #252c35;
  --border:    #353c45;

  --text:        #e6e8ed;
  --text-muted:  #a2a9b4;

  --accent:  #f0a33e;
  --primary: #2f7dd3;

  --shadow: 0 10px 28px rgba(0,0,0,.35);
  --card-radius: 12px;
}

body { background: linear-gradient(135deg, var(--bg-1), var(--bg-2)); color: var(--text); }

.sidebar {
  background: color-mix(in oklab, var(--surface-1) 88%, black 12%);
  border-right: 1px solid var(--border);
}
.sidebar.right { border-left: 1px solid var(--border); border-right: none; }
.sidebar h3 { color: var(--accent); }
.sidebar a { color: var(--text); border: 1px solid transparent; }
.sidebar a:hover {
  background: color-mix(in oklab, var(--accent) 16%, transparent);
  color: #111;
  border-color: color-mix(in oklab, var(--accent) 32%, transparent);
}

.widget {
  background: linear-gradient(
    180deg,
    color-mix(in oklab, var(--surface-1) 90%, black 10%),
    color-mix(in oklab, var(--surface-2) 86%, black 14%)
  );
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
}
.widget:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 42px rgba(0,0,0,.45);
  border-color: color-mix(in oklab, var(--accent) 50%, var(--border));
}

/* ===== Dark table palette ===== */
:root {
  --table-bg:       #0a153d;
  --table-head-bg:  #1a2146;
  --table-hover-bg: #16204a;
  --table-text:     #eaf2ff;
  --table-muted:    #aab7d0;
  --table-border:   #2a3760;
}

/* ===== Data tables (single, compact, dark) ===== */
.data-table { font-size: .9rem; margin-top: 8px; overflow-x: auto; }
.data-table table {
  width: 100%;
  border: 1px solid var(--table-border) !important;
  background: var(--table-bg) !important;
  border-radius: 10px;
  overflow: hidden;
  border-collapse: collapse;
  table-layout: fixed;       /* compact widths */
  white-space: nowrap;       /* keep numbers tidy */
}
.data-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--table-head-bg) !important;
  color: var(--table-text) !important;
  border-bottom: 1px solid var(--table-border) !important;
  text-align: left;
  font-weight: 600;
  padding: .4rem .5rem;
}
.data-table th,
.data-table td {
  padding: .4rem .5rem;
  border-bottom: 1px solid var(--table-border) !important;
  color: var(--table-text) !important;
  text-align: center;
}
.data-table tbody tr,
.data-table tbody tr:nth-child(even),
.data-table tbody tr:nth-child(odd) {
  background: var(--table-bg) !important;
}
.data-table tbody tr:hover { background: var(--table-hover-bg) !important; }

.data-table .table-note {
  margin: .35rem 0 0;
  font-size: .95rem;
  line-height: 1.35;
  color: var(--table-muted);
}
.data-table .table-note strong { color: var(--table-text); }

/* ===== Chart + table layout ===== */
/* Wider chart, slimmer table */
.chart-table-pair {
  display: grid;
  grid-template-columns: minmax(420px, 2fr) minmax(260px, 1fr); /* ~66/34 */
  gap: 16px;
  align-items: stretch;
}
.chart-table-pair > * { min-height: 100%; }

@media (min-width: 1400px) {
  .chart-table-pair {
    grid-template-columns: minmax(560px, 2.5fr) minmax(300px, 1fr); /* ~71/29 */
  }
}

@media (max-width: 900px) {
  .chart-table-pair { grid-template-columns: 1fr; }
}

/* Weather tables: explicit narrower column widths */
#weather-ph-table table,
#weather-tr-table table { table-layout: fixed; }

#weather-ph-table thead th:nth-child(1),
#weather-tr-table thead th:nth-child(1) { width: 48%; }  /* Date */
#weather-ph-table thead th:nth-child(2),
#weather-tr-table thead th:nth-child(2) { width: 26%; }  /* Metric 1 */
#weather-ph-table thead th:nth-child(3),
#weather-tr-table thead th:nth-child(3) { width: 26%; }  /* Metric 2 */

/* City Extremes grid/cards */
.city-extremes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.city-card {
  background: linear-gradient(
    180deg,
    color-mix(in oklab, var(--surface-1, #1d232b) 90%, black 10%),
    color-mix(in oklab, var(--surface-2, #252c35) 86%, black 14%)
  );
  border: 1px solid var(--border, #353c45);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow, 0 10px 28px rgba(0,0,0,.35));
}

.city-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .35rem;
}
.city-name { font-weight: 700; color: var(--text, #e6e8ed); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: .75rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--border, #353c45) 70%, transparent);
  background: color-mix(in oklab, var(--surface-2, #252c35) 80%, transparent);
  color: var(--text, #e6e8ed);
}
.pill.hot  { border-color: #ef4444aa; color: #fecaca; }
.pill.cold { border-color: #60a5faaa; color: #bfdbfe; }

.split-rows { display: grid; gap: 6px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: baseline;
  border-bottom: 1px dashed color-mix(in oklab, var(--border, #353c45) 60%, transparent);
  padding-bottom: 6px;
}
.row:last-child { border-bottom: none; padding-bottom: 0; }

.k { color: var(--text-muted, #a2a9b4); }
.v { color: var(--text, #e6e8ed); font-weight: 600; }
.v.hot  { color: #fecaca; }
.v.cold { color: #bfdbfe; }
.v.emphasis { font-size: 1.05rem; }
.d { color: var(--text-muted, #a2a9b4); font-size: .85rem; }

/* ==== City Extremes cards ==== */
.city-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.city-card {
  background: var(--surface-1, #1d232b);
  border: 1px solid var(--border, #353c45);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow, 0 10px 28px rgba(0,0,0,.35));
  transition: transform .15s ease, box-shadow .15s ease, border-color .2s ease;
}

.city-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 42px rgba(0,0,0,.45);
  border-color: color-mix(in oklab, var(--accent, #f0a33e) 40%, var(--border, #353c45));
}

.city-card header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.city-card .name {
  font-weight: 700;
  line-height: 1.1;
}

.city-card .pill {
  border: 1px solid var(--border, #353c45);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.city-card.hot .pill  { border-color: #f97316; } /* warm/hot edge */
.city-card.cold .pill { border-color: #60a5fa; }

.city-card .row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  font-size: .95rem;
}

.city-card .row .k { opacity: .8; }
.city-card .row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.city-card .row .d { opacity: .75; font-variant-numeric: tabular-nums; }

.city-card footer {
  opacity: .7;
  font-size: .85rem;
  margin-top: 6px;
}
/* Water Widget */
#water-widget { padding: 1rem; border-radius: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.08); }
#water-widget h4 { margin: 0 0 .75rem; }

#water-widget .ww-summary {
  display: grid; gap: .5rem 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: .75rem;
}
#water-widget .ww-k { opacity: .75; margin-right: .25rem; }

#water-widget .ww-add {
  display: grid; gap: .75rem; align-items: end;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) auto;
}
#water-widget .ww-msg { min-height: 1.2em; font-size: .9rem; opacity: .9; }

#water-widget .ww-table-wrap { overflow-x: auto; margin-top: .75rem; }
#water-widget .ww-table { width: 100%; border-collapse: collapse; }
#water-widget .ww-table th, #water-widget .ww-table td {
  padding: .5rem .6rem; border-bottom: 1px solid rgba(0,0,0,.08); text-align: right;
}
#water-widget .ww-table th:first-child, #water-widget .ww-table td:first-child { text-align: left; }

#water-widget .ww-btn { padding: .5rem .8rem; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
#water-widget .ww-btn:hover { opacity: .95; }

#water-widget details.ww-tariff summary { cursor: pointer; font-weight: 600; margin-top: .5rem; }
#water-widget .ww-grid { display: grid; gap: .25rem .75rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

@media (prefers-color-scheme: dark) {
  #water-widget { box-shadow: 0 8px 24px rgba(0,0,0,.35); }
  #water-widget .ww-table th, #water-widget .ww-table td { border-bottom-color: rgba(255,255,255,.08); }
}
/* --- Layout: put the "Add reading" button under the meter input --- */
#water-widget .ww-add {
  /* 2 columns: Date | Meter reading */
  grid-template-columns: 220px 1fr;
}

/* Make the button sit under the meter input (column 2), not full width */
#water-widget #ww-add {
  grid-column: 2;              /* under the meter input column */
  justify-self: start;         /* left align */
  width: auto;                 /* no stretching */
  min-width: 140px;
}

/* Mobile: stack nicely; let the button go full row if narrow */
@media (max-width: 560px) {
  #water-widget .ww-add { grid-template-columns: 1fr; }
  #water-widget #ww-add { grid-column: 1; justify-self: stretch; }
}

/* --- Style inputs: darkish blue boxes --- */
#water-widget input[type="date"],
#water-widget input[type="number"] {
  background: #0f2742;         /* dark blue */
  color: #e8f1ff;              /* light text */
  border: 1px solid #2a4a6c;
  border-radius: 10px;
  padding: .55rem .7rem;
  outline: none;
}

#water-widget input[type="date"]::placeholder,
#water-widget input[type="number"]::placeholder {
  color: #a7bfdc;
}

/* calendar icon visible on dark background (Chromium/WebKit) */
#water-widget input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(90%);
  opacity: .9;
}

/* focus state */
#water-widget input[type="date"]:focus,
#water-widget input[type="number"]:focus {
  border-color: #3c79c8;
  box-shadow: 0 0 0 3px rgba(60,121,200,.25);
}

/* Optional: match button to theme a bit */
#water-widget .ww-btn {
  background: #1f3a5a;
  color: #fff;
  border: 1px solid #335a86;
}
#water-widget .ww-btn:hover { filter: brightness(1.05); }
#water-widget .ww-summary .ww-forecast,
#water-widget .ww-summary .ww-dd {
  grid-column: 1 / -1;      /* span full width */
}
