/*
 * Ajopäiväkirja – puhdas CSS, ei frameworkejä.
 * Mobiili edellä: alanavigaatio pienillä näytöillä, sivupalkki isoilla.
 */

/* ---------- Design tokens ---------- */
:root {
  --brand-900: #10314a;
  --brand-700: #1b4965;
  --brand-500: #2e6f95;
  --brand-300: #7fb3d0;
  --brand-100: #e4eef5;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dde3ea;
  --text: #12202c;
  --text-muted: #63717f;
  --text-inverse: #ffffff;

  --success: #157f4a;
  --success-bg: #e3f4ea;
  --danger: #b3261e;
  --danger-bg: #fceceb;
  --warning: #8a5a00;
  --warning-bg: #fdf2dc;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(16, 49, 74, 0.06);
  --shadow: 0 4px 16px rgba(16, 49, 74, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 49, 74, 0.14);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --nav-height: 4.25rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-900: #cfe3f0;
    --brand-700: #9cc6e0;
    --brand-500: #4f92bb;
    --brand-300: #2c5d7d;
    --brand-100: #17303f;

    --bg: #0e1620;
    --surface: #16212d;
    --surface-alt: #1c2836;
    --border: #2a3847;
    --text: #e8eef4;
    --text-muted: #9aa9b8;
    --text-inverse: #0e1620;

    --success: #6ed49b;
    --success-bg: #12301f;
    --danger: #ff9b93;
    --danger-bg: #35191a;
    --warning: #f0c069;
    --warning-bg: #33270f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

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

/* hidden-attribuutin on voitettava komponenttien display-arvot. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--space-3); }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; height: auto; vertical-align: middle; }

/* Ikonien oletuskoko. Kontekstikohtaiset säännöt ohittavat tämän spesifisyydellä. */
.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}

:focus-visible {
  outline: 3px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  background: var(--brand-700);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-inverse);
}
.topbar__brand:hover { text-decoration: none; }
.topbar__brand svg { width: 1.5rem; height: 1.5rem; }

.topbar__spacer { margin-left: auto; }

.locale-select {
  min-height: 2.25rem;
  width: auto;
  padding: 2px 1.75rem 2px 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-inverse);
  background-color: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.35);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}
.locale-select option { color: var(--text); background: var(--surface); }

/* Tummassa tilassa yläpalkki on vaalea, joten nuolen on oltava tumma. */
@media (prefers-color-scheme: dark) {
  .locale-select {
    background-color: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.25);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%230e1620' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  }
}

.topbar__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-inverse);
  opacity: 0.85;
  font: inherit;
  font-size: 0.875rem;
  appearance: none;
  cursor: pointer;
}
.topbar__link:hover, .topbar__link:focus-visible {
  opacity: 1;
  text-decoration: none;
  color: var(--text-inverse);
  background: rgba(255, 255, 255, 0.18);
}
.topbar__link .icon { width: 1.375rem; height: 1.375rem; }

.main {
  flex: 1;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--nav-height) + var(--space-6));
}

@media (min-width: 60rem) {
  .main { padding-bottom: var(--space-7); }
}

/* ---------- Navigation ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(16, 49, 74, 0.08);
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) var(--space-1);
  min-height: var(--nav-height);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}
.bottom-nav__item:hover { text-decoration: none; color: var(--brand-500); }
.bottom-nav__item[aria-current="page"] { color: var(--brand-500); }
.bottom-nav__item svg { width: 1.375rem; height: 1.375rem; stroke-width: 1.75; }

.bottom-nav__item--accent {
  color: var(--text-inverse);
}
.bottom-nav__item--accent .bottom-nav__badge {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-top: -1.25rem;
  border-radius: 50%;
  background: var(--brand-500);
  color: #fff;
  box-shadow: var(--shadow);
}
.bottom-nav__item--accent span:last-child { color: var(--text-muted); }

@media (min-width: 60rem) {
  .bottom-nav {
    position: static;
    display: flex;
    justify-content: center;
    gap: var(--space-1);
    border-top: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    order: -1;
  }
  .bottom-nav__item {
    flex-direction: row;
    gap: var(--space-2);
    min-height: 0;
    padding: var(--space-3) var(--space-4);
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
  }
  .bottom-nav__item[aria-current="page"] { border-bottom-color: var(--brand-500); }
  .bottom-nav__item--accent .bottom-nav__badge {
    width: 1.5rem; height: 1.5rem; margin-top: 0; box-shadow: none;
  }
  .bottom-nav__item--accent span:last-child { color: inherit; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-4);
}

.card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card__header h2, .card__header h3 { margin: 0; }

.card--flush { padding: 0; overflow: hidden; }
.card--flush .card__header { padding: var(--space-4) var(--space-4) 0; }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-header__title { margin: 0; }
.page-header__subtitle { margin: var(--space-1) 0 0; color: var(--text-muted); font-size: 0.875rem; }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.stat__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}
.stat__value { font-size: 1.5rem; font-weight: 700; line-height: 1.15; }
.stat__unit { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); margin-left: 2px; }
.stat__meta { font-size: 0.8125rem; color: var(--text-muted); margin-top: var(--space-1); }
.stat--accent { background: var(--brand-700); border-color: var(--brand-700); color: var(--text-inverse); }
.stat--accent .stat__label, .stat--accent .stat__meta, .stat--accent .stat__unit { color: rgba(255, 255, 255, 0.8); }

/* ---------- Lists ---------- */
.list { border-top: 1px solid var(--border); }
.list__item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: inherit;
}
a.list__item:hover { text-decoration: none; background: var(--surface-alt); }
.list__body { flex: 1; min-width: 0; }
.list__title { font-weight: 600; }
.list__meta { font-size: 0.8125rem; color: var(--text-muted); }
.list__meta > * + *::before { content: " · "; }
.list__value { text-align: right; font-weight: 700; white-space: nowrap; }
.list__value small { display: block; font-weight: 500; font-size: 0.75rem; color: var(--text-muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th, td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-alt);
}
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--brand-100);
  color: var(--brand-700);
  white-space: nowrap;
}
.badge--business { background: var(--success-bg); color: var(--success); }
.badge--private { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.badge--commute { background: var(--warning-bg); color: var(--warning); }
.badge--danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.875rem;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand-500);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
}
.button:hover { background: var(--brand-700); text-decoration: none; color: #fff; }
.button:active { transform: translateY(1px); }
.button svg { width: 1.125rem; height: 1.125rem; }

.button--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.button--secondary:hover { background: var(--surface-alt); color: var(--text); }

.button--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.button--danger:hover { background: var(--danger-bg); color: var(--danger); }

.button--block { width: 100%; }
.button--small { min-height: 2.25rem; font-size: 0.8125rem; padding: 0 var(--space-3); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}
.button-row--end { justify-content: flex-end; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: var(--space-4); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field > label { font-weight: 600; font-size: 0.875rem; }
.field__hint { font-size: 0.8125rem; color: var(--text-muted); }
.field__optional { font-weight: 400; color: var(--text-muted); font-size: 0.8125rem; }

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 34rem) {
  .field-row--2 { grid-template-columns: 1fr 1fr; }
  .field-row--3 { grid-template-columns: repeat(3, 1fr); }
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"], input[type="tel"],
select, textarea {
  width: 100%;
  min-height: 2.875rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: 1rem; /* estää iOS-zoomauksen */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
}
textarea { min-height: 5.5rem; resize: vertical; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2363717f' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 1rem;
  padding-right: var(--space-6);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.field--invalid input, .field--invalid select, .field--invalid textarea { border-color: var(--danger); }
.field__error { font-size: 0.8125rem; color: var(--danger); font-weight: 600; }

.checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.875rem;
  font-weight: 600;
  font-size: 0.9375rem;
}
.checkbox input[type="checkbox"] {
  width: 1.375rem;
  height: 1.375rem;
  accent-color: var(--brand-500);
  margin: 0;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  gap: var(--space-2);
}
.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.875rem;
  padding: var(--space-2);
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + span,
.segmented label:has(input:checked) { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--brand-500); outline-offset: 2px; }

/* ---------- Filter bar ---------- */
.filters {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
@media (min-width: 40rem) {
  .filters { grid-template-columns: repeat(4, 1fr); align-items: end; }
}

/* ---------- Flash ---------- */
.flash {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
  font-size: 0.9375rem;
  font-weight: 500;
}
.flash--notice { background: var(--success-bg); color: var(--success); border-color: currentColor; }
.flash--alert { background: var(--danger-bg); color: var(--danger); border-color: currentColor; }

.error-summary {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
}
.error-summary ul { list-style: disc; padding-left: var(--space-5); }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-muted);
}
.empty svg { width: 3rem; height: 3rem; color: var(--brand-300); margin-bottom: var(--space-3); }

/* ---------- Auth ---------- */
.auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) var(--space-4);
  background: linear-gradient(160deg, var(--brand-700), var(--brand-900));
}
.auth__card {
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-lg);
}
.auth__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
  margin-bottom: var(--space-2);
  color: var(--brand-700);
  font-weight: 700;
  font-size: 1.125rem;
}
.auth__brand svg { width: 1.75rem; height: 1.75rem; flex: none; }
.auth__tagline { text-align: center; color: var(--text-muted); font-size: 0.875rem; margin-bottom: var(--space-5); }
.auth__footer { text-align: center; font-size: 0.875rem; margin-top: var(--space-4); color: var(--text-muted); }

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.provider-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 2.875rem;
  margin-bottom: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.provider-button:hover { background: var(--surface-alt); text-decoration: none; color: var(--text); }
.provider-button svg { width: 1.25rem; height: 1.25rem; }

/* ---------- Report cards ---------- */
.report-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}
@media (min-width: 44rem) {
  .report-grid { grid-template-columns: repeat(3, 1fr); }
}
.report-card { display: flex; flex-direction: column; height: 100%; }
.report-card p { flex: 1; color: var(--text-muted); font-size: 0.875rem; }
.format-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- Description list ---------- */
.details { display: grid; gap: var(--space-3); grid-template-columns: 1fr; }
@media (min-width: 34rem) { .details { grid-template-columns: 1fr 1fr; } }
.details__item { min-width: 0; }
.details__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.details__value { font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Bar chart (kuukausijakauma) ---------- */
.bars { display: flex; flex-direction: column; gap: var(--space-3); }
.bar__head { display: flex; justify-content: space-between; font-size: 0.8125rem; margin-bottom: 4px; }
.bar__track {
  display: flex;
  height: 0.625rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.bar__segment--business { background: var(--brand-500); }
.bar__segment--commute { background: var(--brand-300); }
.bar__segment--private { background: var(--border); }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: 0.8125rem; color: var(--text-muted); margin-top: var(--space-3); }
.legend__item { display: flex; align-items: center; gap: var(--space-2); }
.legend__swatch { width: 0.75rem; height: 0.75rem; border-radius: 3px; }

/* ---------- Utilities ---------- */
.muted { color: var(--text-muted); }
.small { font-size: 0.8125rem; }
.numeric { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: var(--space-4); }
.stack > * + * { margin-top: var(--space-3); }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .topbar, .bottom-nav, .button, .filters { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
