:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2430;
  --muted: #677185;
  --border: #e1e5ec;
  --primary: #2f6fdb;
  --primary-text: #ffffff;
  --danger: #c23b3b;
  --warn-bg: #fff5df;
  --warn-text: #8a5a00;
  --ok-bg: #e5f5ea;
  --ok-text: #1e6b3a;
  --info-bg: #e8f0fd;
  --info-text: #234f9c;
  --err-bg: #fde8e8;
  --err-text: #9c2323;
  --c-private: #e3f1ff; --t-private: #1c5a99;
  --c-towork: #f1e8ff;  --t-towork: #5b2c9e;
  --c-work: #e5f5ea;    --t-work: #1e6b3a;
  --c-mix: #fff1e0;     --t-mix: #8a4b00;
  --c-open: #fde8e8;    --t-open: #9c2323;
  /* Diagrammfarben (validiert gegen Farbsehschwäche): Personen s-1/s-2, Fahrzeuge v-1/v-2 */
  --s-1: #2a78d6; --s-2: #eb6834; --s-3: #1baf7a; --s-4: #eda100;
  --v-1: #1baf7a; --v-2: #4a3aa7;
  --s-open: #c9ccd3;
  --grid: #eceef2; --axis: #c9ccd3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ef;
    --muted: #98a2b5;
    --border: #2c3340;
    --primary: #5b8ff0;
    --warn-bg: #3a2e12; --warn-text: #f3c86b;
    --ok-bg: #163322;   --ok-text: #8fdcaa;
    --info-bg: #1a2b4a; --info-text: #a9c4f5;
    --err-bg: #3d1b1b;  --err-text: #f2a3a3;
    --c-private: #1a3150; --t-private: #a9cdf5;
    --c-towork: #2e2148;  --t-towork: #cdb3f5;
    --c-work: #163322;    --t-work: #8fdcaa;
    --c-mix: #3a2a12;     --t-mix: #f3c27b;
    --c-open: #3d1b1b;    --t-open: #f2a3a3;
    --s-1: #3987e5; --s-2: #d95926; --s-3: #199e70; --s-4: #c98500;
    --v-1: #199e70; --v-2: #9085e9;
    --s-open: #4a5160;
    --grid: #262c37; --axis: #3a4250;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Kopfzeile */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; align-items: center; }
.mainnav > a, .menu > summary {
  color: var(--muted); text-decoration: none; padding: .3rem .6rem; border-radius: 6px; cursor: pointer;
}
.mainnav > a:hover, .menu > summary:hover { color: var(--text); background: var(--bg); }
.mainnav > a.active, .menu > summary.active { color: var(--text); background: var(--bg); font-weight: 600; }
.menu { position: relative; }
.menu > summary { list-style: none; display: inline-flex; align-items: center; gap: .3rem; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; width: .4em; height: .4em; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); }
.menu-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 170px;
  display: flex; flex-direction: column; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(20, 30, 50, .12);
}
.menu-list a { color: var(--text); text-decoration: none; padding: .4rem .6rem; border-radius: 6px; }
.menu-list a:hover { background: var(--bg); }
.menu-list a.active { font-weight: 600; color: var(--primary); }
.subnav {
  display: flex; gap: .25rem; overflow-x: auto; padding: 0 max(16px, calc((100% - 1100px) / 2 + 16px));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.subnav a { padding: .5rem .8rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.who { color: var(--muted); font-size: .85rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

/* ---------- Elemente */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .45rem .9rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .2rem .6rem; font-size: .85rem; }
.btn.wide { width: 100%; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }

input[type=text], input[type=email], input[type=date], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .35rem .5rem;
  max-width: 100%;
}
input.pct { width: 5rem; text-align: right; }
label { display: block; margin: .5rem 0; }
label > input[type=text], label > input[type=email], label > select, label > textarea { display: block; width: 100%; margin-top: .2rem; }
label.check { display: flex; gap: .5rem; align-items: flex-start; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: .75rem 0; }
legend { color: var(--muted); font-size: .85rem; padding: 0 .3rem; }
.actions { margin-top: .75rem; }
.inline-action { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem 1rem; margin: 0 0 1rem; }
.inline-action label { margin: 0; }
form.inline { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 1rem 0; box-shadow: var(--shadow);
}
.flash { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); }
.flash.info { background: var(--info-bg); color: var(--info-text); }
.flash a { color: inherit; font-weight: 600; }

.badge {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  white-space: nowrap;
}
.badge.private { background: var(--c-private); color: var(--t-private); }
.badge.towork  { background: var(--c-towork);  color: var(--t-towork); }
.badge.work    { background: var(--c-work);    color: var(--t-work); }
.badge.mix     { background: var(--c-mix);     color: var(--t-mix); }
.badge.open, .badge.warn { background: var(--c-open); color: var(--t-open); }

/* ---------- Startseite */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: .25rem; padding: 1.1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--primary); }
.tile-title { font-weight: 700; font-size: 1.05rem; }
.tile-text { color: var(--muted); font-size: .9rem; }
.tile .badge { align-self: flex-start; margin-top: .3rem; }

/* ---------- Fahrtenbuch */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .5rem; }
.page-head h1 { margin: 0; }
.month-nav { display: flex; align-items: center; gap: .6rem; }
.month-nav strong { min-width: 9.5rem; text-align: center; }
.sync-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
.sync-row form { margin: 0; }
.sync-range { flex-basis: auto; }
.sync-range summary { list-style: none; }
.sync-range summary::-webkit-details-marker { display: none; }
.sync-range[open] { flex-basis: 100%; }
.sync-range[open] summary { margin-bottom: .5rem; }
.sync-range form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.pending-job { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat {
  display: flex; flex-direction: column; padding: .8rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.stat.warn { border-color: var(--t-open); }
.stat.warn .stat-value { color: var(--t-open); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .8rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.compact { width: auto; min-width: 50%; }
.form-table td { padding: .35rem .4rem; }
.form-table input[type=text] { width: 100%; min-width: 8rem; }

.trips { border: 1px solid var(--border); border-radius: var(--radius); }
.trips tr.is-open { background: var(--warn-bg); }
.trips td:first-child { white-space: nowrap; }
.trips .route { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .8rem;
  border: 1px solid var(--border); border-radius: 4px; padding: .05rem .35rem; white-space: nowrap;
}
.who-chip { display: inline-block; font-size: .85rem; white-space: nowrap; margin-right: .5rem; font-variant-numeric: tabular-nums; }
.trips select { padding: .2rem .3rem; font-size: .85rem; }
.cat-form { display: inline-block; }
.trips select.cat-private { background: var(--c-private); color: var(--t-private); border-color: transparent; }
.trips select.cat-towork  { background: var(--c-towork);  color: var(--t-towork);  border-color: transparent; }
.trips select.cat-work    { background: var(--c-work);    color: var(--t-work);    border-color: transparent; }
.trips select.cat-mix     { background: var(--c-mix);     color: var(--t-mix);     border-color: transparent; }
.changed { color: var(--muted); font-size: .85rem; margin-left: .3rem; cursor: help; }

.sync-progress { max-width: 640px; margin: 2rem auto; }
.sync-progress form { display: flex; gap: .5rem; flex-wrap: wrap; }
.progress { height: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 1rem 0 .5rem; }
.progress-bar { height: 100%; background: var(--primary); transition: width .3s; }

/* ---------- Übersicht / Diagramme */
.btn.disabled { opacity: .35; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 0 1rem; }
.dash-grid .card { margin: 0 0 1rem; }
.stat-label .swatch { margin-right: .35rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin: .25rem 0 .5rem; font-size: .85rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.chart-plot { position: relative; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-svg .axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .hit { fill: transparent; cursor: default; }
.chart-svg .hit.hover { fill: var(--text); fill-opacity: .045; }
.chart-table { margin-top: .5rem; font-size: .85rem; }
.chart-table summary { cursor: pointer; color: var(--muted); }
.chart-table table { margin-top: .5rem; }
.chart-table th, .chart-table td { padding: .3rem .5rem; }

.share { display: grid; gap: .8rem; margin-top: .5rem; }
.share-row { display: grid; grid-template-columns: minmax(130px, 220px) 1fr; gap: .75rem; align-items: center; }
.share-label { display: flex; flex-direction: column; font-size: .9rem; line-height: 1.3; }
.share-label .muted { font-size: .8rem; font-variant-numeric: tabular-nums; }
.share-bar { display: flex; gap: 2px; height: 26px; }
.share-seg { flex-basis: 0; min-width: 3px; display: flex; align-items: center; justify-content: center; overflow: visible; }
.share-seg:first-child { border-radius: 4px 0 0 4px; }
.share-seg:last-child { border-radius: 0 4px 4px 0; }
.share-seg:only-child { border-radius: 4px; }
.share-seg.hover { filter: brightness(1.08); }
.share-pct { color: #fff; font-size: .78rem; font-weight: 600; white-space: nowrap; text-shadow: 0 0 2px rgba(0,0,0,.35); }
.share-seg.light .share-pct { color: var(--text); text-shadow: none; font-weight: 500; }
.share-empty { color: var(--muted); font-size: .85rem; align-self: center; }

.chart-tip {
  position: absolute; z-index: 50; pointer-events: none; min-width: 150px; max-width: 260px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .65rem; font-size: .82rem; box-shadow: 0 6px 20px rgba(20, 30, 50, .15);
}
.chart-tip-title { font-weight: 600; margin-bottom: .25rem; }
.chart-tip-row { display: flex; align-items: center; gap: .45rem; }
.chart-tip-row.total { border-top: 1px solid var(--border); margin-top: .25rem; padding-top: .25rem; font-weight: 600; }
.chart-tip-name { flex: 1; color: var(--muted); }
.chart-tip-row.total .chart-tip-name { color: var(--text); }
.chart-tip-val { font-variant-numeric: tabular-nums; }
.swatch.none { background: transparent; }

/* Verwaltung */
.user-row { border-bottom: 1px solid var(--border); padding: .5rem 0; }
.user-row summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; list-style: none; }
.user-row summary::-webkit-details-marker { display: none; }
.user-row summary::before { content: "▸"; color: var(--muted); }
.user-row[open] summary::before { content: "▾"; }
.user-main { flex: 1; min-width: 200px; }
.user-row form.stack { max-width: 520px; padding: .5rem 0 .25rem 1.1rem; }
.user-row > form:last-child { padding-left: 1.1rem; margin-bottom: .5rem; }
.person-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: .75rem; align-items: end; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 2rem 1.5rem; box-shadow: var(--shadow); text-align: center;
}
.dev-login { margin-top: 1.5rem; border-top: 1px dashed var(--border); padding-top: 1rem; display: grid; gap: .5rem; }

/* ---------- Handy: Fahrtentabelle als Karten */
@media (max-width: 720px) {
  .trips, .trips tbody, .trips tr, .trips td { display: block; width: 100%; }
  .trips { border: 0; background: none; }
  .trips thead { display: none; }
  .trips tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: .6rem; padding: .4rem .2rem;
  }
  .trips td { border: 0; padding: .15rem .7rem; display: flex; justify-content: space-between; gap: 1rem; }
  .trips td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; flex-shrink: 0; }
  .trips .route { max-width: none; white-space: normal; text-align: right; }
  .trips td.num { text-align: right; }
  .person-row { grid-template-columns: 1fr; }
  .who { display: none; }
}
