/* app.css – Grundlayout der iPhone-Web-App: Farb-Tokens hell/dunkel, Sicherheitsbereiche,
   Reiterleiste, gemeinsame Bedienelemente. Der Rechner hat eigene, feste HP-Farben (calc.css). */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 54px;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  /* hell (Standard) */
  --bg: #F2F1EE;
  --panel: #FFFFFF;
  --panel-2: #F7F6F3;
  --text: #1B1B1A;
  --muted: #74726C;
  --line: #DFDDD7;
  --accent: #D9771C;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(232, 145, 45, 0.14);
  --field: #FFFFFF;
  --field-line: #CFCCC4;
  --danger: #D23B2F;
  --ok: #1F8F4E;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --tabbar-bg: rgba(250, 249, 247, 0.86);
  --backdrop: rgba(0, 0, 0, 0.32);
  --c0: #2A78D6; --c1: #EB6834; --c2: #1BAF7A; --c3: #EDA100;
  --c4: #E87BA4; --c5: #008300; --c6: #4A3AA7; --c7: #E34948;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0F0F0E;
  --panel: #1C1C1B;
  --panel-2: #252523;
  --text: #F1F0EC;
  --muted: #9B998F;
  --line: #34332F;
  --accent: #F0A04A;
  --accent-ink: #1B1B1A;
  --accent-soft: rgba(240, 160, 74, 0.16);
  --field: #141413;
  --field-line: #3E3D38;
  --danger: #FF6B5E;
  --ok: #4CC47F;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --tabbar-bg: rgba(24, 24, 23, 0.86);
  --backdrop: rgba(0, 0, 0, 0.55);
  --c0: #3987E5; --c1: #D95926; --c2: #199E70; --c3: #C98500;
  --c4: #D55181; --c5: #008300; --c6: #9085E9; --c7: #E66767;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.35;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; touch-action: manipulation; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; cursor: pointer; }
.ico { width: 1.25em; height: 1.25em; flex: none; display: inline-block; vertical-align: -0.22em; }
.hidden, [hidden] { display: none !important; }

/* ---------- Gerüst ---------- */
#app { position: absolute; inset: 0; display: flex; flex-direction: column; }
#panes { position: relative; flex: 1; min-height: 0; }
.pane {
  position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0;
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.pane.active { display: flex; }
.pane-head {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 16px 8px; min-height: calc(var(--safe-top) + 52px);
  background: var(--bg); border-bottom: 0.5px solid var(--line);
}
.pane-head h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-head .actions { display: flex; gap: 4px; align-items: center; }
.pane-head .back { margin-left: -8px; }
.pane-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; padding: 12px 16px 24px;
}
body.mathbar-on .pane-body { padding-bottom: 72px; }

/* Reiterleiste */
#tabbar {
  flex: none; display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--tabbar-bg); border-top: 0.5px solid var(--line);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  z-index: 20;
}
#tabbar button {
  flex: 1; min-width: 0; border: 0; background: none; padding: 6px 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0.1px;
}
#tabbar button .ico { width: 25px; height: 25px; }
#tabbar button.on { color: var(--accent); }
#tabbar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
@media (max-width: 400px) { #tabbar button { font-size: 9.5px; letter-spacing: -0.15px; } }

/* Rechner-Reiter: dunkle Leiste passend zum HP-Gehäuse */
body.tab-calc #tabbar { background: rgba(22, 21, 20, 0.94); border-top-color: #2C2B28; }
body.tab-calc #tabbar button { color: #8E8A80; }
body.tab-calc #tabbar button.on { color: #F2A444; }
body.tab-calc { background: #1F1E1C; }

/* Quer-/Breitformat: Rechner links, Arbeitsbereich rechts */
body.split #panes { display: flex; }
body.split .pane { position: relative; inset: auto; }
body.split #pane-calc { display: flex; flex: 0 0 var(--calc-w, 44%); border-right: 0.5px solid #000; }
body.split .pane.active:not(#pane-calc) { flex: 1; min-width: 0; }
body.split #tabbar button[data-tab="calc"] { display: none; }

/* ---------- Bausteine ---------- */
.card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin: 0 0 14px;
}
.card h2 { margin: 0 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted); }
.card h3 { margin: 12px 0 6px; font-size: 15px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.gap { gap: 12px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
small, .small { font-size: 13px; }

.list { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin: 0 0 14px; }
.list-item {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 14px;
  border: 0; border-bottom: 0.5px solid var(--line); background: none; width: 100%; text-align: left;
}
.list-item:last-child { border-bottom: 0; }
.list-item .ico { color: var(--accent); }
.list-item .chev { margin-left: auto; color: var(--muted); }
button.list-item:active { background: var(--panel-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 0.5px solid var(--line);
  background: var(--panel); color: var(--text); font-weight: 600; font-size: 15px;
  white-space: nowrap;
}
.btn:active { filter: brightness(0.92); transform: translateY(0.5px); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.primary, .btn.primary.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.icon { min-width: 44px; min-height: 44px; padding: 0; color: var(--accent); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: 0.4; }

.field {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--field-line); background: var(--field); color: var(--text);
  font-size: 17px; /* ≥ 16 px: iOS zoomt beim Fokussieren nicht */
  outline: none; -webkit-appearance: none; appearance: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.math, .field.num { font-family: var(--mono); font-size: 17px; }
.field.invalid { border-color: var(--danger); }
select.field { padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
label.lbl { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }

.seg {
  display: flex; padding: 2px; border-radius: 10px; background: var(--panel-2);
  border: 0.5px solid var(--line); overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; min-height: 34px; padding: 4px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.seg button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.14); color: var(--accent); }
:root[data-theme="dark"] .seg button.on { background: #3A3935; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  background: var(--panel-2); border: 0.5px solid var(--line); font-size: 13px;
}
.switch {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px 0; position: relative;
}
.switch .switch-text { flex: 1; display: flex; flex-direction: column; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--field-line);
  position: relative; transition: background .18s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.25); transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }

.kv { width: 100%; border-collapse: collapse; font-size: 15px; }
.kv td, .kv th { padding: 6px 4px; border-bottom: 0.5px solid var(--line); text-align: left; vertical-align: top; }
.kv th { color: var(--muted); font-weight: 600; font-size: 13px; }
.kv td.v { font-family: var(--mono); text-align: right; -webkit-user-select: text; user-select: text; }
.kv tr:last-child td { border-bottom: 0; }

.result, .formula {
  font-family: var(--mono); font-size: 15.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  -webkit-user-select: text; user-select: text;
}
.result { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.error { color: var(--danger); font-size: 14.5px; margin: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-size: 15px; }

/* Blatt von unten */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100; background: var(--backdrop); opacity: 0;
  transition: opacity .2s; display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  max-height: 88dvh; /* Safari mit Leisten: vh = größte Höhe – Kopf mit „Schließen“ würde oben abgeschnitten */
  background: var(--panel); color: var(--text); border-radius: 16px 16px 0 0;
  padding: 0 0 calc(var(--safe-bottom) + 8px); transform: translateY(24px); transition: transform .22s;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
}
.sheet.wide { max-width: 760px; }
.sheet-backdrop.open .sheet { transform: none; }
.sheet-grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 7px auto 0; }
.sheet-head { display: flex; align-items: center; padding: 4px 8px 4px 18px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 18px 12px; -webkit-overflow-scrolling: touch; }
.sheet-actions { display: flex; gap: 10px; padding: 8px 18px 4px; justify-content: flex-end; }
.sheet-actions .btn { flex: 1; }
.confirm-text { font-size: 16px; margin: 6px 0 10px; }
@media (min-width: 700px) and (min-height: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; padding-bottom: 8px; }
}

/* Meldung */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); z-index: 200;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: min(92vw, 520px);
  background: rgba(30, 29, 27, 0.94); color: #F4F2EC; padding: 10px 16px; border-radius: 14px;
  font-size: 15px; font-weight: 500; text-align: center; transition: opacity .2s, transform .2s;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Rechen-Leiste über der Tastatur */
#mathbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
  background: var(--panel-2); border-top: 0.5px solid var(--line);
  padding: 5px calc(var(--safe-right) + 4px) 5px calc(var(--safe-left) + 4px);
}
.mathbar-keys { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.mathbar-keys::-webkit-scrollbar { display: none; }
.mb-key {
  flex: none; min-width: 40px; height: 38px; padding: 0 10px; border-radius: 8px;
  border: 0.5px solid var(--line); background: var(--panel); color: var(--text);
  font-family: var(--mono); font-size: 17px; font-weight: 600;
}
.mb-key:active { background: var(--accent); color: var(--accent-ink); }
.mb-nav { color: var(--accent); font-size: 22px; }

/* Haptik-Hilfe (unsichtbar; display: none – nicht fokussierbar, kein Scrollen; die Haptik kommt trotzdem) */
.haptic-helper { display: none !important; }

/* Ausdruck nur beim Drucken */
#print-root { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
