:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #1c2530;
  --muted: #647081;
  --border: #d8dee6;
  --primary: #2563c9;
  --primary-ink: #ffffff;
  --fav: #e8a500;
  --offen: #2563c9;
  --angefragt: #12a594;
  --anfrage: #e2711d;
  --abgesagt: #9aa5b1;
  --ski: #7b2ff7;
  --danger: #d1413b;
  --shadow: 0 2px 10px rgba(20,35,55,.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1621; --surface: #18212e; --surface-2: #1f2a39; --text: #e7edf4;
    --muted: #93a1b3; --border: #2b394b; --primary: #4f8cf0; --primary-ink: #06101e;
    --shadow: 0 2px 12px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1621; --surface: #18212e; --surface-2: #1f2a39; --text: #e7edf4;
  --muted: #93a1b3; --border: #2b394b; --primary: #4f8cf0; --primary-ink: #06101e;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 500;
}
.topbar-left h1 { font-size: 1.15rem; margin: 0; }
.topbar-left { display: flex; flex-direction: column; }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Beim Scrollen nur Titel + Datum zeigen, Rest ausblenden.
   padding-top behält die Notch-Safe-Area (sonst rutscht der Titel unter die Notch). */
.topbar.scrolled { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
.topbar.scrolled .topbar-right { display: none; }
.topbar.scrolled .topbar-left h1 { font-size: 1rem; }
.group-ctrl { background: var(--surface-2); padding: 6px 10px; border-radius: 8px; font-size: .9rem; white-space: nowrap; }
.group-ctrl input { width: 48px; margin: 0 2px; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 13px; border-radius: 8px;
}
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button:hover { filter: brightness(1.04); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; padding: 10px 16px 2px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi .k-value { font-size: 1.25rem; font-weight: 700; margin-top: 1px; }
.kpi .k-sub { font-size: .76rem; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; padding: 10px 16px 24px; align-items: start; }
@media (max-width: 920px) { .layout { grid-template-columns: 1fr; } }

/* ---------- Filters + table ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters input[type="search"] { flex: 1 1 200px; }
.filters label { font-size: .88rem; display: inline-flex; gap: 5px; align-items: center; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
thead th { position: sticky; top: 0; background: var(--surface-2); text-align: left; padding: 6px 8px; font-size: .74rem; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
th.num, td.num { text-align: right; }
tbody td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.active { background: color-mix(in srgb, var(--primary) 14%, var(--surface)); }
tbody tr.cancelled { opacity: .55; }
.u-name { font-weight: 600; line-height: 1.2; }
.u-place { color: var(--muted); font-size: .76rem; }
.price-main { font-weight: 700; white-space: nowrap; }
.pp { white-space: nowrap; }
.best { color: #1a8a4a; font-weight: 700; }
td.piste { font-size: .76rem; max-width: 130px; }
td.note { font-size: .74rem; color: var(--muted); max-width: 230px; line-height: 1.25; }

.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: .7rem; font-weight: 600; color: #fff; white-space: nowrap; }
.badge.favorit { background: var(--fav); }
.badge.offen { background: var(--offen); }
.badge.angefragt { background: var(--angefragt); }
.badge.anfrage { background: var(--anfrage); }
.badge.abgesagt { background: var(--abgesagt); }
.row-actions { display: flex; gap: 2px; }
.icon-btn { border: none; background: transparent; padding: 2px 4px; font-size: .95rem; line-height: 1; text-decoration: none; cursor: pointer; }
.icon-btn.fav-toggle { color: var(--abgesagt); font-size: 1.1rem; }
.icon-btn.fav-toggle:hover { color: var(--fav); }
.icon-btn.fav-toggle.on { color: var(--fav); }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; -webkit-user-select: none; touch-action: none; padding: 0 2px; font-size: 1.05rem; }
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: .4; }
.sortable-chosen { background: var(--surface-2); }
.sortable-drag { box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.hint { color: var(--muted); font-size: .8rem; margin: 7px 2px; }
.warn-flag { color: var(--anfrage); font-weight: 700; }
button.accent { background: var(--angefragt); color: #04201c; border-color: var(--angefragt); font-weight: 600; }
.link-row { display: flex; gap: 6px; }
.link-row input { flex: 1; }
.link-hint { font-size: .76rem; color: var(--muted); min-height: 1em; }
.link-hint.ok { color: #1a8a4a; }
.link-hint.err { color: var(--danger); }

/* ---------- Map ---------- */
.map-pane { position: sticky; top: 70px; }
@media (max-width: 920px) { .map-pane { position: static; } }
#map { height: 68vh; min-height: 360px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 1; }
@media (max-width: 920px) { #map { height: 46vh; } }
.map-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); margin: 8px 2px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }
.dot.fav { background: var(--fav); } .dot.offen { background: var(--offen); }
.dot.angefragt { background: var(--angefragt); }
.dot.anfrage { background: var(--anfrage); } .dot.abgesagt { background: var(--abgesagt); }
.dot.ski { background: var(--ski); }

.leaflet-popup-content { font-size: .88rem; }
.popup-title { font-weight: 700; margin-bottom: 2px; }
.popup-row { margin: 1px 0; }
.popup-actions { margin-top: 6px; display: flex; gap: 8px; }
.popup-actions a, .popup-actions button { font-size: .8rem; }

/* ---------- Overlays / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,18,30,.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.login-card, .modal-card { background: var(--surface); border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,.3); padding: 22px; width: 100%; }
.login-card { max-width: 360px; text-align: center; }
.login-card h1 { margin: 0 0 4px; }
.login-card input { width: 100%; margin: 10px 0; }
.login-card button { width: 100%; }
.modal-card { max-width: 720px; max-height: 92vh; overflow-y: auto; }
.modal-card h2 { margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: 3px; }
.grid2 label input, .grid2 label select, .grid2 label textarea { color: var(--text); }
.grid2 .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.modal-actions .spacer { flex: 1; }
.error { color: var(--danger); font-size: .85rem; margin-top: 8px; }
.admin-card { max-width: 440px; }
.switch-row { display: flex; gap: 8px; align-items: center; margin: 12px 0 4px; font-size: .95rem; }
.switch-row input { width: 18px; height: 18px; }

/* ======================================================================
   iPhone / Handy: Tabelle wird zu antippbaren Karten, große Tap-Targets,
   iOS-Safe-Area und 16px-Eingaben (kein Auto-Zoom).
   ====================================================================== */
@media (max-width: 680px) {
  body { font-size: 16px; -webkit-text-size-adjust: 100%; }
  input, select, textarea { font-size: 16px; } /* verhindert iOS-Zoom beim Fokus */

  /* Safe-Area (Notch / Home-Indikator) */
  .topbar { padding: max(8px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
  .kpis, .layout { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

  .topbar-left h1 { font-size: 1.05rem; }
  .topbar-right { gap: 6px; }
  .topbar-right button { padding: 9px 11px; }
  .group-ctrl { padding: 7px 9px; }

  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .k-value { font-size: 1.15rem; }

  .filters { gap: 10px; }
  .filters label, .filters select { font-size: .95rem; }

  /* ---- Tabelle -> Karten ---- */
  .table-wrap { overflow: visible; border: none; background: transparent; box-shadow: none; }
  #offers-table, #offers-table tbody, #offers-table tr, #offers-table td { display: block; width: auto; }
  #offers-table thead { display: none; }
  #offers-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow); margin-bottom: 11px; padding: 11px 13px;
  }
  #offers-table tr.active { outline: 2px solid var(--primary); outline-offset: 1px; }
  #offers-table td { border: none; padding: 3px 0; text-align: left; }
  #offers-table td.num { text-align: left; }

  /* Zellen mit Beschriftung: Label links, Wert rechts */
  #offers-table td[data-label] { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  #offers-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .82rem; font-weight: 600; }

  td.u-cell { margin-bottom: 7px; padding-bottom: 7px; border-bottom: 1px dashed var(--border); }
  .u-name { font-size: 1.05rem; }
  .u-place { font-size: .84rem; }
  td.price-main { font-size: 1.1rem; }
  td.piste { max-width: none; }

  /* Notiz: Label oben, Text darunter; leere ausblenden */
  td.note { max-width: none; font-size: .86rem; }
  td.note[data-label] { display: block; }
  td.note[data-label]::before { display: block; margin-bottom: 2px; }
  td.note:empty { display: none; }

  /* Aktionen: große, rechtsbündige Tap-Targets */
  td.act-cell { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--border); }
  td.act-cell .row-actions { justify-content: flex-end; gap: 14px; }
  td.act-cell .icon-btn { font-size: 1.45rem; padding: 6px 8px; }
  td.act-cell .fav-toggle { font-size: 1.55rem; }
  .drag-handle { font-size: 1.4rem; padding: 0 8px 0 0; }

  /* Karte, wenn direkt unter eine Karte geschoben: etwas Abstand */
  #offers-body > .map-pane { margin: 4px 0 12px; }
  #map { height: 52vh; }
  .map-legend { font-size: .82rem; }

  /* Modals: volle Breite, Safe-Area unten, größere Buttons */
  .overlay { padding: 10px; }
  .modal-card, .login-card, .admin-card { max-height: 90vh; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .modal-actions button { padding: 12px 15px; }
  .link-row { flex-wrap: wrap; }
  .link-row button { width: 100%; }
}
