:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #ecfdf3;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --stripe: #f1f3f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-bottom: 10px; }
code { font-size: 12px; background: var(--stripe); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; margin: 0; }

/* Vormid */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 550; color: #334155; }
input, textarea, select {
  font: inherit; font-size: 14px; font-weight: 400; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 8px 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s; min-width: 0;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; resize: vertical; width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.check-row { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; margin-top: 10px; }
.check-row input { width: 16px; height: 16px; }

.btn {
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 8px 14px; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f8fafc; border-color: #94a3b8; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--stripe); color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.wide { width: 100%; padding: 10px; }
.btn[disabled] { opacity: .55; cursor: progress; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.card-head h3 { margin: 0; }

/* Sisselogimine */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, #dbe7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #e0ecff 0%, transparent 55%), var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; background: #fff; padding: 28px; border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(15, 23, 42, .08); }
.login-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-lg { font-size: 20px; }

/* Ülariba */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: rgba(255, 255, 255, .85); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; background: var(--stripe); padding: 3px; border-radius: 11px; }
.tab { font: inherit; font-weight: 600; font-size: 13.5px; border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.tab[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.view { padding: 22px 24px 60px; max-width: 1440px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 18px; align-items: start; }
.main-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 14px; align-items: end; }
.empty h2 { margin-bottom: 6px; }
.empty p { margin: 0; max-width: 70ch; }

.stats { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.stat span { font-size: 11.5px; color: var(--muted); font-weight: 550; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat.check b { color: var(--ok); }
.stat.check.bad { background: var(--bad-soft); border-color: #fecaca; }
.stat.check.bad b { color: var(--bad); }
.stat.check:not(.bad) { background: var(--ok-soft); border-color: #bbf7d0; }

.sheet { padding: 0; overflow: hidden; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 18px 6px; flex-wrap: wrap; }
.sheet-head p { margin: 2px 0 0; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { margin: 0; padding: 0 18px 10px; font-size: 12.5px; }
.dirty { margin: 0; padding: 8px 18px 14px; font-size: 12.5px; color: #b45309; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: none; padding: 8px 6px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line-strong); background: #fafbfc; white-space: nowrap; }
.grid td { padding: 2px 3px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tbody tr.era td { background: var(--stripe); }
.grid tbody tr:hover td { background: #eef3fb; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.num { padding-right: 10px; color: #334155; }
.grid th:first-child, .grid td:first-child { padding-left: 15px; }
.grid input, .grid textarea { width: 100%; border-color: transparent; background: transparent; padding: 5px 6px; border-radius: 6px; font-size: 13px; }
.grid textarea { font-family: inherit; resize: none; overflow: hidden; line-height: 1.35; min-height: 30px; display: block; }
.grid input:hover, .grid textarea:hover { border-color: var(--line-strong); background: #fff; }
.grid input:focus, .grid textarea:focus { background: #fff; }
.grid input.km { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.grid tfoot td { border-bottom: 0; padding: 8px 6px; font-weight: 700; }
.c-date { width: 150px; } .c-type { width: 130px; } .c-type2 { width: 160px; } .c-purp { width: 150px; } .c-km { width: 95px; } .c-x { width: 34px; }
.del { border: 0; background: transparent; color: #94a3b8; font-size: 16px; line-height: 1; cursor: pointer; border-radius: 6px; width: 26px; height: 26px; }
.del:hover { background: var(--bad-soft); color: var(--bad); }

.history { position: sticky; top: 74px; }
.months { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 160px); overflow: auto; }
.months li { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 8px 8px 12px; cursor: pointer; transition: border-color .15s, background .15s; }
.months li:hover { border-color: #93c5fd; background: var(--accent-soft); }
.months li.active { border-color: var(--accent); background: var(--accent-soft); }
.months .m-main { flex: 1; min-width: 0; }
.months .m-name { font-weight: 650; }
.months .m-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.months .btn { padding: 4px 8px; font-size: 12px; }

.settings { display: flex; flex-direction: column; gap: 16px; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two .card p { margin: 0 0 10px; }
.save-bar { display: flex; justify-content: flex-end; align-items: center; gap: 14px; }
.save-bar p { margin: 0; }
.pw { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.pw h3 { margin: 0; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); z-index: 20; max-width: min(560px, 92vw); white-space: pre-line; }
.toast.bad { background: var(--bad); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .history { position: static; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 12px; flex-wrap: wrap; }
  .view { padding: 14px; }
  .controls, .row3, .two { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .who span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
