/* ============================================================
   NadaGuide App-Shell — Layout & Komponenten.
   Farben/Radien/Spacing ausschliesslich aus _lex-tokens.css
   (Single Source of Truth). Light = Default, Dark via
   [data-theme="dark"]. Wertneutral, IBM Plex.
   Die eingebettete Ansicht bringt ihr eigenes Styling mit.
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

[hidden] {
  display: none !important;
}

/* ── Branding (einziges Logo) ── */
.brand {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}
.brand .mark {
  font-size: var(--t-h3);
  font-weight: var(--w-semibold);
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand .mark b {
  color: var(--accent-quiet);
  font-weight: var(--w-semibold);
}
.brand--lg .mark {
  font-size: var(--t-h1);
}

/* ── Buttons ── */
.btn {
  appearance: none;
  font: inherit;
  font-weight: var(--w-medium);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: var(--s-2) var(--s-3);
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
/* Als <a> verwendet (z. B. Navigation zur Verbrauchs-Seite): wie ein Button
   ausrichten und keine Link-Unterstreichung. */
a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
.btn--accent {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: var(--accent);
}
.btn--accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-fg);
}
.btn--quiet {
  background: transparent;
  color: var(--text-secondary);
}
.btn--quiet:hover {
  color: var(--text);
  background: var(--surface-3);
}
.btn--icon {
  padding: var(--s-1) var(--s-3);
  line-height: 1;
}

/* ── Form-Felder ── */
.field {
  display: inline-flex;
  flex-direction: column;
  gap: var(--s-1);
}
.field--inline {
  flex-direction: row;
  align-items: center;
  gap: var(--s-2);
}
.field__label {
  font-size: var(--t-caption);
  color: var(--text-secondary);
}
.select,
.textarea,
.file,
.gate__card input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: var(--s-2) var(--s-3);
}
.select:focus-visible,
.textarea:focus-visible,
.gate__card input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-color: var(--accent);
}
.file {
  padding: var(--s-1) var(--s-2);
  font-size: var(--t-caption);
  color: var(--text-secondary);
}

/* ── Theme-Toggle ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}
.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .ic-sun {
  display: none;
}
.theme-toggle .ic-moon {
  display: block;
}
[data-theme="dark"] .theme-toggle .ic-sun {
  display: block;
}
[data-theme="dark"] .theme-toggle .ic-moon {
  display: none;
}

/* ── Header-Auswahl: zwei vertikale Segment-Gruppen ──
   Links Perspektive (Laie/Juristisch), daneben Ansicht (Tree/Tor).
   Jede Gruppe stapelt ihre Optionen vertikal; die aktive Option ist
   ueber [aria-pressed="true"] deutlich markiert. Markup baut
   js/shell-header.js (.segv > .segv__btn). */
.choices {
  display: flex;
  align-items: stretch;
  gap: var(--s-4);
}
.choices__col {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.choices__label {
  font-size: var(--t-caption);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.segv {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.segv__btn {
  appearance: none;
  font: inherit;
  font-size: var(--t-caption);
  font-weight: var(--w-medium);
  line-height: 1.1;
  text-align: left;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--r-xs);
  padding: var(--s-1) var(--s-3);
  cursor: pointer;
  white-space: nowrap;
  transition:
    color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}
.segv__btn:hover {
  color: var(--text);
  background: var(--surface-3);
}
.segv__btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
.segv__btn[aria-pressed="true"] {
  color: var(--accent-fg);
  background: var(--accent);
  cursor: default;
}

/* ── Gate ── */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 10;
}
.gate__card {
  width: min(360px, 90vw);
  padding: var(--s-8);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-dialog);
  display: grid;
  gap: var(--s-3);
}
.gate__hint {
  margin: 0;
  color: var(--text-secondary);
}
.gate__card button[type="submit"] {
  appearance: none;
  font: inherit;
  font-weight: var(--w-medium);
  color: var(--accent-fg);
  background: var(--accent);
  border: none;
  border-radius: var(--r-xs);
  padding: var(--s-3);
  cursor: pointer;
}
.gate__card button[type="submit"]:hover {
  background: var(--accent-hover);
}
.gate__error {
  margin: 0;
  min-height: 1em;
  color: var(--danger);
}

/* ── App-Grid: Header (voll) + Sidebar | Stage | Panel ── */
.app {
  display: grid;
  grid-template-columns: var(--rail-expanded) 1fr minmax(300px, 360px);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "head head head"
    "side stage panel";
  height: 100vh;
}

.shell-top {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.spacer {
  flex: 1 1 auto;
}

/* ── Sidebar (links) ── */
.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
}
.sidebar__head,
.sidebar__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
}
.sidebar__foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  border-bottom: none;
}
.vorgang-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}
.vorgang {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-3);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
}
.vorgang:hover {
  background: var(--surface-3);
}
.vorgang.is-active {
  background: var(--accent-tint);
  color: var(--accent-quiet);
}
.vorgang__del {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 var(--s-1);
}
.vorgang__del:hover {
  color: var(--danger);
}
.usage {
  color: var(--text-muted);
  font-size: var(--t-caption);
}

/* ── Stage (Mitte): nur noch das iframe (keine Titel-Leiste mehr) ── */
.stage {
  grid-area: stage;
  display: block;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.view-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

/* ── Eingabe-Panel (rechts) ── */
.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
}
.panel__head {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.panel__body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  overflow: auto;
  flex: 1;
}
.textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
}
.panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
}
.hinweis-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--s-2);
}
.hinweis {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-xs);
  border-left: 3px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.hinweis:hover {
  background: var(--surface-3);
}
.hinweis--pro {
  border-left-color: var(--success);
}
.hinweis--contra {
  border-left-color: var(--danger);
}
.hinweis--info {
  border-left-color: var(--info);
}

/* ── Seiten-Navigation (EINE Quelle fuer alle drei Seiten) ──
   Segmentierter Umschalter Fall-Ansicht · Einstellungen · Verbrauch.
   Identisches Markup/Styling in index.html, settings.html, usage.html;
   die aktive Seite traegt aria-current="page" (-> .is-current). */
.nav {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: var(--s-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.nav__item {
  appearance: none;
  font: inherit;
  font-size: var(--t-body);
  font-weight: var(--w-medium);
  line-height: 1;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--r-xs);
  padding: var(--s-2) var(--s-3);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}
.nav__item:hover {
  color: var(--text);
  background: var(--surface-3);
}
.nav__item:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
.nav__item.is-current,
.nav__item[aria-current="page"] {
  color: var(--accent-fg);
  background: var(--accent);
  cursor: default;
}

/* ── Kopf-Leiste der eigenen Seiten (Einstellungen/Verbrauch) ──
   Gleiche Hoehe/Optik wie der Shell-Header; traegt Branding + Nav + Theme. */
.page-top {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: var(--topbar-h);
  padding: 0 var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* ── Schmale Viewports: Panel wandert nach UNTEN, Sidebar bleibt links ── */
@media (max-width: 960px) {
  .app {
    grid-template-columns: var(--rail-expanded) 1fr;
    grid-template-rows: var(--topbar-h) 1fr minmax(160px, 34vh);
    grid-template-areas:
      "head head"
      "side stage"
      "panel panel";
  }
  .panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 560px) {
  .shell-top {
    flex-wrap: wrap;
    height: auto;
    gap: var(--s-2) var(--s-3);
    padding: var(--s-2) var(--s-3);
  }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr minmax(140px, 34vh);
    grid-template-areas:
      "head"
      "side"
      "stage"
      "panel";
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 30vh;
  }
}
