/*
 * Shared styles for the irrigation UI (plan 08). Phone-first: the primary
 * client is a phone at the court. Theme tokens follow the dataviz reference
 * palette (light + dark selected, not auto-flipped).
 */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --focus: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --series-1: #5b9eff;
    --series-2: #36c79b;
    --good: #0ca30c;
    --good-text: #0ca30c;
  }
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 12px 48px;
}

/* ---- top bar / nav ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  max-width: 680px;
  margin: 0 auto;
  padding: 10px 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  font-weight: 650;
  letter-spacing: 0.01em;
}

.topbar nav {
  max-width: 680px;
  margin: 0 auto;
  padding: 6px 4px 0;
  display: flex;
}

.topbar nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 12px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  min-height: 44px;
}

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

.link-btn {
  border: none;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
  min-height: 44px;
}

.link-btn:hover {
  color: var(--ink);
}

/* ---- cards & layout ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 12px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.kv .k {
  font-size: 13px;
  color: var(--muted);
}

.kv .v {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.kv .v small {
  font-weight: 400;
  color: var(--ink-2);
}

.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 0;
}

/* ---- badges & status ---- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.badge.on .dot {
  background: var(--good);
}

.badge.warn .dot {
  background: var(--warning);
}

.badge.off .dot {
  background: var(--muted);
}

.banner {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--ink-2);
}

.banner.error {
  border-left-color: var(--critical);
  color: var(--ink);
}

.banner.ok {
  border-left-color: var(--good);
}

/* ---- buttons & forms ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.danger {
  background: var(--critical);
  border-color: var(--critical);
  color: #ffffff;
}

.btn.block {
  width: 100%;
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
.link-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 4px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--baseline);
  border-radius: 8px;
}

input[aria-invalid="true"] {
  border-color: var(--critical);
}

.field {
  margin-bottom: 14px;
}

.field .error {
  color: var(--critical);
  font-size: 13px;
  margin-top: 4px;
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: end;
}

.form-row > * {
  flex: 1;
}

.form-row > .btn,
.form-row > .icon-btn {
  flex: 0 0 auto;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 18px;
  cursor: pointer;
}

/* ---- tabs & filters ---- */

.tabs {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  background: var(--surface);
}

.tabs button {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.filter-row > div {
  flex: 1 1 30%;
  min-width: 130px;
}

.filter-row label {
  font-size: 12px;
  margin-bottom: 2px;
}

/* ---- tables ---- */

.table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

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

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

td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

td.num {
  font-variant-numeric: tabular-nums;
}

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

.pager .btn {
  min-height: 44px;
  padding: 8px 16px;
}

.pager span {
  font-size: 13px;
  color: var(--muted);
}

/* ---- charts (dataviz skill: thin marks, hairline grid, tooltips) ---- */

.chart {
  margin-top: 16px;
}

.chart h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

.chart svg {
  display: block;
  width: 100%;
}

.chart .gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .baseline {
  stroke: var(--baseline);
  stroke-width: 1;
}

.chart .tick,
.chart .bar-label {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .value-label {
  fill: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart .cat-label {
  fill: var(--ink-2);
  font-size: 12px;
}

.chart .bar {
  pointer-events: none;
}

.chart .hit {
  fill: transparent;
  cursor: default;
}

.chart .hit:hover + .bar,
.chart .hit:focus-visible + .bar {
  filter: brightness(1.18);
}

.chart .empty {
  color: var(--muted);
  font-size: 14px;
  padding: 12px 0;
}

/* ---- Väder page: legend + rain/temperature marks ---- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0 0 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: none;
  border: 1px solid var(--border);
}

.chart .nowline {
  stroke: var(--ink-2);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart .nowlabel {
  fill: var(--ink-2);
  font-size: 11px;
}

.chart .templine {
  fill: none;
  stroke: var(--series-2);
  stroke-width: 2;
  stroke-linejoin: round;
}

.chart .tempdot {
  fill: var(--series-2);
}

.hbar-row {
  padding: 6px 0;
}

.hbar-row:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.hbar-label {
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 3px;
}

.hbar-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hbar-track {
  flex: 1;
}

.hbar-fill {
  height: 16px;
  border-radius: 0 4px 4px 0; /* rounded data end, square at baseline */
  min-width: 2px;
}

.hbar-row:hover .hbar-fill,
.hbar-row:focus-visible .hbar-fill {
  filter: brightness(1.18);
}

.hbar-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  min-width: 20px;
}

.viz-tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ink-2);
  max-width: 240px;
}

.viz-tooltip strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---- login ---- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-card p.sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

/* ---- utility ---- */

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

.good-text {
  color: var(--good-text);
  font-weight: 600;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 420px) {
  .kv-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
  }

  main {
    padding: 8px 8px 40px;
  }

  .card {
    padding: 14px;
  }
}

/* ---- dark-mode chart polish: lift grid/baseline, brighter now-line ---- */

@media (prefers-color-scheme: dark) {
  .chart .gridline {
    stroke: #3a3a38;
    stroke-width: 1;
  }

  .chart .baseline {
    stroke: #5a5a55;
    stroke-width: 1;
  }

  .chart .nowline {
    stroke: var(--accent);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
  }

  .chart .nowlabel {
    fill: var(--accent);
    font-weight: 600;
  }

  .chart .tick,
  .chart .bar-label {
    fill: #a09f97;
  }

  .chart .templine {
    stroke: #4dd9a0;
    stroke-width: 2.25;
  }

  .chart .tempdot {
    fill: #4dd9a0;
  }

  .legend-swatch {
    border-color: rgba(255, 255, 255, 0.18);
  }

  .viz-tooltip {
    background: #2a2a28;
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  }

  .viz-tooltip strong {
    color: #ffffff;
  }
}
