/* ICS Door-to-Door – Oberfläche
   ---------------------------------------------------------------------------
   Der Arbeitsbereich ist immer zweispaltig: LINKS die Haushalte des gewählten
   Hauses, RECHTS alles zum gewählten Haushalt (Fortschritt, Ausgang, Kunde,
   Verlauf). Nur die Verpackung wechselt mit der Geräteausrichtung:

   • Querformat (>= 900px): zwei schmale Panels an den Kartenrändern, die Karte
                            läuft dazwischen durch.
   • Hochformat (< 900px):  dieselben zwei Spalten in einem Bottom-Sheet mit
                            Griff (halb / ganz / zu).

   Gestaltungsprinzip: ruhige Flächen, Haarlinien statt Rahmen, Bedeutung über
   Icon-Chips statt über Farbflächen. Jede Kachel trägt links ein Icon im
   abgerundeten Quadrat – im Ruhezustand grau, aktiv in der Farbe der Sache.
   Primäre Touchziele bleiben bei mindestens 44px.
*/

:root {
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #e6ebf2;
  --line-soft: #f1f5f9;
  --bg: #f6f8fb;
  --card: #ffffff;
  --accent: #2563eb;

  --topbar-h: 46px;
  --wp-l: 236px;             /* linkes Panel: Haushalte */
  --wp-r: 336px;             /* rechtes Panel: Detail */
  --r-tile: 12px;
  --r-field: 10px;
  --shadow-tile: 0 1px 1.5px rgba(15, 23, 42, .03);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;             /* kein Seiten-Scroll – nur Panels scrollen */
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { display: flex; flex-direction: column; }

button, input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }

/* ===========================================================================
   Kopfzeile
   =========================================================================== */

.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex; align-items: center; gap: 14px;
  background: #0b1220; color: #f8fafc;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, .07);
  z-index: 30;
}

.brand {
  display: flex; align-items: center; gap: 7px;
  font-weight: 700; letter-spacing: .08em; font-size: 12.5px;
  color: #7dd3fc; flex: 0 0 auto;
}

.tabs { display: flex; gap: 2px; background: rgba(255, 255, 255, .07); padding: 3px; border-radius: 10px; }
.tab {
  appearance: none; border: 0; background: transparent;
  color: #b5c2d3; font-size: 13px; font-weight: 600;
  padding: 6px 16px; border-radius: 7px; cursor: pointer; min-height: 30px;
  transition: background .15s, color .15s;
}
.tab.active { background: #f8fafc; color: #0b1220; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.stat-chip { font-size: 12px; color: #7d8da3; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-chip b { color: #e8eef6; font-weight: 600; }

/* ===========================================================================
   Ansichten
   =========================================================================== */

.views { flex: 1 1 auto; position: relative; min-height: 0; }
.view { display: none; position: absolute; inset: 0; }
.view.active { display: block; }

.map-area { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #dde4ed; }

body.placing #map { cursor: crosshair; }

.place-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 22;
  display: flex; align-items: center; gap: 10px;
  background: #0b1220; color: #f8fafc;
  padding: 7px 8px 7px 15px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(11, 18, 32, .3);
  max-width: calc(100% - 20px);
}
.place-hint[hidden] { display: none; }
.hint-x {
  appearance: none; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .14); color: #f8fafc;
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
}

/* ---- Kartensteuerung ---- */

.map-controls {
  position: absolute; right: 14px; bottom: 14px; z-index: 19;
  display: flex; flex-direction: column; gap: 9px;
  transition: right .2s ease, bottom .26s cubic-bezier(.32, .72, 0, 1), opacity .2s;
}
.map-ctrl {
  appearance: none; border: 1px solid rgba(15, 23, 42, .06); cursor: pointer;
  width: 46px; height: 46px; border-radius: 14px;
  background: #fff; color: var(--ink-2);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .16), 0 1px 3px rgba(15, 23, 42, .08);
  transition: transform .12s ease;
}
.map-ctrl:active { transform: scale(.93); }
.map-ctrl.primary { background: var(--accent); border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .35); }
body.placing .map-ctrl.primary { background: #0b1220; box-shadow: 0 6px 18px rgba(11, 18, 32, .35); }

/* ---- Nadeln ---- */

.pin {
  position: relative;
  width: 32px; height: 32px; border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--pin-color, #64748b);
  border: 2.5px solid #fff;
  box-shadow: 0 3px 9px rgba(15, 23, 42, .42);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pin span {
  transform: rotate(45deg);
  color: #fff; font-size: 12.5px; font-weight: 700; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.pin.selected {
  width: 40px; height: 40px; z-index: 10;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .45), 0 5px 14px rgba(15, 23, 42, .45);
}
.pin.selected span { font-size: 14px; }

/* ===========================================================================
   Arbeitsbereich – Querformat: zwei Panels an den Kartenrändern
   =========================================================================== */

.work {
  position: absolute; inset: 0; z-index: 18;
  pointer-events: none;               /* die Lücke gehört der Karte */
  opacity: 0; visibility: hidden;
  transition: opacity .16s ease, visibility .16s ease;
}
.work.open { opacity: 1; visibility: visible; }

.work-cols { display: flex; justify-content: space-between; height: 100%; }

.wp {
  pointer-events: auto;
  background: var(--card);
  display: flex; flex-direction: column;
  min-height: 0;
}
.wp-left  { width: var(--wp-l); border-right: 1px solid var(--line); box-shadow:  8px 0 28px rgba(15, 23, 42, .08); }
.wp-right { width: var(--wp-r); border-left:  1px solid var(--line); box-shadow: -8px 0 28px rgba(15, 23, 42, .08); }

.sheet-grip { display: none; }

/* Kopf eines Panels: bleibt beim Scrollen stehen. */
.wp-head {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  display: flex; align-items: center; gap: 7px;
  min-height: 50px;
}
.wp-title { flex: 1 1 auto; min-width: 0; }
.wp-title strong {
  display: block; font-size: 14.5px; font-weight: 650; letter-spacing: -.005em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wp-title small {
  display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.wp-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: #fbfcfe;                /* Kacheln heben sich als Weiß darauf ab */
}
.wp-foot {
  flex: 0 0 auto; border-top: 1px solid var(--line-soft);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}

/* ===========================================================================
   Eingabefelder mit Icon
   =========================================================================== */

.ifield { position: relative; margin-bottom: 7px; }
.ifield:last-child { margin-bottom: 0; }

.ifield-ic {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  display: flex; color: #a5b2c4; pointer-events: none;
  transition: color .15s;
}
.ifield input, .ifield textarea {
  width: 100%; display: block; appearance: none;
  border: 1px solid var(--line); border-radius: var(--r-field);
  background: #fff; color: var(--ink);
  padding: 9px 11px 9px 38px; min-height: 40px;
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}
.ifield textarea { min-height: 74px; padding-top: 10px; resize: vertical; line-height: 1.45; }
.ifield-area .ifield-ic { top: 13px; transform: none; }
.ifield input::placeholder, .ifield textarea::placeholder { color: #aab6c6; }
.ifield input:focus, .ifield textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.ifield:focus-within .ifield-ic { color: var(--accent); }

/* Kompakte Variante für die Adresse im Panelkopf. */
.wp-head .ifield { flex: 1 1 auto; margin: 0; min-width: 0; }
.ifield-sm .ifield-ic { left: 9px; }
.ifield-sm input {
  min-height: 36px; padding: 7px 9px 7px 32px;
  font-size: 13px; font-weight: 600;
}
.a-nr {
  flex: 0 0 50px; width: 50px; text-align: center; appearance: none;
  border: 1px solid var(--line); border-radius: var(--r-field); background: #fff;
  min-height: 36px; padding: 7px 4px; font-size: 13px; font-weight: 600;
  transition: border-color .15s, box-shadow .15s;
}
.a-nr:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.a-nr::placeholder { color: #aab6c6; font-weight: 500; }

/* ===========================================================================
   Knöpfe
   =========================================================================== */

.icon-btn {
  appearance: none; border: 1px solid var(--line); background: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:active { background: var(--line-soft); }

.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: var(--r-tile); padding: 8px 12px; min-height: 38px;
  font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:active { background: var(--line-soft); }
.btn.block { width: 100%; }
.btn.dashed { border-style: dashed; border-color: #d5dde8; color: var(--ink-2); background: transparent; }
.btn.dashed:active { background: #fff; border-color: var(--accent); color: var(--accent); }
.btn.ghost-danger {
  color: #e11d48; border-color: transparent; background: transparent;
  font-weight: 500; min-height: 34px; font-size: 12.5px;
}
.btn.ghost-danger:active { background: #fff1f2; }

/* ===========================================================================
   Haushaltsliste (linkes Panel)
   =========================================================================== */

.wpl-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 12px 7px;
  font-size: 10px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.wpl-count {
  letter-spacing: 0; font-size: 11px; font-weight: 600; color: var(--ink-2);
  background: var(--line-soft); padding: 2px 8px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.hh-list { display: flex; flex-direction: column; gap: 5px; padding: 0 9px; }

.hh-row {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-tile);
  background: #fff; padding: 6px 8px; min-height: 48px;
  box-shadow: var(--shadow-tile);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.hh-row:active { background: var(--line-soft); }
.hh-row.on {
  border-color: var(--accent); background: #f6faff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

/* Icon-Chip mit der Farbe des Ausgangs – ohne Ausgang bleibt er neutral. */
.hh-ic {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--c);
  background: #f1f5f9;
  background: color-mix(in srgb, var(--c) 13%, #fff);
}
.hh-ic.idle { background: var(--line-soft); color: #b9c4d2; }

.hh-main { flex: 1 1 auto; min-width: 0; }
.hh-name {
  display: block; font-weight: 600; font-size: 13px; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hh-meta {
  display: block; font-size: 11px; color: var(--muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hh-flags { display: flex; gap: 3px; flex: 0 0 auto; }
.hh-flag {
  width: 20px; height: 20px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: #e7f8ee; color: #15803d;
}

.wpl-add { padding: 9px; }

/* ===========================================================================
   Abschnitte im rechten Panel
   =========================================================================== */

.sec { padding: 12px; border-bottom: 1px solid var(--line-soft); }
.sec:last-child { border-bottom: 0; }
.sec > h3 {
  margin: 0 0 8px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em; color: var(--muted);
}

/* Gemeinsamer Icon-Chip für Fortschritts- und Ausgangskacheln. */
.tile-ic {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--line-soft); color: #a5b2c4;
  transition: background .15s, color .15s;
}

/* ---- Fortschritt: volle Breite, damit die Beschriftung ganz dasteht ---- */

.checks { display: flex; flex-direction: column; gap: 6px; }
.check {
  appearance: none; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--r-tile);
  background: #fff; padding: 6px 10px 6px 6px; min-height: 46px;
  box-shadow: var(--shadow-tile);
  transition: border-color .15s, background .15s;
}
.tile-label {
  flex: 1 1 auto; min-width: 0; font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-time {
  flex: 0 0 auto; font-size: 11.5px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.check.on { border-color: #b7ebcb; background: #f4fdf7; }
.check.on .tile-ic { background: #16a34a; color: #fff; }
.check.on .tile-label { color: #15803d; }
.check.on .tile-time { color: #4ba36f; }

/* ---- Ausgänge: zwei Spalten, Beschriftung darf zweizeilig werden ---- */

.outcomes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.outcomes .out-btn:last-child { grid-column: 1 / -1; }   /* Übersprungen breit */

.out-btn {
  appearance: none; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--r-tile);
  background: #fff; padding: 6px 8px 6px 6px; min-height: 46px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  box-shadow: var(--shadow-tile);
  transition: border-color .15s, background .15s, color .15s;
}
.out-label { min-width: 0; line-height: 1.2; }
.out-btn:active { background: var(--line-soft); }
.out-btn.on {
  /* Rückfall zuerst, danach die color-mix-Variante für neuere Browser. */
  background: #f8fafc; color: var(--ink); border-color: #cbd5e1;
  background: color-mix(in srgb, var(--c) 6%, #fff);
  color: color-mix(in srgb, var(--c) 74%, #0f172a);
  border-color: color-mix(in srgb, var(--c) 42%, #fff);
}
.out-btn.on .tile-ic { background: var(--c); color: #fff; }

/* ---- Verlauf ---- */

.hist { display: flex; flex-direction: column; gap: 2px; }
.hist-row { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.hist-ic {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--c);
  background: #f1f5f9;
  background: color-mix(in srgb, var(--c) 12%, #fff);
}
.hist-label {
  flex: 1 1 auto; font-size: 12.5px; font-weight: 500; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-time { flex: 0 0 auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-x {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  color: #cbd5e1; padding: 4px; border-radius: 6px; flex: 0 0 auto;
  display: flex; align-items: center;
}
.hist-x:active { color: #e11d48; background: #fff1f2; }

/* ---- Leerzustände ---- */

.empty { padding: 30px 20px; text-align: center; color: var(--muted); }
.empty svg { color: #cdd7e3; margin: 0 auto 10px; }
.empty p { margin: 0 0 4px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.empty small { font-size: 12px; line-height: 1.5; display: block; }

/* ===========================================================================
   Übersicht
   =========================================================================== */

.list-wrap {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(26px + var(--safe-bottom));
}
.ov-house {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  margin: 0 auto 10px; max-width: 760px; overflow: hidden;
  box-shadow: var(--shadow-tile);
}
.ov-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer;
}
.ov-pin {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--c);
  background: #f1f5f9;
  background: color-mix(in srgb, var(--c) 12%, #fff);
}
.ov-head .ov-addr { flex: 1 1 auto; font-weight: 650; font-size: 14px; }
.ov-head .ov-count { font-size: 12px; color: var(--muted); }
.ov-chev { color: #cbd5e1; display: flex; }

.ov-hh {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.ov-hh:last-child { border-bottom: 0; }
.ov-hh .hh-ic { width: 26px; height: 26px; border-radius: 8px; }
.ov-hh .ov-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-badge {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: #f1f5f9; color: var(--ink-2);
  background: color-mix(in srgb, var(--c) 12%, #fff);
  color: color-mix(in srgb, var(--c) 78%, #0f172a);
}
.ov-time { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Karte weicht den Panels aus, damit die Knöpfe erreichbar bleiben. */
body.work-open .map-controls { right: calc(var(--wp-r) + 14px); }

/* ===========================================================================
   Hochformat: dieselben zwei Spalten in einem Bottom-Sheet
   =========================================================================== */

@media (max-width: 899px) {
  .work {
    top: auto; left: 0; right: 0; bottom: 0;
    height: 60%;
    background: var(--card);
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 34px rgba(15, 23, 42, .16);
    display: flex; flex-direction: column;
    pointer-events: auto;
    opacity: 1; visibility: visible;      /* Sichtbarkeit läuft über transform */
    transform: translateY(100%);
    transition: transform .26s cubic-bezier(.32, .72, 0, 1), height .26s cubic-bezier(.32, .72, 0, 1);
  }
  .work.open { transform: translateY(0); }
  .work.full { height: calc(100% - 8px); }

  .work-cols { flex: 1 1 auto; min-height: 0; }

  .wp-left  { flex: 0 0 40%; width: 40%; box-shadow: none; }
  .wp-right { flex: 1 1 auto; width: auto; border-left: 1px solid var(--line); box-shadow: none; }

  /* Griff zum Vergrößern/Verkleinern */
  .sheet-grip {
    display: block; appearance: none; border: 0; cursor: pointer;
    width: 100%; height: 22px; background: transparent; flex: 0 0 auto;
    position: relative; touch-action: none;
  }
  .sheet-grip::before {
    content: ''; position: absolute; left: 50%; top: 8px; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 3px; background: #d3dbe5;
  }

  /* Kartensteuerung über das Sheet schieben statt darunter verstecken. */
  body.work-open .map-controls { right: 14px; bottom: calc(60% + 14px); }
  body.work-full .map-controls { opacity: 0; pointer-events: none; }
}

/* Schmal (iPad mini hochkant, geteiltes Fenster): Ausgänge einspaltig, damit
   die Beschriftungen nicht umbrechen. */
@media (max-width: 620px) {
  .outcomes { grid-template-columns: 1fr; }
  .outcomes .out-btn:last-child { grid-column: auto; }
}

@media (max-width: 460px) {
  .brand span { display: none; }
  .stat-chip { display: none; }
}

/* Querformat auf schmaleren Fenstern: Panels etwas zusammenziehen. */
@media (min-width: 900px) and (max-width: 1120px) {
  :root { --wp-l: 208px; --wp-r: 304px; }
}
