:root {
  --emerald: #059669;
  --emerald-dark: #047857;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-border: #f59e0b;
  --radius: 10px;        /* Cards */
  --radius-sm: 6px;      /* Buttons, Felder, Tags */
  --control-h: 40px;     /* einheitliche Höhe für Buttons & Felder (Touch-Target) */
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}
main { max-width: 1280px; margin: 0 auto; padding: 1rem clamp(0.75rem, 2vw, 1.5rem); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--emerald); color: #fff; padding: 0.6rem 1rem;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: #fff; text-decoration: none;
  font-size: 1.35rem; font-weight: 600; letter-spacing: -0.5px; }
.topbar nav a { color: #fff; text-decoration: none; margin-left: 1rem; opacity: 0.92; font-size: 0.95rem; }
.topbar nav a:hover { opacity: 1; text-decoration: underline; }
.topbar nav a.active { opacity: 1; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.burger { display: none; background: none; border: none; cursor: pointer; min-height: 0;
  width: 40px; height: 40px; padding: 0; flex-direction: column; align-items: center; justify-content: center; gap: 5px; }
.burger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.card h2 { margin-top: 0; font-size: 1.15rem; }
.card.error { border-color: var(--danger); color: var(--danger); }
.card.warn { background: var(--warn-bg); border-color: var(--warn-border); font-weight: 500; }

.grid { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
input:not([type=checkbox]), select { min-height: var(--control-h); padding: 0.45rem 0.6rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.95rem; background: #fff; color: var(--text); max-width: 100%; }
input:focus, select:focus { outline: 2px solid var(--emerald); border-color: var(--emerald); }
input[type=checkbox] { width: 1.2rem; height: 1.2rem; min-height: 0; accent-color: var(--emerald); cursor: pointer; }
/* Selects an Inputs angleichen: native OS-Optik entfernen, eigener Pfeil */
select { appearance: none; -webkit-appearance: none; -moz-appearance: none; padding-right: 1.9rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.7rem center; background-size: 0.7rem auto; }

/* Abfrage-Formular: Fahrzeug/Orte breiter, Zahlenfelder kompakt, alle füllen ihre Spalte */
.query .grid > label { flex: 1 1 160px; min-width: 0; }
.query .grid > label > select,
.query .grid > label > input { width: 100%; }
.query .grid > label:nth-child(4),  /* Umkreis */
.query .grid > label:nth-child(5),  /* Tankfüllstand */
.query .grid > label:nth-child(6) { /* Payback */
  flex: 0 1 110px;
}
/* Generische Feld-Breiten-Helfer für jedes .grid (Abfrage, Umkreis, Settings, Station) */
.grid > label.fld-wide { flex: 2 1 14rem; min-width: 0; }
.grid > label.fld { flex: 1 1 9rem; min-width: 0; }
.grid > label.fld-narrow { flex: 0 1 7rem; min-width: 0; }
.grid > label.fld-check { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 0.45rem; }
.grid > label.fld-wide > input, .grid > label.fld > input,
.grid > label.fld-narrow > input, .grid > label > select { width: 100%; }
.grid > label.fld-check > input { width: auto; }

/* Tabs (Startseite: Tankcheck / Umkreis) */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; background: #f1f5f9;
  border-radius: var(--radius-sm); padding: 0.25rem; margin-bottom: 1rem; }
.tab { background: none; min-height: 36px; padding: 0.45rem 1.1rem; font-weight: 500;
  color: var(--muted); border-radius: calc(var(--radius-sm) - 1px); }
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); }

/* Übersichts-Kopf mit Fahrzeug-Dropdown */
.ov-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 0.8rem; }
.ov-head h2 { margin: 0; }
.ov-veh { flex-direction: row; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.fill-note { margin-top: -0.4rem; }

/* Settings als Karten je Eintrag */
.section-title { font-size: 1.15rem; font-weight: 600; margin: 0.5rem 0 0.8rem; }
.card.item { padding: 0.9rem 1rem; }
.item-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.8rem; }
.item-actions .coords { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: auto; font-size: 0.85rem; }

button { cursor: pointer; border: none; border-radius: var(--radius-sm); font-size: 0.9rem;
  min-height: var(--control-h); padding: 0.5rem 0.95rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; }
button.primary { background: var(--emerald); color: #fff; font-weight: 500; }
button.primary:hover { background: var(--emerald-dark); }
button.secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #e2e8f0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.nb-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.8rem; }
button.small { min-height: 34px; padding: 0.35rem 0.7rem; font-size: 0.82rem; background: #f1f5f9; }
button.danger { background: #fee2e2; color: var(--danger); }
button.link { background: none; color: var(--emerald); min-height: 0; padding: 0; text-decoration: underline; font-size: inherit; }
.query button.primary { margin-top: 0.8rem; }
.inline { display: inline; }

.spinner { display: inline-block; width: 0.85em; height: 0.85em; vertical-align: -0.1em;
  border: 2px solid var(--border); border-top-color: var(--emerald); border-radius: 50%;
  animation: spin 0.7s linear infinite; }
#refreshState { color: var(--emerald-dark); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Vollflächiger Lade-Overlay beim Tankcheck */
#loadingOverlay { position: fixed; inset: 0; z-index: 9999;
  background: rgba(248, 250, 252, 0.88); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; }
#loadingOverlay[hidden] { display: none; }
.loadbox { display: flex; flex-direction: column; align-items: center; gap: 0.9rem;
  color: var(--emerald-dark); font-size: 1.15rem; font-weight: 500; text-align: center; }
.loadbox small { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.spinner.big { width: 3rem; height: 3rem; border-width: 4px; }

.summary { display: flex; flex-wrap: wrap; gap: 1.5rem; }
.summary .k { display: block; font-size: 0.8rem; color: var(--muted); }
.summary .v { font-size: 1.25rem; font-weight: 600; }
.summary .v.emph { color: var(--emerald); }
.summary small { display: block; color: var(--muted); font-size: 0.72rem; }

.map { height: clamp(300px, 46vh, 480px); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 1rem; }

.calc-explain { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.85rem 1rem; margin-bottom: 1rem; }
.calc-explain[hidden] { display: none; }
.popup-navi { display: inline-block; margin-top: 0.35rem; color: var(--emerald-dark);
  font-weight: 500; text-decoration: none; }
.popup-navi:hover { text-decoration: underline; }
.calc-explain h3 { margin: 0 0 0.5rem; font-size: 1rem; color: var(--emerald-dark); }
ol.calc { margin: 0; padding-left: 1.3rem; }
ol.calc li { margin: 0.3rem 0; font-size: 0.9rem; line-height: 1.55; }
ol.calc li::marker { color: var(--muted); }
.cx-note { color: var(--muted); font-size: 0.86em; }
.cx-warn { color: #b45309; font-weight: 500; }

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

.tablebar { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin: 0.6rem 0; font-size: 0.85rem; color: var(--muted); }
.tablebar .pp { flex-direction: row; align-items: center; gap: 0.4rem; }
.tablebar .pager { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
th.sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.sort:hover { color: var(--text); }
th.sort.active-asc::after { content: " ▲"; font-size: 0.7em; }
th.sort.active-desc::after { content: " ▼"; font-size: 0.7em; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
.tag { display: inline-block; font-size: 0.66rem; font-weight: 500; padding: 0.05rem 0.3rem;
  border-radius: var(--radius-sm); background: #e2e8f0; color: #475569; vertical-align: middle; }
.tag.fr { background: #dbeafe; color: #1e40af; }
.discsb { white-space: nowrap; }
.disc { color: var(--emerald-dark); font-size: 0.82rem; }
.sb { color: var(--muted); font-size: 0.82rem; margin-left: 0.2rem; cursor: help; }

table { width: 100%; border-collapse: collapse; }
table.result th, table.result td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
table.result th { color: var(--muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.result td.num { font-weight: 600; }
table.result tr.meh { color: var(--muted); }
table small { display: block; color: var(--muted); font-size: 0.72rem; }
table a { color: var(--emerald); text-decoration: none; }
table a:hover { text-decoration: underline; }
.editlink { color: var(--muted); margin-left: 0.3rem; font-size: 0.82rem; text-decoration: none; }
.editlink:hover { color: var(--emerald); }

.hint { color: var(--muted); font-size: 0.82rem; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 1rem 0 0.8rem; }

/* Dashboard: Fahrzeug-Carousel (Scroll-Snap, Anzahl Fahrzeuge egal) */
.vcarousel { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 6px; margin-bottom: 0.6rem; -webkit-overflow-scrolling: touch; }
.vcarousel .vtile { flex: 0 0 min(85%, 340px); scroll-snap-align: start;
  text-decoration: none; color: var(--text); display: block; margin-bottom: 0; }
.vtile:hover { border-color: var(--emerald); }
.vtile-head { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap;
  font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.vtile-price { font-size: 2.1rem; font-weight: 600; color: var(--emerald); line-height: 1.15; }
.vtile-unit { font-size: 1rem; font-weight: 400; color: var(--muted); margin-left: 2px; }
.vtile-sub { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }

/* Dashboard: Info- und Schnellzugriff-Kacheln */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 0.8rem; }
button.dtile { font-size: inherit; line-height: 1.5; min-height: 0; }
.dtile { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem;
  text-align: left; text-decoration: none; color: var(--text); margin-bottom: 0; cursor: pointer; }
.dtile:hover { border-color: var(--emerald); }
.dtile-head { font-size: 0.85rem; color: var(--muted); }
.dtile-big { font-size: 1.15rem; font-weight: 600; }
.dtile-big .hint { font-weight: 400; }
.dtile-detail { width: 100%; margin-top: 0.4rem; border-top: 1px solid var(--border); padding-top: 0.4rem; }
.el-row { display: flex; flex-wrap: wrap; gap: 0.6rem; font-size: 0.85rem; padding: 0.15rem 0; }
.dtile-more { margin-top: 0.2rem; }
.dtile.qa { align-items: center; text-align: center; justify-content: center; gap: 0.15rem; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  vertical-align: -1px; margin-right: 0.3rem; flex: none; }
/* Erklär-Overlay der Ampel: mobil Bottom-Sheet, Desktop zentriertes Modal */
.ovl-backdrop { position: fixed; inset: 0; z-index: 9000; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-end; justify-content: center; }
.ovl-backdrop[hidden] { display: none; }
.ovl-sheet { background: var(--card); width: 100%; max-width: 580px; max-height: 92vh;
  overflow-y: auto; border-radius: 16px 16px 0 0; padding: 1.1rem 1.15rem 1.3rem; }
@media (min-width: 641px) {
  .ovl-backdrop { align-items: center; padding: 1rem; }
  .ovl-sheet { border-radius: 16px; }
}
.ovl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.4rem; }
.ovl-verdict { font-size: 1.15rem; font-weight: 600; display: flex; align-items: center; }
.ovl-sub { font-size: 0.9rem; color: var(--text); margin-top: 0.25rem; }
.ovl-close { min-height: 0; width: 34px; height: 34px; border-radius: 50%; background: #f1f5f9;
  padding: 0; font-size: 1.15rem; flex: none; }
.ovl-sheet svg { display: block; width: 100%; margin: 0.4rem 0 0.1rem; }
.legend { display: flex; gap: 0.9rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--muted); margin: 0 0 0.7rem; }
.leg-line { display: inline-block; width: 16px; vertical-align: middle; margin-right: 4px; }
.ovl-block { display: flex; gap: 0.6rem; font-size: 0.9rem; line-height: 1.55;
  border-top: 1px solid var(--border); padding-top: 0.6rem; margin-top: 0.6rem; }
.ovl-block .ico { flex: none; }
.ovl-foot { border-top: 1px solid var(--border); margin-top: 0.8rem; padding-top: 0.55rem;
  font-size: 0.75rem; color: var(--muted); }

.opening { margin: 0.3rem 0 0.7rem; }
.opening-list { margin: 0.25rem 0 0; padding-left: 1.2rem; font-size: 0.88rem; }
.opening-list li { padding: 0.05rem 0; }
.spark-labels { display: flex; justify-content: space-between; width: 100%; }
.dtile svg { display: block; width: 100%; margin: 0.2rem 0; }
.qa-ico { font-size: 1.5rem; }
.qa-title { font-weight: 600; font-size: 0.95rem; }

/* Such-Combobox (Preishistorie: Station nach Name/Ort suchen) */
.combo { position: relative; }
.combo input[type=text] { padding-right: 2.3rem; }
.combo-clear { position: absolute; right: 0.35rem; bottom: calc(var(--control-h) / 2);
  transform: translateY(50%); width: 30px; height: 30px; min-height: 0; padding: 0;
  border-radius: 50%; background: transparent; color: var(--muted);
  font-size: 1.25rem; line-height: 1; }
.combo-clear:hover { background: #e2e8f0; color: var(--text); }
.combo-clear[hidden] { display: none; }
.combo-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 280px; overflow-y: auto; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); }
.combo-list[hidden] { display: none; }
.combo-item { padding: 0.5rem 0.65rem; cursor: pointer; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 0.9rem; }
.combo-item:last-child { border-bottom: none; }
.combo-item:hover, .combo-item.active { background: var(--bg); }
.combo-item small { color: var(--muted); display: block; font-size: 0.75rem; }

/* Login-Seite */
.login-wrap { max-width: 440px; margin: 9vh auto 0; padding: 1rem;
  display: flex; flex-direction: column; align-items: center; gap: 1.6rem; }
.login-banner { width: 100%; max-width: 400px; height: auto; }
.login-card { width: 100%; display: flex; flex-direction: column; gap: 0.9rem; }
.login-card label { font-size: 0.85rem; }
.login-card input { width: 100%; }
.login-error { color: var(--danger); margin: 0; font-size: 0.9rem; }

.foot { max-width: 1280px; margin: 1rem auto; padding: 0 1rem 2rem; color: var(--muted);
  font-size: 0.82rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* Tablet */
@media (max-width: 820px) {
  .summary { gap: 1rem; }
  .summary > div { flex: 1 1 40%; }
}

/* Mobile */
@media (max-width: 640px) {
  .topbar { position: relative; }
  .burger { display: flex; }
  .topbar nav { position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
    display: none; flex-direction: column; background: var(--emerald-dark);
    padding: 0.25rem 1rem 0.6rem; box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18); }
  .topbar nav.open { display: flex; }
  .topbar nav a { margin-left: 0; padding: 0.75rem 0; font-size: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15); }
  .topbar nav a.active { text-decoration: none; }

  /* Alle Formular-Grids stapeln; px-flex-basis nicht als Höhe wirken lassen */
  .grid { flex-direction: column; align-items: stretch; }
  .grid > label { flex: 1 1 auto !important; }
  .grid > label.fld-check { flex-direction: row; }
  .query button.primary, .item-actions .small.primary { width: 100%; }
  .summary > div { flex: 1 1 100%; }
  .map { height: 320px; }
  .tablebar { font-size: 0.8rem; }
  .tablebar .pager { margin-left: 0; }

  /* Ergebnis-Tabelle: Nebensächliches ausblenden statt 9 Spalten zu quetschen.
     Sichtbar: # · Station · Preis · Entfernung · Netto. Ausgeblendet: Rabatt, Gesamtkosten, Mehrzeit, €/h */
  table.result th:nth-child(4), table.result td:nth-child(4),
  table.result th:nth-child(5), table.result td:nth-child(5),
  table.result th:nth-child(7), table.result td:nth-child(7),
  table.result th:nth-child(9), table.result td:nth-child(9) { display: none; }
  table.result td, table.result th { white-space: normal; }
}
