:root {
  --green: #0b3d2e;
  --green-600: #14584180;
  --accent: #1f8f63;
  --accent-strong: #157a52;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --text: #14211c;
  --muted: #4a5852;
  --border: #dce4df;
  --danger: #c0392b;
  --warn: #b8860b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.05);
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green: #0c3a2c;
    --accent: #2ea06e;
    --accent-strong: #35b57c;
    --bg: #0f1512;
    --surface: #172019;
    --surface-2: #1e2a23;
    --text: #eef4f0;
    --muted: #b3c5bb;
    --border: #2a3a31;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.visually-hidden, .skip-link {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 8px; left: 8px; width: auto; height: auto; clip: auto;
  background: var(--surface); color: var(--text); padding: .5rem .75rem; border-radius: 8px; z-index: 100;
}

/* Appbar */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
  background: var(--green); color: #fff;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; }
.appbar-actions { display: flex; align-items: center; gap: .5rem; }
.user-email { font-size: .8rem; opacity: .85; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout */
main { max-width: var(--maxw); margin: 0 auto; padding: 1rem; padding-bottom: max(2rem, env(safe-area-inset-bottom)); }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.stack { display: flex; flex-direction: column; gap: .6rem; }

/* Auth */
.auth-card { max-width: 420px; margin: 2rem auto; }

/* Buttons */
button, .btn-primary, .btn-ghost, .btn-danger {
  font: inherit; color: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
  padding: .6rem 1rem; transition: background .15s, opacity .15s, transform .05s;
}
button:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); }
a.btn-primary { text-decoration: none; display: inline-block; text-align: center; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.icon-btn { padding: .5rem .7rem; line-height: 1; font-size: 1.1rem; }
:where(button, a, input, select, summary):focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* Inputs */
label { font-weight: 600; font-size: .9rem; }
input, select {
  font: inherit; width: 100%; padding: .6rem .7rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input[readonly] { background: var(--surface-2); }
.form-status { min-height: 1.2em; font-size: .9rem; margin: .2rem 0 0; }
.form-status.error { color: var(--danger); }
.form-status.ok { color: var(--accent-strong); }

/* Route bar */
.route-bar { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.route-select { flex: 1; font-weight: 600; }

/* Tur/Retur-växel */
.dir-toggle { display: flex; gap: .4rem; margin-bottom: 1rem; }
.dir-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: .4rem 1.1rem; font-weight: 600; font-size: .9rem;
}
.dir-btn:hover { background: var(--surface-2); }
.dir-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.dir-add { color: var(--accent-strong); border-style: dashed; font-weight: 500; }

/* Empty */
.empty { text-align: center; }
.empty p { margin-top: 0; }

/* Filters */
.filters summary {
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; list-style: none;
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after { content: "▾"; color: var(--muted); }
.filters[open] summary::after { content: "▴"; }
.filter-summary { font-weight: 400; color: var(--muted); font-size: .85rem; }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: .7rem; margin-top: .8rem; }
.filter-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-top: .8rem;
}
.filters .weekdays { margin-top: .8rem; }
@media (min-width: 560px) {
  .settings-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.field { display: flex; flex-direction: column; gap: .25rem; }
.field-wide { grid-column: 1 / -1; }
.filter-actions { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; }
.filter-actions .spacer { flex: 1; }

/* Vy-kontroll (Visa dag) ovanför resultaten */
.view-bar { display: flex; gap: .8rem; align-items: flex-end; margin-bottom: 1rem; flex-wrap: wrap; }
.view-bar .field { min-width: 160px; max-width: 240px; }

/* Results */
.results { display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1rem; }
.trip {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow);
}
.trip.recommended { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent), var(--shadow); }
.trip-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.trip-times { font-size: 1.25rem; font-weight: 700; letter-spacing: .01em; }
.trip-times .arrow { color: var(--muted); margin: 0 .35rem; font-weight: 400; }
.trip-dur { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.rec-badge {
  display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent); color: #fff; padding: .1rem .45rem; border-radius: 6px; margin-bottom: .4rem;
}
.trip-meta { display: flex; flex-wrap: wrap; gap: .4rem .8rem; margin-top: .5rem; font-size: .85rem; color: var(--muted); }
.trip-meta .chip { display: inline-flex; align-items: center; gap: .3rem; }
.badge-delay { color: #fff; background: var(--warn); padding: .05rem .4rem; border-radius: 6px; font-weight: 600; }
.badge-cancel { color: #fff; background: var(--danger); padding: .05rem .4rem; border-radius: 6px; font-weight: 600; }
.badge-ontime { color: var(--accent-strong); font-weight: 600; }
.chip-rel { color: var(--accent-strong); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 6px; padding: 0 .3rem; }
.trip-legs { margin-top: .6rem; border-top: 1px dashed var(--border); padding-top: .6rem; display: none; }
.trip.open .trip-legs { display: block; }
.leg { display: flex; gap: .6rem; font-size: .85rem; padding: .2rem 0; }
.leg-time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 88px; }
.leg-mode { font-weight: 600; }
.leg-sub { color: var(--muted); }
.toggle-legs { background: none; border: none; color: var(--accent-strong); padding: .3rem 0 0; font-size: .85rem; }

.state-msg { text-align: center; color: var(--muted); padding: 1.5rem; }

/* Calendar */
.ical-row { display: flex; gap: .5rem; margin: .6rem 0; }
.ical-row input { flex: 1; font-size: .8rem; }
.calendar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Modal */
.modal {
  border: none; border-radius: 16px; padding: 0; width: min(500px, 92vw);
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal::backdrop { background: rgba(0,0,0,.45); }
#routeForm { padding: 1.2rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.modal-head h2 { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox-row input { width: auto; }
.modal-actions { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; }
.modal-actions .spacer { flex: 1; }
.weekdays { border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; margin: 0; }
.weekdays legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.weekday-row { display: flex; gap: .3rem; flex-wrap: wrap; }
.wd {
  cursor: pointer; border: 1px solid var(--border); border-radius: 8px; padding: .35rem .55rem;
  font-size: .85rem; user-select: none; background: var(--surface);
}
.wd input { position: absolute; opacity: 0; width: 0; height: 0; }
.wd.checked { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Autocomplete */
.autocomplete { position: relative; display: flex; flex-direction: column; gap: .25rem; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5; margin: 2px 0 0; padding: 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.suggest li { padding: .55rem .7rem; cursor: pointer; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--surface-2); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 50;
  box-shadow: var(--shadow); font-size: .9rem; max-width: 90vw;
}

/* Störningar */
.disruptions {
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: 1rem;
}
.disruptions-head { font-weight: 700; color: var(--warn); margin-bottom: .3rem; }
.disruption { border-top: 1px solid var(--border); padding: .35rem 0; }
.disruption:first-of-type { border-top: none; }
.disruption summary { cursor: pointer; font-size: .9rem; }
.disruption p { margin: .4rem 0 .2rem; font-size: .85rem; color: var(--muted); }
.disruption-src {
  display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  background: var(--warn); color: #fff; padding: .05rem .35rem; border-radius: 5px; margin-right: .3rem;
}

/* Överblick */
.overview {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .7rem; margin-bottom: 1rem;
}
.ov-loading { grid-column: 1 / -1; margin: 0; }
.ov-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem .9rem; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: .3rem;
}
.ov-card:hover { background: var(--surface-2); }
.ov-card.current { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent), var(--shadow); }
.ov-title { font-weight: 700; font-size: .98rem; }
.ov-od { font-size: .78rem; color: var(--muted); margin-bottom: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-row { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; font-size: .82rem; }
.ov-time { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ov-sub { color: var(--muted); font-size: .78rem; text-align: right; }

/* Filter: ursprungsstations-chips */
.filter-note { font-size: .8rem; color: var(--muted); margin: .8rem 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .35rem; }
.chip-tag {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--accent); color: #fff; border-radius: 999px; padding: .2rem .3rem .2rem .6rem; font-size: .82rem;
}
.chip-tag button {
  background: rgba(255,255,255,.25); color: #fff; border: none; border-radius: 999px;
  width: 18px; height: 18px; padding: 0; line-height: 1; font-size: .7rem; display: inline-flex; align-items: center; justify-content: center;
}

/* Ursprung i resultatet – klickbara piller */
.origins-summary { margin: 0 0 1rem; font-size: .85rem; }
.origins-label { color: var(--muted); margin-right: .3rem; }
.origin-pill {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: .25rem .6rem; font-size: .82rem; margin: .15rem .25rem .15rem 0;
}
.origin-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (min-width: 560px) {
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Desktop: skala upp rot-typografin så allt växer proportionerligt + bredare kolumn */
@media (min-width: 900px) {
  :root { --maxw: 900px; }
  html { font-size: 112.5%; }          /* 16 -> 18px */
  body { line-height: 1.6; }
  main { padding: 1.5rem 1.5rem 3rem; }
  .card { padding: 1.3rem 1.5rem; }
  .filter-grid { gap: 1rem 1.3rem; margin-top: 1rem; }
  .trip { padding: 1.1rem 1.35rem; }
  .trip-meta { gap: .5rem 1rem; }
  .overview { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
}
@media (min-width: 1400px) {
  html { font-size: 118.75%; }         /* 16 -> 19px på riktigt breda skärmar */
}
