/* ============================================================
   main.css — Base reset, typography, layout, color tokens
   Design: ISRI / ISRINGHAUSEN Corporate Identity
   Siehe ISRI_Brand_Guide.md — Orange #FF8C00, Blau #1B61AB,
   Schwarz, Dunkelgrau #747778, Hellgrau #D6D6D6, Weiß
   ============================================================ */

/* ---------- CSS Custom Properties (Design Tokens) ---------- */
:root {
  /* Colors — ISRI Brand Palette */
  --color-primary:        #FF8C00;   /* ISRI Orange, Pantone 1375 C */
  --color-primary-dark:   #E67A00;   /* Hover / Active */
  --gradient-primary:     linear-gradient(135deg, #FF8C00 0%, #FFA733 100%);
  --color-accent:         #1B61AB;   /* Sekundärer CTA, Blau */
  --color-accent-dark:    #164F8C;
  --color-bg:             #F7F7F7;   /* leichte Ableitung von Hellgrau */
  --color-surface:        #FFFFFF;   /* Logo steht laut Guide auf Weiß */
  --color-border:         #D6D6D6;   /* Hellgrau, Pantone 427 C */
  --color-text:           #000000;
  --color-strong:         #000000;   /* Überschriften, Icons */
  --color-grey-ci:        #747778;   /* Dunkelgrau, Pantone 424 C — Flächen/Linien */
  --color-text-muted:     #6E7071;   /* Pantone 424 C minimal abgedunkelt → 4.65:1 auf --color-bg */
  --color-on-primary:     #000000;   /* Schrift auf Orange — 9.0:1 (weiß wäre 2.33:1) */
  --color-error:          #FF0000;   /* ISRI Diagrammfarbe Rot */
  --color-success:        #00CC00;   /* ISRI Diagrammfarbe Grün — LEDs/Glows */
  --color-success-strong: #008A00;   /* Flächen mit weißer Schrift (Kontrast) */

  /* Typography — Arial ist laut Guide die Schrift für digitale Medien.
     Interstate (Primärschrift) ist nicht als Webfont lizenzierbar. */
  --font-heading: Arial, 'Helvetica Neue', Helvetica, system-ui, sans-serif;
  --font-body:    Arial, 'Helvetica Neue', Helvetica, system-ui, sans-serif;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Shadows */
  --shadow-card: 0 2px 12px rgba(26, 40, 48, 0.10);
  --shadow-btn:  0 2px 8px rgba(26, 40, 48, 0.20);

  /* Layout */
  --max-width:         480px;   /* Mobile (iPhone) */
  --max-width-tablet:  720px;   /* iPad Hochformat (≥768px) */
  --max-width-desktop: 1280px;  /* iPad Querformat + Desktop (≥1024px) */
  --logo-h:       26px;                    /* Mobile — ISRI-Logo ist 4.25:1 breit */
  /* Seitliches Padding von .page und .header-inner — hält Logo, Inhalt und
     die orange Linie auf derselben Kante. */
  --page-pad:     var(--space-md);

  /* Safe-Area (iPhone Notch / Dynamic Island / Home-Indicator).
     Fallback 0px, damit calc() auch ohne env()-Support rechnet. */
  --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);

  /* Header-Höhe folgt dem höheren von Logo und Bedienelementen (44px Touch-Target),
     plus 2×10px Padding und 3px orange Linie. */
  --header-ctrl:  44px;
  --header-h:     calc(max(var(--logo-h), var(--header-ctrl)) + 23px + var(--safe-top));
  --transition:   0.18s ease;
}

/* ---------- Dark Theme — Schwarz/Dunkelgrau, Orange bleibt CI-Konstante ---------- */
[data-theme="dark"] {
  --color-bg:           #0D0D0D;
  --color-surface:      #1A1A1A;
  --color-border:       #3A3C3D;
  --color-strong:       #FFFFFF;
  --color-text:         #FFFFFF;
  --color-text-muted:   #A8ABAC;   /* Dunkelgrau aufgehellt für Kontrast */
  --color-accent:       #4A8FD4;   /* Blau aufgehellt für Kontrast auf Schwarz */
  --color-accent-dark:  #6FA8DF;
  --shadow-card:        0 2px 12px rgba(0, 0, 0, 0.55);
  --shadow-btn:         0 2px 8px rgba(0, 0, 0, 0.65);
}

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100dvh;
  /* Prevent overscroll bounce showing white on iOS */
  overscroll-behavior: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

img, video {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

[hidden] { display: none !important; }

#snapshot-canvas { display: none; }

/* ---------- Typography ---------- */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-strong);
  text-wrap: balance;
}

h1 { font-size: clamp(1.6rem, 5vw, 2rem); }
h2 { font-size: clamp(1.25rem, 4vw, 1.5rem); }
h3 { font-size: 1.1rem; }

p {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* ---------- App Layout ---------- */

/* Fixed header */
/* Orange Linie als Trennelement — laut Brand Guide (Abschnitt 7) */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-surface);
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  transition: background-color 0.2s ease;
  /* Statusleiste liegt bei black-translucent über dem Inhalt → freihalten */
  padding-top: var(--safe-top);
  padding-bottom: 3px;   /* Platz für die orange Linie */
}

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px calc(var(--page-pad) + var(--safe-right)) 10px calc(var(--page-pad) + var(--safe-left));
  max-width: var(--max-width);
  margin: 0 auto;
}

/* Orange Linie als Trennelement — endet bündig mit Logo und Inhalt,
   statt über die volle Fensterbreite zu laufen. */
.header-inner::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left:  calc(var(--page-pad) + var(--safe-left));
  right: calc(var(--page-pad) + var(--safe-right));
  height: 3px;
  background: var(--color-primary);
}

.header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.8125rem;
  color: var(--color-strong);
  letter-spacing: 0.01em;
  white-space: nowrap;
  pointer-events: none;
}

/* Sehr schmale Geräte: Titel weicht dem breiteren ISRI-Logo */
@media (max-width: 379px) {
  .header-title { display: none; }
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Logo nie verzerren oder beschneiden — Höhe führt, Breite folgt */
.brand-logo-img {
  height: var(--logo-h);
  width: auto;
  display: block;
  object-fit: contain;
}

/* Schwarze Variante im Light Mode, weiße im Dark Mode */
.brand-logo-img--dark  { display: none; }
[data-theme="dark"] .brand-logo-img--light { display: none; }
[data-theme="dark"] .brand-logo-img--dark  { display: block; }

/* Main content — offset by header height */
.app-main {
  padding-top: var(--header-h);
  min-height: 100dvh;
}

/* Inner page container — centered, max-width for mobile.
   Seitliches und unteres Padding respektieren die Safe-Area (Querformat-Notch,
   Home-Indicator). */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding:
    var(--space-md)
    calc(var(--page-pad) + var(--safe-right))
    calc(var(--space-2xl) + var(--safe-bottom))
    calc(var(--page-pad) + var(--safe-left));
}

.page-hero {
  margin-bottom: var(--space-md);
  text-align: center;
}

.page-hero h1 {
  font-size: 1.25rem;
  margin-bottom: var(--space-xs);
}

.page-hero p {
  font-size: 0.875rem;
}

/* Card container */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

/* Divider — ISRI-Bogen (sekundäres Designelement, aus dem Federsymbol abgeleitet) */
.divider {
  border: none;
  border-top: 3px solid var(--color-primary);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  width: 56px;
  height: 14px;
  margin: var(--space-md) auto;
}

/* ---------- Toast Notification ---------- */
.toast {
  position: fixed;
  bottom: calc(28px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #000000;
  color: #fff;
  padding: 14px 24px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.30);
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  z-index: 200;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
}

.toast.toast--visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.toast--success { background: var(--color-success-strong); }
.toast.toast--error   { background: var(--color-error); }

/* ---------- Success Screen ---------- */
.success-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  gap: var(--space-lg);
}

.success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-success-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.success-screen h2 {
  color: var(--color-success-strong);
}

/* ---------- Utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.mt-sm  { margin-top: var(--space-sm); }
.mt-md  { margin-top: var(--space-md); }
.mt-lg  { margin-top: var(--space-lg); }
.mb-md  { margin-bottom: var(--space-md); }

/* ---------- Single-Page Sections ---------- */
.page-section--hidden {
  display: none;
}

#success-screen {
  position: fixed;
  inset: 0;
  top: var(--header-h);
  background: var(--color-bg);
  z-index: 50;
  overflow-y: auto;
}

/* ---------- Header Actions (Gear + Theme Toggle) ---------- */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-shrink: 0;
}

/* ---------- Setup Overlay (hinter Panel, schließt bei Klick außen) ---------- */
.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 89;
  background: transparent;
}

/* ---------- Result Screens (Tracking + Daten — analog zu #success-screen) ---------- */
.result-screen {
  position: fixed;
  inset: 0;
  top: var(--header-h);
  background: var(--color-bg);
  z-index: 50;
  overflow-y: auto;
}

/* ---------- Sichtbarer Fokus für Tastaturbedienung ----------
   Oranger Ring allein erreicht nur 2.33:1 gegen Weiß — deshalb zusätzlich
   eine dunkle Kontur, die auf beiden Themes trägt. */
:where(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px solid var(--color-strong);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- Theme Toggle Button ---------- */
.btn-theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-theme-toggle:hover {
  background: var(--color-border);
  color: var(--color-primary);
}

.btn-theme-toggle .icon-sun  { display: none; }
.btn-theme-toggle .icon-moon { display: block; }

[data-theme="dark"] .btn-theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .btn-theme-toggle .icon-moon { display: none; }

/* ============================================================
   Responsive Breakpoints
   Mobile-first: base styles target iPhone 14 (390px)
   ============================================================ */

/* ---------- Tablet Hochformat — ab 768px ----------
   768px deckt iPad 9.7"/10.2" (768pt), iPad Mini (744pt greift knapp darunter
   noch das Handy-Layout) und Handys im Querformat ab. Der frühere Wert 820px
   ließ genau diese Geräte im 480px-Handylayout laufen. */
@media (min-width: 768px) {
  :root {
    --logo-h: 32px;
    --page-pad: var(--space-lg);
  }

  .header-title { font-size: 1rem; }

  .header-inner { max-width: var(--max-width-tablet); }

  .page {
    max-width: var(--max-width-tablet);
    padding-top: var(--space-xl);
  }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Desktop / iPad Querformat — ≥1024px ----------
   Die App-Spalte bleibt auch auf großen Monitoren bei 720px. Vorher lief der
   Header auf 1280px auf, während der tatsächliche Inhalt 480px breit war —
   Logo und Icons standen dadurch weit außerhalb der Inhaltsspalte. Header,
   Inhalt und Fußzeile fluchten jetzt auf jeder Breite. */
@media (min-width: 1024px) {
  :root {
    --logo-h: 40px;
    --max-width-desktop: var(--max-width-tablet);
    --page-pad: var(--space-xl);
  }

  h1 { font-size: 2.25rem; }
  h2 { font-size: 1.75rem; }

  .header-inner { max-width: var(--max-width-desktop); }

  .page {
    max-width: var(--max-width-desktop);
    padding-top: var(--space-xl);
  }
}
