/* =====================================================================
   Petrol Spending Tracker — styles
   Light theme by default, dark theme via the OS setting, and either one
   forced by the taskbar toggle (data-theme on <html>).
   ===================================================================== */

:root {
  color-scheme: light;

  /* Surfaces & ink */
  --plane:            #f9f9f7;
  --surface:          #fcfcfb;
  --surface-sunken:   #f2f1ed;
  --text-primary:     #0b0b0b;
  --text-secondary:   #52514e;
  --text-muted:       #898781;
  --hairline:         #e1e0d9;
  --axis:             #c3c2b7;
  --ring:             rgba(11, 11, 11, 0.10);
  --shadow:           0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px rgba(11, 11, 11, 0.04);

  /* Data series (validated: slot 1, blue) */
  --series-1:         #2a78d6;
  --series-1-soft:    rgba(42, 120, 214, 0.14);
  --series-1-strong:  #1c5cab;

  /* Status */
  --good:             #0ca30c;
  --critical:         #d03b3b;

  /* Metrics */
  --radius:           12px;
  --radius-sm:        8px;
  --taskbar-h:        58px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --plane:            #0d0d0d;
    --surface:          #1a1a19;
    --surface-sunken:   #141413;
    --text-primary:     #f0efec;
    --text-secondary:   #c3c2b7;
    --text-muted:       #898781;
    --hairline:         #2c2c2a;
    --axis:             #383835;
    --ring:             rgba(255, 255, 255, 0.10);
    --shadow:           0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);

    --series-1:         #3987e5;
    --series-1-soft:    rgba(57, 135, 229, 0.18);
    --series-1-strong:  #86b6ef;

    --good:             #0ca30c;
    --critical:         #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --plane:            #0d0d0d;
  --surface:          #1a1a19;
  --surface-sunken:   #141413;
  --text-primary:     #f0efec;
  --text-secondary:   #c3c2b7;
  --text-muted:       #898781;
  --hairline:         #2c2c2a;
  --axis:             #383835;
  --ring:             rgba(255, 255, 255, 0.10);
  --shadow:           0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);

  --series-1:         #3987e5;
  --series-1-soft:    rgba(57, 135, 229, 0.18);
  --series-1-strong:  #86b6ef;

  --good:             #0ca30c;
  --critical:         #e66767;
}

/* --------------------------------------------------------------- base */

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

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--series-1); }

:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ----------------------------------------------------------- taskbar */

.taskbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--taskbar-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}

.brand svg { display: block; color: var(--series-1); }

.brand span { display: none; }

@media (min-width: 560px) {
  .brand span { display: inline; }
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.nav a {
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav a:hover { background: var(--surface-sunken); color: var(--text-primary); }

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

.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--ring);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.theme-toggle:hover { background: var(--surface-sunken); color: var(--text-primary); }
.theme-toggle svg { display: block; }

/* ------------------------------------------------------------- layout */

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 16px 56px;
}

.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 21px; }
.page-head p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------- the two counters */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;   /* side by side, right under the taskbar */
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  position: relative;
  padding: 18px 20px;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--series-1);
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 7px;
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 680;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-value .cents { font-size: 0.62em; font-weight: 600; color: var(--text-secondary); }
.stat-value .sign  { font-size: 0.52em; font-weight: 600; color: var(--text-secondary); margin-right: 2px; }

.stat-sub {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 13px;
}

/* --------------------------------------------------------- the form */

.entry { padding: 18px 20px 20px; margin-bottom: 22px; }
.entry h2 { font-size: 15px; margin-bottom: 14px; }

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr) auto;
  gap: 12px;
  align-items: end;
}

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

@media (max-width: 720px) {
  .form-row { grid-template-columns: 1fr 1fr; }
  .form-row .field-notes { grid-column: 1 / -1; }
  .form-row .form-actions { grid-column: 1 / -1; }
  .form-row .form-actions > * { flex: 1; }
}

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

.field label {
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
}

.field .hint { color: var(--text-muted); font-weight: 500; }

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--axis);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 14.5px;
}

input:focus,
select:focus {
  border-color: var(--series-1);
  outline: 2px solid var(--series-1-soft);
  outline-offset: 0;
}

.input-prefix { position: relative; }
.input-prefix > span {
  position: absolute;
  top: 50%;
  left: 11px;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14.5px;
  pointer-events: none;
}
.input-prefix input { padding-left: 34px; }

button {
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
}

.btn-primary {
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--series-1);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.14s ease;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.55; cursor: progress; }

.btn-ghost {
  padding: 5px 10px;
  border: 1px solid var(--ring);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text-primary); }
.btn-ghost.danger:hover { border-color: var(--critical); color: var(--critical); }

/* ------------------------------------------------------- the message */

.message {
  display: none;
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.message[data-kind="error"] {
  display: block;
  background: rgba(208, 59, 59, 0.10);
  border: 1px solid rgba(208, 59, 59, 0.35);
  color: var(--critical);
}
.message[data-kind="success"] {
  display: block;
  background: rgba(12, 163, 12, 0.10);
  border: 1px solid rgba(12, 163, 12, 0.32);
  color: var(--good);
}

/* -------------------------------------------------------- the table */

.table-wrap { padding: 18px 20px 8px; }

.table-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.table-head h2 { font-size: 15px; }
.table-head .count { color: var(--text-muted); font-size: 13px; }

.scroller { overflow-x: auto; }

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

thead th {
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-sunken); }

.col-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.col-date   { white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-notes  { color: var(--text-secondary); }
.col-act    { text-align: right; white-space: nowrap; }
.col-act button + button { margin-left: 6px; }

.empty {
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

/* -------------------------------------------------------- the chart */

.chart-card { padding: 18px 20px 20px; }

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 6px;
}
.chart-toolbar .field { width: 150px; }
.chart-toolbar .spacer { margin-left: auto; }

.chart-legend-note {
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chart-holder { position: relative; margin-top: 10px; }
.chart-holder svg { display: block; width: 100%; height: auto; overflow: visible; }

.bar { fill: var(--series-1); transition: fill 0.12s ease; }
.bar-hit { fill: transparent; cursor: default; }
.bar-group:hover .bar { fill: var(--series-1-strong); }
.grid-line { stroke: var(--hairline); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.tick-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.year-text { fill: var(--text-secondary); font-size: 12px; font-weight: 600; }
.bar-label { fill: var(--text-secondary); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.axis-title { fill: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }

.tooltip {
  position: absolute;
  z-index: 5;
  min-width: 140px;
  padding: 9px 11px;
  border: 1px solid var(--ring);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s ease;
}
.tooltip[data-show="true"] { opacity: 1; }
.tooltip .tt-period { color: var(--text-secondary); font-size: 12px; }
.tooltip .tt-value  { margin-top: 2px; font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-meta   { margin-top: 1px; color: var(--text-muted); font-size: 12px; }

/* --------------------------------------------- chart summary strip */

.chart-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}
.chart-stats div { padding: 0 14px 0 0; }
.chart-stats dt {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.chart-stats dd {
  margin: 3px 0 0;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------ data table */

.data-table { margin-top: 22px; }
.data-table summary {
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
}
.data-table summary:hover { color: var(--text-primary); }
.data-table .scroller { margin-top: 12px; }

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