/* Handy-Rahmen: Bottom-Sheet, Navigation, Dialoge am Handy (Design-Audit 18.11.2026, Paket P2). */
/* Aufbau: 1 Blatt (ui/sheet.js) · 2 untere Leiste + „mehr“-Blatt · 3 Theme-Auswahl, Menü, KI-Eingabe als Blatt ·
   4 Dialoge (.overlay > .modal) als Blatt · 5 Kopfzeile, ~/ki. Alles gilt nur am Handy (≤ 760 px) bzw. für
   Elemente, die nur dort entstehen; der Desktop bleibt unberührt.
   Schrift, Größen, Radien, Abstände und Tippziele kommen aus den Tokens in css/foundation.css
   (--fs-*, --r-*, --sp-*, --tap); Hover-Regeln und Fokus-Ring stehen dort bzw. in app.css und werden hier nicht wiederholt. */

@keyframes sheet { from { transform: translateY(30px); opacity: 0; } } /* nutzt .brain-sheet in app.css */

:root {
  --navh: calc(60px + env(safe-area-inset-bottom));  /* Höhe der unteren Leiste */
  --sheet-r: calc(var(--r-card) * 1.3);              /* obere Ecken des Blatts: folgt dem Kachel-Radius des Themes (eckige Themes bleiben eckig) */
  --sheet-dim: rgba(0,0,0,.5);                       /* Abdunklung hinter dem Blatt */
  --sheet-tap: max(var(--tap), 44px);                /* Zeilen und Kacheln im Blatt: nie unter 44 px */
}
:root[data-mode="light"] { --sheet-dim: rgba(20,20,30,.28); }

/* ================= 1 · Blatt ================= */
.sheet-bg { position: fixed; inset: 0; z-index: 100; background: var(--sheet-dim); touch-action: none; -webkit-tap-highlight-color: transparent; }
.sheet { position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 100; display: flex; flex-direction: column;
  max-height: calc((var(--vvh, 100dvh) - env(safe-area-inset-top)) * .9); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surf); color: var(--text); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--sheet-r) var(--sheet-r) 0 0; will-change: transform;
  /* der Block unterhalb deckt die Lücke, wenn die Feder beim Öffnen kurz überschwingt */
  box-shadow: 0 40px 0 0 var(--surf), 0 -14px 40px rgba(0,0,0,.35); }
html.kb-open .sheet { padding-bottom: 0; }
/* Blatt und Dialog bekommen den Fokus nur als Behälter (tabindex -1): kein Ring um das ganze Fenster */
.sheet:focus-visible, .modal:focus-visible { outline: none; }
.sheet-grip { flex: none; display: flex; align-items: center; justify-content: center; width: 100%; height: 22px; padding: 0; margin: 0;
  border: 0; background: transparent; cursor: grab; touch-action: none; -webkit-tap-highlight-color: transparent; }
.sheet-grip i { display: block; width: 36px; height: 4px; border-radius: var(--r-full); background: color-mix(in srgb, var(--dim) 55%, transparent); }
.sheet-grip:focus-visible { outline: none; }
.sheet-grip:focus-visible i { background: var(--focus); }
.sheet-head { flex: none; padding: 0 var(--sp-4) var(--sp-2); touch-action: none; }
.sheet-title { margin: 0; font-family: var(--ui); font-size: var(--fs-meta); font-weight: 600; line-height: 1.3; color: var(--dim); letter-spacing: .02em; }
.sheet-body { flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 var(--sp-3) var(--sp-3); }
.sheet-foot { flex: none; padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--line); }
/* angedockt: das Blatt sitzt über der unteren Leiste und fährt hinter ihr heraus; die Leiste bleibt bedienbar */
.sheet-docked { bottom: var(--navh); z-index: 56; padding-bottom: 0;
  max-height: min(calc(var(--vvh, 100dvh) - var(--navh) - env(safe-area-inset-top) - 28px), 640px); }
.sheet-bg-docked { z-index: 55; }
/* Inhalt dahinter steht still, solange ein Blatt offen ist */
html.sheet-lock .main { overflow: hidden; }
html.sheet-lock, html.sheet-lock body { overscroll-behavior: none; }
/* Ziele im Blatt füllen ihre Zelle: der Fokus-Ring sitzt innen, sonst schneidet ihn der Rollbereich ab */
:is(.ns-it, .ns-out, .thm-it, .thm-mo, .sm-it):focus-visible, .nav.rail > :is(a, .navmore):focus-visible { outline-offset: -2px; }

/* ================= 2 · untere Leiste und „mehr“-Blatt ================= */
@media (max-width: 760px) {
  .nav.rail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; width: auto; display: flex; flex-wrap: nowrap; align-items: stretch; gap: 2px;
    overflow: visible; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
    background: var(--surf); background-image: none; box-shadow: 0 -6px 18px rgba(0,0,0,.18); }
  .nav.rail > * { display: none; } /* in der Leiste stehen nur die festen Ziele und „mehr“ */
  .nav.rail > a.pri, .nav.rail > .navmore { display: flex; flex: 1 1 0; min-width: 0; min-height: 48px; margin: 0; padding: var(--sp-1) 1px; border: 0; border-radius: var(--r-l);
    align-items: center; justify-content: center; background: transparent; color: var(--dim); font: inherit; font-weight: 400; cursor: pointer;
    box-shadow: none; text-shadow: none; animation: none; -webkit-tap-highlight-color: transparent; transition: background var(--t), color var(--t), transform var(--t); }
  /* Beschriftung: nie unter 11 px (--fs-micro) */
  .nav.rail .ns { display: flex; flex-direction: column; align-items: center; gap: 3px; max-width: 100%; overflow: visible;
    font-family: var(--nav-font); font-stretch: 87.5%; font-size: var(--fs-micro); font-weight: 500; line-height: 1.1; letter-spacing: 0; white-space: nowrap; }
  .nav.rail .st { display: block; }
  .nav.rail .ns .nico { width: 22px; height: 22px; opacity: .85; filter: none; color: inherit; }
  /* genau eine Hervorhebung: Fläche statt Strich */
  .nav.rail > a.on, .nav.rail > .navmore.on { color: var(--acc); background: color-mix(in srgb, var(--acc) 14%, transparent); box-shadow: none; }
  .nav.rail > a.on .nico, .nav.rail > .navmore.on .nico { opacity: 1; color: var(--acc); }
  /* „mehr“ offen: Pfeil nach unten, keine zweite Fläche */
  .nav.rail .nico-auf { display: none; }
  .nav.rail > .navmore.open { color: var(--text); }
  .nav.rail > .navmore.open .nico-zu { display: none; }
  .nav.rail > .navmore.open .nico-auf { display: block; opacity: 1; }
  .nav.rail > a:active, .nav.rail > .navmore:active { transform: scale(.95); }
}
/* sehr schmal (iPhone SE 1, 320 px): gleiche Schriftgröße, aber kein Zwischenraum und schmaler laufende Schrift –
   so bleibt auch „kalender“ in seiner Zelle */
@media (max-width: 350px) {
  .nav.rail { padding-left: 2px; padding-right: 2px; gap: 0; }
  .nav.rail > a.pri, .nav.rail > .navmore { padding-left: 0; padding-right: 0; }
  .nav.rail .ns { font-stretch: 75%; letter-spacing: -.02em; }
}
@media (prefers-reduced-motion: reduce) { :root:not([data-motion="an"]) .nav.rail > a:active, :root:not([data-motion="an"]) .nav.rail > .navmore:active { transform: none; } }

.nav-sheet .sheet-body { padding: 0 10px 10px; }
.ns-h { margin: 0; padding: var(--sp-2) 6px 3px; font-family: var(--nav-font); font-stretch: 87.5%; font-size: var(--fs-micro); font-weight: 500; line-height: 1; color: var(--faint); letter-spacing: .03em; }
.ns-h::before { content: "# "; color: var(--acc); }
.ns-grp:first-child .ns-h { padding-top: 2px; }
/* ein Raster für alle Gruppen: vier gleich breite Spalten, die über die Gruppen hinweg fluchten */
.ns-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-1); }
.ns-it { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px; min-width: 0; min-height: 60px;
  padding: 6px 2px 4px; border-radius: var(--r-l); color: var(--dim); text-decoration: none; -webkit-tap-highlight-color: transparent; transition: background var(--t), color var(--t); }
.ns-ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
/* Namen dürfen umbrechen (zwei Zeilen) statt mit „…“ zu enden */
.ns-txt { max-width: 100%; font-family: var(--nav-font); font-stretch: 87.5%; font-size: var(--fs-micro); font-weight: 500; line-height: 1.15; text-align: center; overflow-wrap: break-word; }
.ns-it.on { background: var(--sel); color: var(--text); }
.ns-it.on .ns-ico { color: var(--acc); }
.ns-it:active { background: var(--surf-2); }
.ns-ext { position: absolute; top: 6px; right: 12px; font-size: var(--fs-micro); line-height: 1; color: var(--faint); }
.ns-out { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); width: 100%; min-height: var(--sheet-tap); padding: 0 var(--sp-3); border: 0; border-radius: var(--r-l);
  background: transparent; color: var(--red); font: inherit; font-size: var(--fs-body); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ns-out:active { background: color-mix(in srgb, var(--red) 12%, transparent); }

/* ================= 3 · Theme-Auswahl, Menü, KI-Eingabe ================= */
.thm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.thm-it { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; min-height: var(--sheet-tap); padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-l);
  background: transparent; color: var(--dim); font: inherit; font-size: var(--fs-body); text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.thm-it .sw { width: 18px; height: 18px; border-radius: var(--r-s); }
.thm-it span:not(.sw) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thm-it small { margin-left: auto; flex: none; font-size: var(--fs-sm); line-height: 1; color: var(--faint); }
.thm-it.on { border-color: var(--acc); background: var(--sel); color: var(--text); }
.thm-h { margin: var(--sp-4) var(--sp-1) 6px; font-family: var(--ui); font-size: var(--fs-meta); font-weight: 600; color: var(--dim); letter-spacing: .02em; }
.thm-seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-l); overflow: hidden; }
.thm-mo { min-height: var(--sheet-tap); padding: 0 6px; border: 0; background: transparent; color: var(--dim); font: inherit; font-size: var(--fs-sm); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.thm-mo + .thm-mo { border-left: 1px solid var(--line); }
.thm-mo.on { background: var(--sel); color: var(--text); }

.menu-sheet .sheet-body { padding: 0 var(--sp-2) var(--sp-2); }
.sm-list { display: flex; flex-direction: column; }
.sm-it { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: max(var(--tap), 48px); padding: 0 var(--sp-3); border: 0; border-radius: var(--r-m);
  background: transparent; color: var(--text); font: inherit; font-size: var(--fs-lead); text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sm-it:active { background: var(--sel); }
.sm-it.danger { color: var(--red); }
.sm-more { color: var(--faint); font-size: 18px; line-height: 1; }
.sm-back { color: var(--dim); }
.sm-sep { height: 1px; margin: 6px var(--sp-3); background: var(--line); }
.sm-hd { padding: 10px var(--sp-3) var(--sp-1); font-size: var(--fs-meta); color: var(--faint); }

.ask-sheet .sheet-body { padding-bottom: var(--sp-2); }
/* 16 px: darunter zoomt iOS beim Antippen in das Feld */
.sheet .ask-in { display: block; width: 100%; min-height: 96px; max-height: 34dvh; padding: 10px var(--sp-3); font-size: 16px; line-height: 1.4; resize: none; }
.ask-row { display: flex; justify-content: flex-end; gap: var(--sp-2); }
.ask-row .btn { min-height: var(--sheet-tap); padding-left: var(--sp-4); padding-right: var(--sp-4); }

/* ================= 4 · Dialoge als Blatt ================= */
/* ui/sheet.js übernimmt jedes .overlay > .modal am Handy (Klassen sheet-ov / sheet-modal, Griff als erstes Kind). */
@media (max-width: 760px) {
  .overlay.sheet-ov, .sheet-ghost { padding: 0; align-items: flex-end; justify-content: center; overflow: hidden; overscroll-behavior: contain; }
  .sheet-ghost { position: fixed; inset: 0; z-index: 100; display: flex; pointer-events: none; }
  :is(.overlay, .sheet-ghost) > .modal.sheet-modal { width: 100% !important; margin: 0 0 var(--kb, 0px) !important; min-height: 0;
    max-height: calc(var(--vvh, 100dvh) - env(safe-area-inset-top) - 14px); padding-bottom: env(safe-area-inset-bottom);
    overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    border-bottom: 0; border-radius: var(--sheet-r) var(--sheet-r) 0 0; animation: none; will-change: transform;
    box-shadow: 0 40px 0 0 var(--bg), 0 -14px 40px rgba(0,0,0,.35); }
  html.kb-open .modal.sheet-modal { padding-bottom: 0; }
  /* Griff und Kopfzeile kleben oben: „fertig“ und „×“ bleiben beim Scrollen erreichbar */
  .sheet-modal > .sheet-grip { position: sticky; top: 0; z-index: 5; background: var(--surf); }
  .sheet-modal > .mh { position: sticky; top: 22px; z-index: 5; flex-wrap: wrap; padding: 0 10px var(--sp-2) 14px; touch-action: none; }
  .sheet-modal > .mh > :last-child:not(:first-child) { margin-left: auto; }
  /* Schließen-Knopf: Fläche über --tap, auch bei feinem Zeiger im schmalen Fenster 40 px */
  .sheet-modal .sheet-x, .modal.palette .sheet-x { min-width: max(var(--tap), 40px); min-height: max(var(--tap), 40px); padding: 0; font-size: var(--fs-title); line-height: 1; }
  .sheet-modal .mb { min-height: 0; }
  .sheet-modal > .modal-body { max-height: none !important; overflow: visible !important; }
  /* Rückfragen: Knöpfe groß und nebeneinander */
  .overlay[data-confirm] > .sheet-modal > .row:last-child { flex-wrap: wrap; }
  .overlay[data-confirm] > .sheet-modal > .row:last-child .btn { flex: 1 1 auto; min-height: var(--sheet-tap); }
  /* Ticket-Titel: mehrzeilig, wächst mit (am Handy ein textarea); Schrift kommt aus .title-in */
  textarea.title-in { display: block; resize: none; overflow: hidden; line-height: 1.25; }
  /* Suche: volle Höhe des sichtbaren Bereichs statt 100vh */
  .modal.palette { max-height: var(--vvh, 100dvh); min-height: min(60dvh, var(--vvh, 100dvh)); }
}

/* ================= 5 · Kopfzeile, Briefing und ~/ki ================= */
@media (max-width: 760px) {
  .bar { gap: 6px; padding: 6px var(--sp-2); padding-top: calc(6px + env(safe-area-inset-top)); }
  .bar .brand { padding: 10px var(--sp-1); }
  /* die Befehlszeile ist am Handy nur der Auslöser fürs Eingabe-Blatt */
  .bar .cmd { min-height: max(var(--tap), 40px); cursor: pointer; }
  .bar .cmd input { cursor: pointer; caret-color: transparent; }
  .bar .psearch, .bar .theme > .btn { display: inline-flex; align-items: center; justify-content: center; min-width: max(var(--tap), 40px); min-height: max(var(--tap), 40px); padding: 0; }

  /* Briefing: am Handy ein Textblock mit dem Knopf oben rechts (app.css) – das vierspaltige Raster aus dem Fundament
     drückt den Text sonst in eine schmale Spalte */
  .brief:not(.handyhint) { display: block; }

  /* ~/ki: Eingabe bleibt im Bild – Verlauf schrumpft, Briefing ist gedeckelt */
  .ai .ailist { flex: 1 1 60px; min-height: 0; }
  .ai .brief { max-height: calc(4 * 1.55em + 20px); overflow-y: auto; overscroll-behavior: contain; } /* vier Zeilen, der Rest rollt */
  .ai .aiin { flex: none; }
  .ai .aiin textarea { max-height: 30dvh; }
}
@media (max-width: 760px) and (max-height: 560px) {
  /* wenig Höhe (Tastatur, geteilte Ansicht, Querformat): Briefing weicht dem Verlauf */
  .ai .brief { display: none; }
  .ai .ailist { flex-basis: 40px; }
}
