/* ============================================================================
 * Provetra Design-Tokens – Theme-Kontrakt v2 (IDEE-007, Schritt 1 + 3)
 *
 * EINZIGE Stelle im Frontend, an der rohe Farbwerte, Radien, Abstände,
 * Schatten und Typo-Stufen stehen dürfen (test/brand-tokens.test.js erzwingt
 * das). Die drei UIs (app.html, index-api.html, operator.html) konsumieren
 * ausschließlich var(--…).
 *
 * Kunden-Theming (Managed Hosting): /theme/theme.css wird NACH dieser Datei
 * geladen und überschreibt nur :root-Variablen (Werte, nie Selektoren) –
 * fehlt das Theme-Volume, gilt das Provetra-Default aus dieser Datei.
 *
 * Quellen der Default-Werte:
 *   - docs/brand/provetra-brand-guide.pdf (v1.2) – Farbe/Typo/Marke
 *   - Provetra Design System (claude.ai/design, Projekt 301274f9-…) –
 *     tokens/{colors,typography,spacing}.css: Skalen-Ebene (v2), d. h.
 *     Abstände, Radien, Schatten, Typo-Hierarchie, Fokus-Ring, Transitions.
 *     Import-/Sync-Anleitung: CLAUDE.md „Design-System-Anbindung".
 * ==========================================================================*/

/* ---- Schriften (self-hosted, SIL OFL 1.1 – Lizenz: /public/fonts/OFL.txt) */
@font-face {
    font-family: 'Poppins';
    font-style: normal; font-weight: 500; font-display: swap;
    src: url('/public/fonts/poppins-500.woff2') format('woff2');
}
@font-face {
    font-family: 'Poppins';
    font-style: normal; font-weight: 700; font-display: swap;
    src: url('/public/fonts/poppins-700.woff2') format('woff2');
}
@font-face {
    font-family: 'Lato';
    font-style: normal; font-weight: 400; font-display: swap;
    src: url('/public/fonts/lato-400.woff2') format('woff2');
}
@font-face {
    font-family: 'Lato';
    font-style: normal; font-weight: 700; font-display: swap;
    src: url('/public/fonts/lato-700.woff2') format('woff2');
}
/* Noto Sans Mono ist ein Variable Font – EINE Datei deckt 400–700 ab. */
@font-face {
    font-family: 'Noto Sans Mono';
    font-style: normal; font-weight: 400 700; font-display: swap;
    src: url('/public/fonts/noto-sans-mono.woff2') format('woff2');
}

:root {
    /* ---- Rohpalette (Brand Guide §03) – nur als Quelle der semantischen
       Tokens; Komponenten-CSS greift NIE direkt auf --pv-* zu. ---- */
    --pv-petrol:      #0E5A63;
    --pv-petrol-dark: #0A3E45;
    --pv-mint:        #BFE5DE;
    --pv-copper:      #C9703A;
    --pv-ink:         #1B262C;
    --pv-slate:       #5A6B72;
    --pv-fog:         #E9ECEA;
    --pv-paper:       #FAF8F4;
    --pv-success:     #2F9E6E;
    --pv-warning:     #D9A036;
    --pv-error:       #C4453C;
    --pv-info:        #3E7CB1;

    /* ---- Semantische Tokens (der eigentliche Theme-Kontrakt) ---- */
    /* Marke / Interaktion */
    --primary:        var(--pv-petrol);
    --primary-hover:  #0C4E56;              /* Petrol-600: Hover DUNKELT (DS-Regel) */
    --primary-dark:   var(--pv-petrol-dark);/* Petrol-Dunkel: aktiv/gedrückt */
    --primary-soft:   #E7F0EE;              /* Petrol-Tint: ghost-hover, Adress-Pill */
    --primary-border: var(--pv-mint);       /* helle Marken-Kante (Banner, QR-Box) */
    --on-primary:     #FFFFFF;              /* Text/Icons auf Primärflächen */
    --accent:         var(--pv-copper);     /* sparsam (~10 %), Brand Guide §03 */
    --accent-hover:   #B5622F;
    --accent-bg:      #F4E4D9;
    --accent-text:    #8F4E24;

    /* Flächen / Text */
    --bg:             var(--pv-paper);
    --card:           #FFFFFF;
    --surface-2:      #F2F4F3;              /* Chips, Tabellenkopf, Hover auf Karten */
    --surface-3:      #E3E8E6;              /* Hover auf surface-2 */
    --text:           var(--pv-ink);
    --muted:          var(--pv-slate);
    --disabled:       #A9B4B8;
    --border:         var(--pv-fog);        /* Haarlinie: Karten, Trenner */
    --border-strong:  #D3D8D5;              /* Eingabefeld-Kontur (DS) */

    /* Funktionsfarben (UI-Status, Brand Guide §03) */
    --ok:             var(--pv-success);
    --ok-bg:          #E0F1E9;
    --ok-text:        #1E6647;
    --ok-border:      #BEE2D1;
    --err:            var(--pv-error);
    --err-dark:       #A23A32;              /* danger-hover */
    --err-bg:         #F7E1DF;
    --err-text:       #8E322B;
    --err-border:     #EBC4C0;
    --warn:           var(--pv-warning);
    --warn-bg:        #F8EDD6;
    --warn-text:      #7A5A1E;
    --info:           var(--pv-info);
    --info-bg:        #E2ECF5;
    --info-text:      #2C5A82;
    --neutral-bg:     var(--pv-fog);
    --neutral-text:   #3F4C52;

    /* Typografie (Brand Guide §04; Web-Fallback system-ui) */
    --font-sans:      'Lato', -apple-system, system-ui, 'Segoe UI', Arial, sans-serif;
    --font-heading:   'Poppins', -apple-system, system-ui, 'Segoe UI', sans-serif;
    --font-mono:      'Noto Sans Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    /* ---- Schatten: dezent + kühl (Petrol-getönt), NIE am Logo (DS/Guide) ---- */
    --shadow-xs:      0 1px 2px rgba(10, 62, 69, .06);
    --shadow-sm:      0 1px 3px rgba(10, 62, 69, .08), 0 1px 2px rgba(10, 62, 69, .06);
    --shadow-md:      0 4px 12px rgba(10, 62, 69, .10);
    --shadow-lg:      0 12px 32px rgba(10, 62, 69, .14);
    --shadow-overlay: 0 20px 60px rgba(10, 62, 69, .22);
    /* Semantische Aliase (bestehender Kontrakt, jetzt auf die DS-Stufen gemappt) */
    --shadow-card:    var(--shadow-xs);
    --shadow-raised:  var(--shadow-md);
    --shadow-modal:   var(--shadow-overlay);
    /* Modal-Scrim: einzige Transparenz/Blur-Fläche des Systems (DS) */
    --backdrop:       rgba(10, 62, 69, .42);
    --backdrop-blur:  2px;

    /* ---- Fokus + Bewegung (DS: ruhig, 120/180 ms ease, kein Bounce) ---- */
    --focus-ring:       0 0 0 3px rgba(14, 90, 99, .12);
    --transition-fast:  120ms ease;
    --transition-base:  180ms ease;

    /* ---- Abstände: 4px-Basisraster (DS tokens/spacing.css) ---- */
    --space-1:  4px;
    --space-2:  8px;
    --space-3:  12px;
    --space-4:  16px;
    --space-5:  20px;
    --space-6:  24px;
    --space-8:  32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* ---- Eckradien: ruhig, nie verspielt (DS) ---- */
    --radius-xs:    4px;
    --radius-sm:    6px;
    --radius-md:    10px;   /* Standard: Buttons, Inputs, kleine Flächen */
    --radius-lg:    14px;   /* Karten/Container */
    --radius-xl:    20px;   /* große Flächen, Dialoge */
    --radius-badge: 28px;   /* App-Kachel */
    --radius-pill:  999px;

    /* ---- Typo-Hierarchie (DS tokens/typography.css; Satzschreibung) ---- */
    --type-h1-size: 28px;    --type-h1-line: 34px;
    --type-h2-size: 20px;    --type-h2-line: 26px;
    --type-h3-size: 17px;    --type-h3-line: 24px;
    --type-body-size: 15px;  --type-body-line: 22px;
    --type-small-size: 13px; --type-small-line: 19px;
    --type-caption-size: 12px; --type-caption-line: 16px;
    --type-code-size: 13px;  --type-code-line: 18px;
    --weight-body: 400;
    --weight-body-strong: 600;
    --weight-body-bold: 700;
    --weight-display: 500;      /* Poppins Medium – Headlines */
    --weight-display-bold: 700;
    --tracking-caption: .08em;  /* Caption/Label gesperrt (einzige Versalien) */

    /* Kamera-Scan (app.html): Video-Bühne + Zielrahmen */
    --scan-bg:           #000000;
    --scan-reticle:      rgba(255, 255, 255, .55);
    --scan-scrim:        rgba(0, 0, 0, .28);
    --scan-scrim-strong: rgba(0, 0, 0, .45);
    --scan-hint:         #FFFFFF;
    --scan-hint-shadow:  0 1px 3px rgba(0, 0, 0, .8);

    /* Proben-Graph (D3, index-api/operator) */
    --graph-edge:          #9DA9AE;
    --graph-node:          #8A979D;
    --graph-node-external: #CBD4D2;

    /* Begleitdokument-Druck: Fließtext bleibt schwarz auf weiß (druckerneutral),
       die Marken-Flächen folgen dem Design System (ui_kits/begleitdokument). */
    --print-paper: #FFFFFF;
    --print-ink:   #000000;
    --print-muted: #333333;
    --print-line:  #999999;
    --print-brand:      var(--pv-petrol);      /* Kopflinie, Ziffernkreise, Kurz-ID */
    --print-brand-ink:  var(--pv-petrol-dark); /* Label auf der Mint-Fläche */
    --print-brand-soft: var(--pv-mint);        /* Fläche des Freigabe-Codes */
    --print-on-brand:   #FFFFFF;               /* Ziffern in den Petrol-Kreisen */
    --print-surface:    #F5F7F6;               /* Füllung von Kurz-ID- und QR-Box */
}

/* ============================================================================
 * Dunkelmodus (Bedienoberfläche v1.0, docs/UX_NATIVE_APP.md §8)
 *
 * Reine Neubelegung derselben Token-Namen – KEINE Zeile Layout. Die App hatte
 * bisher keinen Dunkelmodus und leuchtete auf einem dunkel gestellten Telefon
 * hellweiss.
 *
 * Zwei Schalter, in dieser Reihenfolge:
 *   1. @media (prefers-color-scheme: dark) folgt dem Gerät – ausser die Seite
 *      ist ausdrücklich auf hell gestellt (:root[data-theme="light"]).
 *   2. :root[data-theme="dark"] erzwingt dunkel (Einstellung im Profil).
 * Beide Selektoren sind spezifischer als das :root des Kunden-Themes, das
 * NACH dieser Datei geladen wird – die Umschaltung gewinnt also auch dort.
 *
 * Zwei Besonderheiten:
 *   • --primary wird HELL und --on-primary DUNKEL: derselbe Token trägt in
 *     dieser App zwei Rollen (Füllfläche UND Textfarbe); nur so funktionieren
 *     beide (6,2:1 als Text, 6,8:1 für Text auf der Fläche).
 *   • --print-paper bleibt WEISS: QR-Module sind schwarz, auf dunklem Grund
 *     wäre der Übergabe-Code nicht mehr scanbar.
 * Alle Paare gegen WCAG 2.1 AA gerechnet; Werte als Kommentar dahinter.
 * ==========================================================================*/

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* Flächen / Text */
        --bg:             #14161C;
        --card:           #1C1F27;
        --surface-2:      #262A34;
        --surface-3:      #313642;
        --text:           #ECEEF3;   /* 14,2:1 auf --card */
        --muted:          #A4ADBA;   /*  7,3:1 auf --card · 6,3:1 auf --surface-2 */
        --disabled:       #8B939E;
        --border:         #2E333E;
        --border-strong:  #3A404D;

        /* Marke: auf dunklem Grund wird --primary HELL und --on-primary DUNKEL.
           Derselbe Token trägt zwei Rollen (Füllfläche und Textfarbe); nur so
           funktionieren beide – helles Indigo als Text (6,2:1) und dunkler Text
           auf der Indigo-Fläche (6,8:1). */
        --primary:        #9A93F7;
        --primary-hover:  #ADA7F9;   /* im Dunkeln HELLT der Hover auf */
        --primary-dark:   #C0BBFB;   /* gedrückt noch heller */
        --primary-soft:   #23213B;
        --primary-border: #3B3663;
        --on-primary:     #15122E;

        /* Akzent (sparsam, ~10 %) */
        --accent:         #F3B567;
        --accent-hover:   #F7C98D;
        --accent-bg:      #33230E;
        --accent-text:    #F3B567;   /* 8,4:1 auf --accent-bg */

        /* Funktionsfarben */
        --ok:             #4FBF8B;
        --ok-bg:          #16301F;
        --ok-text:        #86E3B4;   /* 9,3:1 */
        --ok-border:      #24503A;
        --err:            #E2655C;
        --err-dark:       #EC8880;
        --err-bg:         #3A1A17;
        --err-text:       #FFB3AC;   /* 9,2:1 */
        --err-border:     #5B2A25;
        --warn:           #E0A94A;
        --warn-bg:        #332513;
        --warn-text:      #F2CE86;   /* 9,9:1 */
        --info:           #6DA6DC;
        --info-bg:        #152536;
        --info-text:      #A8CBEC;   /* 9,2:1 */
        --neutral-bg:     #262A34;
        --neutral-text:   #C6CEDA;   /* 9,1:1 */

        /* Schatten tragen im Dunkeln kaum – stattdessen hellt die Kante auf.
           Deshalb bleiben die Werte, aber deutlich kräftiger, damit Karten
           sich überhaupt noch abheben. */
        --shadow-xs:      0 1px 2px rgba(0, 0, 0, .50);
        --shadow-sm:      0 1px 3px rgba(0, 0, 0, .55), 0 1px 2px rgba(0, 0, 0, .45);
        --shadow-md:      0 4px 12px rgba(0, 0, 0, .55);
        --shadow-lg:      0 12px 32px rgba(0, 0, 0, .60);
        --shadow-overlay: 0 20px 60px rgba(0, 0, 0, .70);
        --backdrop:       rgba(0, 0, 0, .62);

        --focus-ring:     0 0 0 3px rgba(154, 147, 247, .30);
    }
}

/* Erzwungen dunkel (Prototyp-Vergleich / späterer Schalter). Inhaltsgleich mit
   dem Block oben – bewusst doppelt statt über eine gemeinsame Klasse, weil der
   Token-Kontrakt in tokens.css nur :root-Regeln zulässt. */
:root[data-theme="dark"] {
    --bg:             #14161C;
    --card:           #1C1F27;
    --surface-2:      #262A34;
    --surface-3:      #313642;
    --text:           #ECEEF3;
    --muted:          #A4ADBA;
    --disabled:       #8B939E;
    --border:         #2E333E;
    --border-strong:  #3A404D;

    --primary:        #9A93F7;
    --primary-hover:  #ADA7F9;
    --primary-dark:   #C0BBFB;
    --primary-soft:   #23213B;
    --primary-border: #3B3663;
    --on-primary:     #15122E;

    --accent:         #F3B567;
    --accent-hover:   #F7C98D;
    --accent-bg:      #33230E;
    --accent-text:    #F3B567;

    --ok:             #4FBF8B;
    --ok-bg:          #16301F;
    --ok-text:        #86E3B4;
    --ok-border:      #24503A;
    --err:            #E2655C;
    --err-dark:       #EC8880;
    --err-bg:         #3A1A17;
    --err-text:       #FFB3AC;
    --err-border:     #5B2A25;
    --warn:           #E0A94A;
    --warn-bg:        #332513;
    --warn-text:      #F2CE86;
    --info:           #6DA6DC;
    --info-bg:        #152536;
    --info-text:      #A8CBEC;
    --neutral-bg:     #262A34;
    --neutral-text:   #C6CEDA;

    --shadow-xs:      0 1px 2px rgba(0, 0, 0, .50);
    --shadow-sm:      0 1px 3px rgba(0, 0, 0, .55), 0 1px 2px rgba(0, 0, 0, .45);
    --shadow-md:      0 4px 12px rgba(0, 0, 0, .55);
    --shadow-lg:      0 12px 32px rgba(0, 0, 0, .60);
    --shadow-overlay: 0 20px 60px rgba(0, 0, 0, .70);
    --backdrop:       rgba(0, 0, 0, .62);

    --focus-ring:     0 0 0 3px rgba(154, 147, 247, .30);
}
