/* ============================================================================
   WidgetApp Studio — Premium Design System
   Dunkles „Studio"-Theme. Diese Tokens bilden die App auf dem Handy 1:1 nach
   (Theme.kt setzt dieselben Material-Rollen).
   ============================================================================ */
:root {
  --bg: #14161C;           /* etwas heller als zuvor (#0A0B0E), weiter dunkel */
  --surface: #1C1F26;      /* Karten, Listen, App-Bars */
  --surface-2: #252934;    /* Eingaben, Menüs, gehobene Flächen */
  --surface-3: #2F333E;    /* Hover/Active */
  --border: rgba(255,255,255,.08);
  --border-2: rgba(255,255,255,.13);
  --text: #ECEEF3;
  --text-2: #9AA1AE;
  --text-3: #5E6573;
  --accent: #22D3EE;
  --accent-2: #4F86F7;
  --on-accent: #04181C;
  --accent-soft: rgba(34,211,238,.14);
  --accent-line: rgba(34,211,238,.55);
  --danger: #FF6B6B;
  --grad: linear-gradient(135deg, #22D3EE 0%, #4F86F7 100%);
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 10px 30px rgba(0,0,0,.45);
  --r-card: 18px;
  --r-btn: 12px;
  --r-input: 11px;
  --font: 'Inter', -apple-system, 'Segoe UI Variable', 'Segoe UI', Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); background: #0C0E12; color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss01'; letter-spacing: -0.006em;
}
.stage { min-height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 26px 12px 48px;
  background: radial-gradient(1200px 700px at 50% -10%, rgba(34,211,238,.06), transparent 60%), #0C0E12; }
.phone {
  width: 396px; max-width: 100%; height: 836px; background: var(--bg); border-radius: 38px; overflow: hidden;
  position: relative; display: flex; flex-direction: column;
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 30px 70px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.04);
}
.screen { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; padding-top: 24px; }
.screen::-webkit-scrollbar { width: 0; }

/* ── App-Bars ──────────────────────────────────────────────────────────────── */
.appbar { display: flex; align-items: center; gap: 6px; padding: 14px 14px 10px; }
.appbar .title { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; flex: 1; padding-left: 4px; }
.ebar { display: flex; align-items: center; gap: 2px; padding: 12px 10px; min-height: 60px; }
.etitle {
  flex: 1; min-width: 0; margin: 0 2px;
  display: block; text-align: left;
  background: transparent; border: none; cursor: pointer;
  font: inherit; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; color: var(--text);
  padding: 10px 8px; border-radius: 9px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.etitle:hover { background: var(--surface); }
.etitle:active { background: var(--surface-2); }
.etitle:focus-visible { outline: none; background: var(--surface-2); }
.eactions { display: flex; align-items: center; gap: 2px; }
.subhead { display: flex; align-items: center; padding: 12px 12px; min-height: 60px; gap: 4px; }
.subhead .stitle { flex: 1; text-align: center; font-size: 17px; font-weight: 650; margin-right: 44px; }

/* Icon-Buttons */
.iconbtn { background: none; border: none; padding: 9px; margin: 0; cursor: pointer; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-btn); transition: .14s; }
.iconbtn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.iconbtn:disabled { color: var(--text-3); cursor: default; opacity: .55; }
.iconbtn svg { display: block; width: 26px; height: 26px; }
.iconbtn.accent { color: var(--accent); }
.iconbtn.accent:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }

/* Textlinks (z. B. „+ Global", Inspector-Aktionen) */
.link { color: var(--accent); background: none; border: none; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; padding: 6px 4px; border-radius: 8px; }
.link:hover { background: var(--accent-soft); }
.link.danger { color: var(--danger); }
.link.danger:hover { background: rgba(255,107,107,.12); }

/* ── Bibliothek: Widget-Galerie ────────────────────────────────────────────── */
.gallery { display: flex; flex-direction: column; gap: 14px; padding: 6px 16px 24px; }
.wcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden;
  cursor: pointer; transition: transform .16s cubic-bezier(.2,.7,.3,1), border-color .16s, box-shadow .16s; box-shadow: var(--shadow-1); }
.wcard:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: var(--shadow-2); }
.wcard:active { transform: translateY(0); }
.wthumb { width: 100%; display: block; opacity: 0; transition: opacity .4s ease; background:
  linear-gradient(0deg, rgba(255,255,255,.02), rgba(255,255,255,.02)),
  conic-gradient(from 90deg at 1px 1px, transparent 90deg, rgba(255,255,255,.025) 0) 0 0/16px 16px; }
.tpl-blank { width: 100%; aspect-ratio: 2 / 1; display: flex; align-items: center; justify-content: center; color: var(--text-3); background: var(--surface-2); }
.wmeta { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border-top: 1px solid var(--border); }
.wmeta .col { flex: 1; min-width: 0; }
.wname { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wsub { font-size: 12px; color: var(--text-3); margin-top: 3px; font-weight: 500; }
.wcard .iconbtn { padding: 8px; }

.empty { color: var(--text-2); font-size: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 360px; padding: 0 36px; gap: 6px; }
.empty .big { font-size: 17px; font-weight: 650; color: var(--text); }

/* FAB */
.fab { position: absolute; right: 16px; bottom: 16px; z-index: 40; background: var(--accent); color: var(--on-accent); border: none;
  border-radius: 16px; padding: 0 20px 0 16px; height: 52px; font: inherit; font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  box-shadow: 0 6px 18px rgba(34,211,238,.28), 0 2px 8px rgba(0,0,0,.35); }
.fab:hover { background: #38DBEF; transform: translateY(-1px); box-shadow: 0 10px 26px rgba(34,211,238,.38), 0 2px 8px rgba(0,0,0,.35); }
.fab svg { width: 21px; height: 21px; }

/* ── Editor: Vorschau-Bühne ────────────────────────────────────────────────── */
.stage-wrap { padding: 8px 16px 14px; }
.preview { border-radius: var(--r-card); overflow: hidden; border: 1px solid var(--border);
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(34,211,238,.05), transparent 55%),
    var(--surface);
  box-shadow: var(--shadow-1); padding: 18px; line-height: 0; }
#cv { display: block; width: 100%; height: 168px; border-radius: 10px; touch-action: none; }

.section-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); padding: 16px 18px 8px; }

/* Ebenenliste */
.layers { padding: 0 12px; display: flex; flex-direction: column; gap: 6px; }
.lyr { display: flex; align-items: center; gap: 12px; padding: 11px 12px; cursor: pointer; border-radius: 12px;
  border: 1px solid transparent; transition: .12s; position: relative; }
.lyr:hover { background: var(--surface); }
.lyr.sel { background: var(--accent-soft); border-color: var(--accent-line); }
.lyr.sel::before { content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.lyr .licon { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--text-2); flex: 0 0 auto; }
.lyr.sel .licon { background: rgba(34,211,238,.18); color: var(--accent); }
.lyr .licon svg { width: 18px; height: 18px; }
.lyr .col { flex: 1; min-width: 0; }
.lyr .nm { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.lyr .id { font-size: 12px; color: var(--text-3); margin-top: 1px; font-weight: 500; }

/* ── Inspector / Karten ────────────────────────────────────────────────────── */
.panel { margin: 8px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; }
.panel + .panel { margin-top: 12px; }
.phead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.phead .ptitle { display: flex; align-items: center; gap: 7px; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
.chip { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 4px 9px; border-radius: 999px; }
.phead .link { margin: -6px -4px -6px 0; }

.fld { display: block; margin: 13px 0; }
.fld:first-of-type { margin-top: 8px; }
.fldl { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; letter-spacing: -0.005em; }
.fldrow { display: flex; gap: 12px; }
.fldrow .fld { flex: 1; margin: 13px 0; }
.pvhead { display: flex; align-items: center; gap: 10px; }
.colorrow { display: flex; gap: 8px; align-items: center; }
.hint { color: var(--text-2); padding: 22px 18px; font-size: 15px; text-align: center; }
.subnote { color: var(--text-3); font-size: 13px; line-height: 1.55; }

.btnrow { display: flex; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.grow { display: flex; gap: 8px; margin: 10px 0; align-items: flex-end; }
.grow .fld { margin: 0; flex: 1; }
.grow .x { color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-size: 14px; padding: 0; width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto; }
.grow .x:hover { color: var(--danger); border-color: rgba(255,107,107,.4); }

/* Eingaben */
input[type=text], input[type=number], select {
  width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-input); padding: 11px 13px; font: inherit; font-size: 14px; transition: border-color .12s, box-shadow .12s; }
input[type=text]::placeholder, input[type=number]::placeholder { color: var(--text-3); }
input[type=text]:focus, input[type=number]:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) center, calc(100% - 12px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.colorrow input[type=text] { flex: 1; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
input[type=color] { padding: 0; width: 46px; height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 4px; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 7px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px; background: var(--surface-3); outline: none; padding: 0; border: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.5); border: 2px solid #0c1417; }
.rangewrap { display: flex; align-items: center; gap: 12px; }
.valr { font-size: 13px; color: var(--text); min-width: 48px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Material-Switch */
.sw { position: relative; display: inline-block; width: 50px; height: 30px; flex: 0 0 auto; cursor: pointer; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.sw .tr { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-2); box-sizing: border-box; transition: .18s; pointer-events: none; }
.sw .th { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: .18s cubic-bezier(.4,1.2,.5,1); pointer-events: none; }
.sw input:checked ~ .tr { background: var(--accent); border-color: var(--accent); }
.sw input:checked ~ .th { left: 26px; width: 20px; height: 20px; background: #04181C; }

/* Dropdown-Menü */
.menu { position: absolute; z-index: 20; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 14px; padding: 6px; min-width: 190px; box-shadow: var(--shadow-2); backdrop-filter: blur(8px); }
.menu .mi { padding: 11px 13px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text); border-radius: 9px; display: flex; align-items: center; gap: 10px; }
.menu .mi:hover { background: var(--surface-3); }

/* Einstellungs-Zeilen */
.srow { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin: 0 12px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; cursor: pointer; transition: .12s; }
.srow:hover { border-color: var(--border-2); background: var(--surface-2); }
.srow .ic { width: 40px; height: 40px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.srow .ic svg { width: 22px; height: 22px; }
.srow .col { flex: 1; min-width: 0; }
.srow .nm { font-size: 15px; font-weight: 600; }
.srow .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.srow .chev { color: var(--text-3); }

/* Snackbar */
#snack { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--surface-2); color: var(--text);
  padding: 13px 18px; border-radius: 14px; font-size: 13.5px; font-weight: 600; max-width: 88%; text-align: center;
  border: 1px solid var(--border-2); box-shadow: var(--shadow-2); z-index: 30; }

.note { width: 396px; max-width: 100%; color: var(--text-3); font-size: 12px; line-height: 1.55; text-align: center; }
.note code { color: var(--text-2); }

/* ── Apple-Niveau-Feinschliff ──────────────────────────────────────────────── */
/* Punch-Hole-Kamera (OnePlus 15, mittig oben) */
.phone::after { content: ''; position: absolute; top: 15px; left: 50%; transform: translateX(-50%); width: 11px; height: 11px; border-radius: 50%; background: #000; box-shadow: inset 0 0 0 1.5px #16181d, 0 0 0 1px rgba(0,0,0,.7); z-index: 60; pointer-events: none; }

/* Sanfter Screen-Übergang NUR bei echtem Screen-Wechsel (.anim wird in render() gesetzt) */
@keyframes screenIn { from { opacity: 0; transform: translateY(10px) scale(.992); } to { opacity: 1; transform: none; } }
.screen > div.anim { animation: screenIn .32s cubic-bezier(.2,.7,.25,1); }

/* Tile/Kachel-Einblendung */
@keyframes riseIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.gallery .wcard { animation: riseIn .42s cubic-bezier(.2,.7,.25,1) backwards; }
.gallery .wcard:nth-child(1) { animation-delay: .02s; }
.gallery .wcard:nth-child(2) { animation-delay: .07s; }
.gallery .wcard:nth-child(3) { animation-delay: .12s; }
.gallery .wcard:nth-child(4) { animation-delay: .17s; }
.gallery .wcard:nth-child(n+5) { animation-delay: .2s; }
.srow { animation: riseIn .4s cubic-bezier(.2,.7,.25,1) backwards; }

/* Taktiles Feedback — alles drückt sich beim Tippen leicht ein */
.wcard, .srow, .lyr, .fab, .iconbtn, .link, .menu .mi, input[type=color] { transition: transform .12s cubic-bezier(.2,.7,.3,1), background-color .14s, border-color .14s, box-shadow .16s, color .14s; }
.wcard:active { transform: scale(.985); }
.srow:active { transform: scale(.99); }
.lyr:active { transform: scale(.99); }
.iconbtn:active:not(:disabled) { transform: scale(.9); }
.fab:active { transform: translateY(0) scale(.96); }
.link:active { transform: scale(.96); }

/* Sanftere Slider-/Switch-/Karten-Schatten */
.panel { box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255,255,255,.03); }
.wcard { box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255,255,255,.035); }

@media (prefers-reduced-motion: reduce) { *, .screen > div.anim, .gallery .wcard, .srow, .modal-backdrop, .modal-card { animation: none !important; transition: none !important; } }

/* ── ⓘ Info-Icon + Erklär-Popover ──────────────────────────────────────────── */
.infobtn { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: none; border: none; padding: 0; margin: 0; cursor: pointer; color: var(--text-3); flex: 0 0 auto; transition: color .12s, background-color .12s; }
.infobtn:hover { color: var(--accent); background: var(--accent-soft); }
.infobtn svg { width: 16px; height: 16px; display: block; }
.iaction { display: inline-flex; align-items: center; gap: 4px; }
.popover { position: absolute; z-index: 90; width: 252px; max-width: 86%; max-height: 72%; overflow-y: auto; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 14px; padding: 13px 15px; box-shadow: var(--shadow-2); animation: popIn .16s cubic-bezier(.2,.7,.3,1); }
.popover::-webkit-scrollbar { width: 0; }
.popover .pt { font-size: 13.5px; font-weight: 700; color: var(--text); margin-bottom: 5px; }
.popover .px { font-size: 13px; line-height: 1.55; color: var(--text-2); }
@keyframes popIn { from { opacity: 0; transform: translateY(-5px) scale(.97); } to { opacity: 1; transform: none; } }

/* ── Formel verständlicher: Live-Ergebnis + Einfüge-Chips ───────────────────── */
.fresult { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.fresult .rv { color: var(--accent); font-variant-numeric: tabular-nums; }
.fresult.err { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-ins { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-family: inherit; transition: transform .12s, background-color .12s; }
.chip-ins:hover { background: rgba(34,211,238,.2); transform: translateY(-1px); }
.chip-ins:active { transform: translateY(0); }

/* ── Farbwähler (Palette statt Hex-Eingabe) ────────────────────────────────── */
.swatch-btn { display: block; width: 100%; height: 42px; border-radius: 10px; border: 1px solid var(--border-2); cursor: pointer; padding: 0; transition: border-color .12s; }
.swatch-btn:hover { border-color: var(--accent); }
.cpop { width: 244px; }
.cph { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 13px 0 8px; }
.cph:first-child { margin-top: 0; }
.cpop .pal { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.cpop .pal button { aspect-ratio: 1; border-radius: 8px; border: 1px solid rgba(255,255,255,.14); cursor: pointer; padding: 0; transition: transform .1s; }
.cpop .pal button:hover { transform: scale(1.14); }
.cpop .pal button.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.cpop input[type=color] { width: 100%; height: 40px; }

/* ── Echtes Handy: Vollbild statt Mockup-Rahmen, Safe-Areas berücksichtigen ──── */
@media (max-width: 540px) {
  .stage { min-height: 100dvh; padding: 0; gap: 0; background: var(--bg); }
  .phone { width: 100%; max-width: none; height: 100dvh; border-radius: 0; border: none; box-shadow: none; }
  .phone::after { display: none; }            /* keine Mockup-Kamera am echten Gerät */
  .note { display: none; }                     /* PC-Hinweis ausblenden */
  .screen { padding-top: env(safe-area-inset-top, 0px); }     /* unter der echten Statusleiste starten */
  .fab { right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}

/* ── Zentriertes Modal (z. B. Umbenennen) ──────────────────────────────────── */
.modal-backdrop {
  position: absolute; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px); animation: backdropIn .16s ease;
}
.modal-card {
  width: 100%; max-width: 360px; background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--r-card); box-shadow: var(--shadow-2); padding: 20px;
  animation: popIn .18s cubic-bezier(.2,.7,.3,1);
}
.modal-card .mtitle { font-size: 16px; font-weight: 700; color: var(--text); margin: 0 0 14px; }
.modal-card .field {
  width: 100%; box-sizing: border-box; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 13px 14px;
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;     /* >=16px: kein iOS-Auto-Zoom beim Fokus */
}
.modal-card .field:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions button { min-height: 44px; padding: 0 18px; border-radius: 12px; border: none; cursor: pointer; font: inherit; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.modal-actions .mbtn-cancel { background: transparent; color: var(--text-2); font-weight: 600; }
.modal-actions .mbtn-cancel:hover { background: var(--surface); color: var(--text); }
.modal-actions .mbtn-save { background: var(--accent); color: var(--on-accent); }
.modal-actions .mbtn-save:hover { background: #38DBEF; }
.modal-actions .mbtn-save:active { transform: scale(.97); }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
