/* ============================================================
   WattTrack — design tokens & base
   ============================================================ */
:root {
  color-scheme: dark;
  --font-sans: "Inter", "Fira Sans", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Fira Code",
    Menlo, Consolas, monospace;

  --bg: #0a1120;
  --bg-2: #0d1728;
  --surface: #111c2f;
  --surface-2: #16233a;
  --card: #121d31;
  --card-hover: #16243b;
  --text: #eef5ff;
  --text-strong: #ffffff;
  --muted: #93a5c0;
  --muted-2: #6f819e;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.3);
  --accent: #34d399;
  --accent-strong: #10b981;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --accent-ink: #04251a;
  --blue: #60a5fa;
  --blue-soft: rgba(96, 165, 250, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.13);
  --focus: #a7f3d0;
  --shadow-lg: 0 24px 60px -30px rgba(0, 0, 0, 0.85);
  --shadow-md: 0 14px 30px -20px rgba(0, 0, 0, 0.8);
  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --header-h: 64px;
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5fb;
  --bg-2: #e9eff8;
  --surface: #ffffff;
  --surface-2: #eef3fa;
  --card: #ffffff;
  --card-hover: #f8fbff;
  --text: #15233a;
  --text-strong: #071226;
  --muted: #5c6c84;
  --muted-2: #78879c;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.2);
  --accent: #0f9f6e;
  --accent-strong: #0b8a5e;
  --accent-soft: rgba(15, 159, 110, 0.12);
  --accent-ink: #ffffff;
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, 0.1);
  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.1);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.09);
  --focus: #0b8a5e;
  --shadow-lg: 0 24px 60px -34px rgba(15, 23, 42, 0.35);
  --shadow-md: 0 14px 30px -22px rgba(15, 23, 42, 0.3);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 600px at 12% -10%, rgba(52, 211, 153, 0.1), transparent 60%),
    radial-gradient(900px 520px at 92% 2%, rgba(96, 165, 250, 0.09), transparent 62%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 34%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="light"] body {
  background-image:
    radial-gradient(1100px 600px at 12% -10%, rgba(15, 159, 110, 0.09), transparent 60%),
    radial-gradient(900px 520px at 92% 2%, rgba(37, 99, 235, 0.07), transparent 62%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 34%);
}

h1, h2, h3, h4, p, dl, dd, dt {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
}

a {
  color: var(--accent);
}

svg.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 200;
  top: 12px;
  left: 12px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform 0.18s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.main:focus {
  outline: none;
}

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

.small {
  font-size: 13px;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

/* ============================================================
   Header, navigation, layout
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 70;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text);
  border-radius: 12px;
}

.brand:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #03251a;
  background: linear-gradient(135deg, #6ee7b7, #34d399 45%, #22d3ee);
  box-shadow: 0 10px 24px -12px rgba(52, 211, 153, 0.8);
}

.brand-mark svg {
  width: 23px;
  height: 23px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: 0 0 auto;
}

.save-status[data-state="saving"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.save-status[data-state="error"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.save-status[data-state="linked"] .status-dot {
  background: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.save-status[data-state="permission"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.tabs {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}

.tabs-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 4px 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-inner::-webkit-scrollbar {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
  min-height: 44px;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

.tab[aria-current="page"] {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

.tab[aria-current="page"] svg {
  color: var(--accent);
}

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

.view {
  animation: view-in 0.28s ease both;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.view-head h1 {
  font-size: clamp(1.45rem, 3vw, 1.9rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-weight: 800;
  color: var(--text-strong);
}

.view-head p {
  margin-top: 5px;
  font-size: 14px;
  max-width: 58ch;
}

.view-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* ============================================================
   Cards, buttons, form controls
   ============================================================ */
.card {
  background: linear-gradient(180deg, color-mix(in srgb, var(--card) 97%, white 3%), var(--card));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
}

[data-theme="light"] .card {
  background: var(--card);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.card-head h2,
.card > h2 {
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.card-head p {
  margin-top: 3px;
}

.card-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.18s ease, border-color 0.18s ease,
    transform 0.12s ease, box-shadow 0.18s ease, color 0.18s ease;
}

.btn:hover {
  background: var(--card-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.tab:focus-visible,
.segmented button:focus-visible,
.zoom-controls button:focus-visible,
.switch input:focus-visible + .switch-track,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, #6ee7b7, var(--accent) 55%, #2dd4bf);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -14px rgba(52, 211, 153, 0.8);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #8af0c7, var(--accent) 55%, #45e4cf);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface);
}

.btn-danger {
  background: var(--danger);
  border-color: transparent;
  color: #2a0707;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 86%, white);
  border-color: transparent;
}

.btn-danger-ghost {
  color: var(--danger);
  background: transparent;
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 38%, transparent);
}

.btn-small {
  min-height: 38px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: 9px;
}

.btn-icon {
  width: 44px;
  padding: 0;
}

.btn-icon.btn-small {
  width: 38px;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 11px;
}

.segmented button {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.5), inset 0 0 0 1px var(--border);
}

label.field,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

.field .label,
.field > span:first-child {
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 550;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.field textarea {
  min-height: 84px;
  padding: 10px 12px;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted-2);
}

.field input:hover,
.field select:hover {
  border-color: var(--border-strong);
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field-inline input {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.field-help {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

.form-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ============================================================
   KPI cards
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  padding: 16px 17px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.kpi-top {
  display: flex;
  align-items: center;
  gap: 9px;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  flex: 0 0 auto;
}

.kpi-icon svg {
  width: 17px;
  height: 17px;
}

.kpi-icon.green {
  color: var(--accent);
  background: var(--accent-soft);
}

.kpi-icon.blue {
  color: var(--blue);
  background: var(--blue-soft);
}

.kpi-icon.violet {
  color: var(--violet);
  background: var(--violet-soft);
}

.kpi-icon.amber {
  color: var(--amber);
  background: var(--amber-soft);
}

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.055em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: clamp(1.35rem, 2.6vw, 1.72rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.15;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.kpi-unit {
  margin-left: 4px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  min-height: 32px;
}

.kpi-sub strong {
  color: var(--text);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.delta.over {
  color: var(--amber);
}

.delta.under {
  color: var(--accent);
}

.delta.neutral {
  color: var(--muted);
}

/* ============================================================
   Onboarding, empty states
   ============================================================ */
.onboarding {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  background:
    linear-gradient(120deg, var(--accent-soft), transparent 55%),
    var(--card);
}

.onboarding-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--accent-soft);
  color: var(--accent);
  flex: 0 0 auto;
}

.onboarding h2 {
  font-size: 17px;
  margin-bottom: 3px;
}

.onboarding p {
  color: var(--muted);
  font-size: 13.5px;
  max-width: 54ch;
}

.onboarding-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.empty-state {
  text-align: center;
  padding: 42px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 40%, transparent);
}

.empty-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
}

.empty-state h3 {
  color: var(--text);
  font-size: 16px;
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 13.5px;
  margin: 0 auto 14px;
  max-width: 48ch;
}

/* ============================================================
   Dashboard charts & breakdown
   ============================================================ */
.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

@media (min-width: 1080px) {
  .chart-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
  }
}

.chart-card {
  padding: 18px;
  min-width: 0;
}

.chart-wrap {
  position: relative;
  height: 290px;
  min-width: 0;
}

.chart-wrap.tall {
  height: 320px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--muted);
  font-size: 13px;
}

.chart-empty strong {
  color: var(--text);
  font-size: 14px;
}

.chart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chart-hint {
  font-size: 11.5px;
  color: var(--muted-2);
}

.zoom-controls {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}

.zoom-controls button {
  min-width: 38px;
  min-height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.zoom-controls button:hover {
  background: var(--card);
  color: var(--text);
}

.breakdown-card {
  padding: 18px;
}

.breakdown-chart-wrap {
  position: relative;
  height: 230px;
  margin-bottom: 18px;
}

.breakdown-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.breakdown-row {
  display: grid;
  gap: 6px;
}

.breakdown-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
}

.breakdown-swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.breakdown-name {
  font-weight: 650;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breakdown-value {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.breakdown-track {
  height: 7px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
}

.breakdown-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  min-width: 2px;
}

/* ============================================================
   Items
   ============================================================ */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 14px;
}

.item-card {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 17px;
  min-width: 0;
}

.item-card.is-disabled {
  opacity: 0.6;
}

.item-top {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.item-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  flex: 0 0 auto;
}

.item-head {
  min-width: 0;
  flex: 1;
}

.item-head h3 {
  font-size: 15.5px;
  font-weight: 750;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  margin-top: 3px;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 10px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  width: 34px;
  height: 20px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  position: relative;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(14px);
  background: var(--accent);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.item-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 11px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.item-stats dt {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 2px;
}

.item-stats dd {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.item-schedule {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.item-schedule svg {
  width: 15px;
  height: 15px;
}

.day-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.day-chip {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 24px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted-2);
}

.day-chip.on {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 2px;
}

.item-actions .btn {
  flex: 1;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
}

.cell-note {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  max-width: 32ch;
  white-space: pre-line;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

/* ============================================================
   Settings
   ============================================================ */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.settings-card-head {
  margin-bottom: 16px;
}

.settings-card-head h2 {
  font-size: 16px;
  font-weight: 750;
}

.settings-card-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.bill-preview {
  margin-top: 16px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  background:
    linear-gradient(120deg, var(--accent-soft), transparent 70%),
    var(--surface-2);
}

.preview-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-top span {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-top strong {
  font-family: var(--font-mono);
  font-size: 17px;
  letter-spacing: -0.02em;
}

.preview-rows {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.preview-rows div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.preview-rows dt {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.preview-rows dd {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.csv-status {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 13px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.csv-status .status-dot {
  margin-top: 6px;
}

.csv-status strong {
  display: block;
  font-size: 13.5px;
}

.csv-status p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.data-actions .btn,
.data-actions .file-btn {
  flex: 1 1 180px;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.prose {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.prose h2 {
  color: var(--text);
  font-size: 16px;
  margin-bottom: 10px;
}

.prose ol {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ============================================================
   Dialogs, toast
   ============================================================ */
dialog {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  max-width: min(590px, calc(100vw - 32px));
  width: 100%;
  max-height: calc(100dvh - 32px);
  overflow: visible;
}

dialog::backdrop {
  background: rgba(3, 8, 18, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.dialog-card {
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 20px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: dialog-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-head h2 {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.dialog-head p {
  margin-top: 3px;
  font-size: 12.5px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.dialog-actions .btn {
  flex: 0 1 auto;
}

.day-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.day-picker label {
  position: relative;
  cursor: pointer;
}

.day-picker input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.day-picker span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  user-select: none;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.day-picker input:checked + span {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  color: var(--accent);
}

.day-picker input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.estimate-box {
  margin-top: 14px;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.estimate-box strong {
  color: var(--text);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  min-width: 220px;
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface) 94%, black);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-kind="error"] {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

.toast[data-kind="success"] {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ============================================================
   Bottom nav (mobile)
   ============================================================ */
.bottom-nav {
  display: none;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .tabs {
    display: none;
  }

  .main {
    padding: 20px 16px calc(112px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(18px) saturate(150%);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
  }

  .bottom-nav a {
    flex: 1;
    min-height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 11px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
  }

  .bottom-nav a svg {
    width: 20px;
    height: 20px;
  }

  .bottom-nav a[aria-current="page"] {
    color: var(--accent);
    background: var(--accent-soft);
  }

  .brand-sub,
  .save-status {
    display: none;
  }

  .header-inner {
    padding: 8px 14px;
  }

  .chart-wrap {
    height: 270px;
  }

  .chart-wrap.tall {
    height: 300px;
  }

  .onboarding-actions {
    width: 100%;
    margin-left: 0;
  }

  .onboarding-actions .btn {
    flex: 1 1 auto;
  }

  .toast {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }

  dialog {
    max-width: 100%;
    width: 100%;
    margin: 0;
    position: fixed;
    inset: auto 0 0 0;
    max-height: 92dvh;
  }

  .dialog-card {
    border-radius: 20px 20px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    max-height: 92dvh;
    animation: sheet-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  @keyframes sheet-in {
    from {
      opacity: 0.6;
      transform: translateY(24px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .span-2 {
    grid-column: auto;
  }

  .view-head {
    align-items: flex-start;
  }

  .view-actions {
    width: 100%;
  }

  .view-actions .field-inline {
    flex: 1;
  }

  .view-actions .field-inline input {
    width: 100%;
  }

  .kpi {
    padding: 14px;
  }

  .kpi-top {
    align-items: flex-start;
    gap: 8px;
  }

  .kpi-label {
    min-width: 0;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 10.5px;
    line-height: 1.2;
  }

  .kpi-value {
    font-size: 1.4rem;
  }

  .kpi-sub {
    min-height: 0;
  }

  .header-actions .btn-primary .save-label {
    display: none;
  }

  .header-actions .btn-primary {
    width: 44px;
    padding: 0;
  }

  .segmented button {
    min-height: 42px;
    padding: 0 10px;
  }

  .zoom-controls button {
    min-height: 40px;
    min-width: 44px;
  }

  /* Table becomes stacked cards */
  .months-table thead {
    display: none;
  }

  .months-table,
  .months-table tbody,
  .months-table tr,
  .months-table td {
    display: block;
    width: 100%;
  }

  .months-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }

  .months-table tr:last-child {
    border-bottom: 0;
  }

  .months-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 5px 2px;
    border: 0;
    text-align: right;
  }

  .months-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-family: var(--font-sans);
    font-size: 10.5px;
    font-weight: 750;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    flex: 0 0 auto;
  }

  .months-table td:first-child {
    padding-top: 0;
  }

  .months-table td.actions-cell {
    padding-top: 9px;
    justify-content: flex-end;
  }

  .months-table td.actions-cell::before {
    content: none;
  }

  .row-actions .btn {
    flex: 1;
  }

  .item-stats dd {
    font-size: 12px;
  }
}

@media (max-width: 390px) {
  .day-picker {
    gap: 4px;
  }

  .day-picker span {
    min-height: 40px;
    font-size: 11px;
  }
}

/* ============================================================
   Motion preferences
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .app-header,
  .tabs,
  .bottom-nav,
  .chart-foot,
  .view-actions,
  .item-actions,
  .toast {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
  }

  .main {
    max-width: none;
    padding: 0;
  }
}

svg.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-dot.blue {
  background: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.status-dot.amber {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.status-dot.red {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}
