/* ==========================================================================
   Zeit und Uhr — Design-Tokens & Basis
   Werte gespiegelt aus der SwiftUI-App:
   - tintColor: Assets.xcassets/tintColor.colorset (display-p3)
   - Menü-Hintergrund: LinearGradient(Color(white:0.95) → Color(white:0.9))
   - Karten: cornerRadius 18, shadow(black 10%, radius 8, y 4), border tint 10%
   ========================================================================== */

:root {
  /* --- Farben ------------------------------------------------------------ */
  --tint: #4f6f90;                        /* sRGB-Fallback für display-p3 */
  --tint-rgb: 79, 111, 144;
  --bg-top: #f2f2f2;                      /* Color(white: 0.95) */
  --bg-bottom: #e6e6e6;                   /* Color(white: 0.90) */
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --text: #1c1c1e;                        /* .primary */
  --text-secondary: #6c6c70;              /* .secondary */
  --text-tertiary: #8e8e93;               /* .gray */
  --separator: rgba(60, 60, 67, 0.18);

  /* Semantische Farben der App — die SwiftUI-Systemfarben im hellen
     Erscheinungsbild, das UhrzeitApp mit .preferredColorScheme(.light)
     festlegt. Werte aus iOS 26 ausgelesen (UIColor(Color.blue) & Co.);
     mit iOS 26 hat Apple Blau, Rot, Indigo, Türkis, Orange und Violett
     verschoben — Grün, Gelb und Pink sind unverändert. */
  --hours: #0088ff;                       /* Stundenbogen = blau */
  --minutes: #34c759;                     /* Minutenbogen = grün */
  --seconds: #ff383c;                     /* Sekundenzeiger = rot */
  --indigo: #6155f5;
  --teal: #00c3d0;
  --orange: #ff8d28;
  --yellow: #ffcc00;
  --red: #ff383c;
  --green: #34c759;
  --amber: #ffbf00;
  --purple: #cb30e0;
  --pink: #ff2d55;

  /* Ampel der Diagnose */
  --rating-good: #34c759;
  --rating-mid: #ffcc00;
  --rating-bad: #ff383c;
  --rating-none: rgba(142, 142, 147, 0.4);

  /* --- Maße -------------------------------------------------------------- */
  --radius-card: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 4px 8px rgba(0, 0, 0, 0.1);
  --shadow-soft: 0 2px 3px rgba(0, 0, 0, 0.1);
  --shadow-clock: 0 2px 4px rgba(0, 0, 0, 0.15);

  /* Content-Breite: das iPhone-Layout bleibt lesbar, größere Schirme
     bekommen mehr Spalten statt endlos breiter Karten. */
  --content-max: 1360px;
  --gap: 20px;

  /* --- Typografie (SwiftUI-Textstile in pt → px) -------------------------- */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded",
    "Segoe UI", Roboto, sans-serif;
  --fs-large-title: 34px;
  --fs-title: 28px;
  --fs-title2: 22px;
  --fs-title3: 20px;
  --fs-headline: 17px;
  --fs-body: 17px;
  --fs-subheadline: 15px;
  --fs-footnote: 13px;
  --fs-caption: 12px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Display-P3-fähige Geräte bekommen exakt die Asset-Farbe */
@supports (color: color(display-p3 1 1 1)) {
  :root { --tint: color(display-p3 0.337 0.431 0.552); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --tint: #6fa1d3;
    --tint-rgb: 111, 161, 211;
    --bg-top: #1c1c1e;
    --bg-bottom: #000000;
    --surface: #2c2c2e;
    --surface-2: #1c1c1e;
    --text: #ffffff;
    --text-secondary: #aeaeb2;
    --text-tertiary: #8e8e93;
    --separator: rgba(84, 84, 88, 0.6);
    --shadow-card: 0 4px 8px rgba(0, 0, 0, 0.4);
  }
  @supports (color: color(display-p3 1 1 1)) {
    :root { --tint: color(display-p3 0.477 0.625 0.810); }
  }
}

/* Nutzer-Override über den Einstellungen-Dialog */
:root[data-theme="light"] {
  --tint: #4f6f90; --tint-rgb: 79, 111, 144;
  --bg-top: #f2f2f2; --bg-bottom: #e6e6e6;
  --surface: #ffffff; --surface-2: #f7f7f8;
  --text: #1c1c1e; --text-secondary: #6c6c70; --separator: rgba(60, 60, 67, 0.18);
  --shadow-card: 0 4px 8px rgba(0, 0, 0, 0.1);
}
:root[data-theme="dark"] {
  --tint: #6fa1d3; --tint-rgb: 111, 161, 211;
  --bg-top: #1c1c1e; --bg-bottom: #000000;
  --surface: #2c2c2e; --surface-2: #1c1c1e;
  --text: #ffffff; --text-secondary: #aeaeb2; --separator: rgba(84, 84, 88, 0.6);
  --shadow-card: 0 4px 8px rgba(0, 0, 0, 0.4);
}
@supports (color: color(display-p3 1 1 1)) {
  :root[data-theme="light"] { --tint: color(display-p3 0.337 0.431 0.552); }
  :root[data-theme="dark"] { --tint: color(display-p3 0.477 0.625 0.810); }
}

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  color: var(--text);
  background: linear-gradient(to bottom, var(--bg-top), var(--bg-bottom)) fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; border-radius: 4px; }

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

/* --- App-Rahmen ----------------------------------------------------------- */
#app { min-height: 100%; }

.screen {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 24px);
}
/* Randlose Screens (Module mit eigenem Hintergrund): kein Seitenpadding —
   dann darf auch die Navigationsleiste ihre Ausgleichs-Ränder nicht setzen. */
.screen--flush { padding: 0; }
.screen--flush .navbar { margin: 0; padding: calc(var(--safe-top) + 6px) 12px 6px; }
.screen__inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* --- Karten (MenuCard / CompactMenuCard) ---------------------------------- */
.card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid rgba(var(--tint-rgb), 0.1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13); }
.card:active { transform: translateY(0) scale(0.99); }

.card__preview {
  flex: 0 0 110px;
  width: 110px;
  height: 110px;
  position: relative;
  display: grid;
  place-items: center;
}
.card__body { flex: 1 1 auto; min-width: 0; }
.card__title {
  margin: 0 0 6px;
  font-size: var(--fs-title2);
  font-weight: 700;
  color: var(--tint);
  line-height: 1.15;
  /* Lange Komposita („Klassenzimmeruhr") dürfen die Karte nicht aufblähen */
  overflow-wrap: break-word;
  hyphens: auto;
}
.card__desc {
  margin: 0;
  font-size: var(--fs-subheadline);
  color: var(--text-secondary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__chevron { flex: 0 0 auto; color: rgba(var(--tint-rgb), 0.7); padding-right: 8px; }

.card--compact { padding: 14px 16px; gap: 12px; }
.card--compact .card__title { font-size: var(--fs-title3); margin: 0; }
.card--compact .card__icon {
  flex: 0 0 40px; width: 40px; height: 40px;
  display: grid; place-items: center; color: var(--tint);
}

/* --- Sektionsüberschrift (MenuSectionHeader) ------------------------------ */
.section-header {
  grid-column: 1 / -1;
  padding-top: 28px;
  padding-bottom: 4px;
}
.section-header::before {
  content: "";
  display: block;
  height: 1px;
  background: rgba(var(--tint-rgb), 0.2);
  margin-bottom: 4px;
}
.section-header h2 {
  margin: 0;
  font-size: var(--fs-title3);
  font-weight: 700;
  color: var(--tint);
}

/* --- Menü-Raster ---------------------------------------------------------- */
/* Handy: eine Spalte. Ab Tablet zwei, auf großen Schirmen drei — die Karte
   behält dabei ihre iOS-Proportionen statt in die Breite zu laufen. */
/* minmax(0, 1fr) statt 1fr: sonst kann die Spur nicht unter die Min-Content-
   Breite der Karte schrumpfen und die Seite scrollt seitwärts. */
.menu-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}
/* Sehr schmale Geräte: kompaktere Vorschau, damit Text Platz behält */
@media (max-width: 430px) {
  .card { gap: 12px; padding: 16px 12px; }
  .card__preview { flex-basis: 92px; width: 92px; height: 92px; }
  .card__preview > * { transform: scale(0.84); transform-origin: center; }
  .card__title { font-size: var(--fs-title3); }
}
@media (min-width: 720px) {
  .menu-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1180px) {
  .menu-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* --- Menü-Kopf ------------------------------------------------------------ */
.menu-head { text-align: center; padding-top: 20px; }
.menu-head__clock {
  width: 160px; height: 160px; margin: 0 auto;
  display: grid; place-items: center;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}
.menu-head__title {
  margin: 10px 0 0;
  font-size: 38px;
  font-weight: 700;
  color: var(--tint);
  text-shadow: 0 1px 2px rgba(128, 128, 128, 0.3);
}
.menu-head__subtitle {
  margin: 4px 0 20px;
  font-size: var(--fs-subheadline);
  color: var(--text-tertiary);
}

.menu-footer {
  margin-top: 40px;
  padding-bottom: 20px;
  text-align: center;
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

/* --- Runde Icon-Buttons (Info / Einstellungen) ---------------------------- */
.icon-button {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--surface);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-soft);
  color: var(--tint);
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); }

.menu-corner {
  position: sticky;
  top: calc(var(--safe-top) + 10px);
  z-index: 5;
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  height: 0;                 /* nimmt keinen Fluss-Platz ein, wie das ZStack-Overlay */
}
.menu-corner > * { pointer-events: auto; }

/* --- Aufklapp-Button („Mehr anzeigen…") ----------------------------------- */
.disclosure {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid rgba(var(--tint-rgb), 0.1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  color: var(--tint);
  font-size: var(--fs-subheadline);
  font-weight: 500;
  cursor: pointer;
}

/* --- Uhr-Canvas ----------------------------------------------------------- */
.clock-canvas { display: block; touch-action: none; max-width: 100%; }
.clock-canvas--interactive { cursor: grab; }
.clock-canvas--interactive:active { cursor: grabbing; }

.clock-disc {
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1);
  display: grid;
  place-items: center;
}

/* --- Navigationsleiste der Unterseiten ------------------------------------ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  margin: calc(var(--safe-top) * -1 - 8px) -16px 12px;
  padding: calc(var(--safe-top) + 6px) 12px 6px;
  background: color-mix(in srgb, var(--bg-top) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.navbar__back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--tint);
  font-size: var(--fs-headline);
  cursor: pointer;
  padding: 6px 4px;
}
.navbar__title {
  margin: 0;
  font-size: var(--fs-headline);
  font-weight: 600;
  flex: 1 1 auto;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.navbar__actions { display: flex; gap: 4px; min-width: 44px; justify-content: flex-end; }

/* --- Segmentierter Umschalter (SwiftUI SegmentedPickerStyle) --------------- */
/* Gehört hierher und nicht in ein Modul: mehrere Screens nutzen ihn. */
.segmented-nav {
  display: inline-flex;
  /* Umbrechen statt überlaufen: drei lange Beschriftungen passen sonst
     auf Handybreite nicht nebeneinander. */
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
  background: rgba(120, 120, 128, 0.16);
  border-radius: 9px;
  padding: 2px;
}
.segmented-nav button {
  border: none;
  background: none;
  padding: 6px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: var(--fs-subheadline);
  color: var(--text);
  white-space: nowrap;
}
@media (max-width: 480px) {
  .segmented-nav button { padding: 6px 10px; font-size: var(--fs-footnote); }
}
.segmented-nav button[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  font-weight: 600;
}

/* --- Platzhalter für noch nicht portierte Module --------------------------- */
.placeholder {
  max-width: 560px;
  margin: 40px auto;
  padding: 28px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.placeholder h2 { margin-top: 0; color: var(--tint); }
.placeholder p { color: var(--text-secondary); }

/* Formularzeilen — von Blättern und Bildschirmen gleichermaßen genutzt */
    .row {
      display: flex; align-items: center; justify-content: space-between; gap: 12px;
      padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-md);
      margin-bottom: 8px;
    }
    .row label { flex: 1 1 auto; }
    .row select, .row input[type="number"] {
      font: inherit; padding: 6px 10px; border-radius: 8px;
      border: 1px solid var(--separator); background: var(--surface); color: var(--text);
    }
    .segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px;
      border: 1px solid var(--separator); }
    .segmented button {
      border: none; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer;
      font-size: var(--fs-subheadline);
    }
    .segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow-soft); font-weight: 600; }
    .stepper { display: inline-flex; flex: 0 0 auto; border: 1px solid var(--separator);
      border-radius: 9px; overflow: hidden; background: var(--surface); }
    .stepper button {
      font: inherit; font-size: var(--fs-title3); line-height: 1; width: 40px; padding: 6px 0;
      border: none; background: none; color: var(--tint); cursor: pointer;
    }
    .stepper button + button { border-left: 1px solid var(--separator); }
    .stepper button:disabled { color: var(--text-secondary); opacity: 0.4; cursor: default; }
    .row__note { margin: -4px 0 10px; padding: 0 4px; font-size: var(--fs-caption); color: var(--text-secondary); }
    .row__note--warn { color: var(--red); }
    .slider-row { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px;
      background: var(--surface-2); border-radius: var(--radius-md); margin-bottom: 8px; }
    .slider-row__head { display: flex; justify-content: space-between; gap: 12px; }
    .slider-row__head b { color: var(--tint); font-weight: 600; }
    .slider-row input[type="range"] { width: 100%; accent-color: var(--tint); }
    .slider-row__scale { display: flex; justify-content: space-between; font-size: var(--fs-caption);
      color: var(--text-secondary); }
    .switch { position: relative; width: 51px; height: 31px; flex: 0 0 auto; }
    .switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
    .switch span {
      position: absolute; inset: 0; border-radius: 999px; background: rgba(120,120,128,0.32);
      transition: background 0.2s; pointer-events: none;
    }
    .switch span::after {
      content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
      border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.2s;
    }
    .switch input:checked + span { background: var(--minutes); }
    .switch input:checked + span::after { transform: translateX(20px); }
