/* ============================================================
   E-MAIL MANAGER – BASE
   Design-Tokens, Reset, Typografie, Dark Mode (nur über Tokens)
   ============================================================ */

/* Lokal eingebundene Schriften (assets/fonts) – kein Google-Fonts-Aufruf */
@import url('../fonts/fonts.css');

:root {
    /* Markenfarbe – wird vom ThemeManager überschrieben */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-dark: #1e40af;
    --color-primary-light: #dbe6fd;

    --color-secondary: #475569;
    --color-secondary-hover: #334155;

    /* Status */
    --color-success: #16a34a;
    --color-success-bg: #e7f7ec;
    --color-warning: #d97706;
    --color-warning-bg: #fdf3e0;
    --color-danger: #dc2626;
    --color-danger-bg: #fdeaea;
    --color-info: #2563eb;
    --color-info-bg: #e6eefc;

    /* Flächen (hell) */
    --color-bg: #f5f6fa;
    --color-bg-elevated: #ffffff;
    --color-bg-subtle: #f1f3f8;
    --color-bg-muted: #e7eaf1;
    --color-bg-hover: #eceff5;
    /* Zeile einer ungelesenen E-Mail: Akzentfarbe leicht in die Listenfläche gemischt */
    --color-unread-bg: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg-elevated));

    /* Text (hell) */
    --color-text: #111827;
    --color-text-secondary: #4b5563;
    --color-text-muted: #8a94a6;
    --color-text-inverse: #ffffff;

    /* Linien */
    --color-border: #e4e7ee;
    --color-border-strong: #cdd3de;

    /* Sidebar (dunkel in beiden Modi) */
    --sidebar-bg: #1e3a5f;
    --sidebar-text: #f1f5f9;
    --sidebar-text-muted: #9fb0c6;
    --sidebar-hover: rgba(255, 255, 255, 0.07);
    --sidebar-active: rgba(255, 255, 255, 0.14);
    --sidebar-border: rgba(255, 255, 255, 0.08);

    /* Abstände */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Typografie */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Fira Code', 'SF Mono', Consolas, 'Cascadia Code', monospace;

    --text-2xs: 0.6875rem;   /* 11px – Zähler, Abschnittsüberschriften */
    --text-xs: 0.75rem;      /* 12px */
    --text-sm: 0.8125rem;    /* 13px */
    --text-base: 0.875rem;   /* 14px */
    --text-lg: 1rem;         /* 16px */
    --text-xl: 1.125rem;     /* 18px */
    --text-2xl: 1.375rem;    /* 22px */
    --text-3xl: 1.75rem;     /* 28px */

    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.65;

    /* Rundungen – werden vom ThemeManager skaliert */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Schatten */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 1px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 10px -2px rgba(16, 24, 40, 0.10), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, 0.14), 0 4px 8px -4px rgba(16, 24, 40, 0.06);
    --shadow-xl: 0 24px 48px -12px rgba(16, 24, 40, 0.22);
    --shadow-focus: 0 0 0 3px var(--color-primary-light);

    /* Bewegung */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Ebenen */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-toast: 500;

    /* Layout */
    --sidebar-width: 268px;
    --toolbar-height: 60px;
    --topbar-height: 56px;
    --page-max-width: 1120px;
    --page-narrow-width: 840px;

    /* Aliase für ältere Inline-Styles */
    --primary: var(--color-primary);
    --primary-hover: var(--color-primary-hover);
    --primary-light: var(--color-primary-light);
    --secondary: var(--color-secondary);
    --bg-body: var(--color-bg);
    --bg-white: var(--color-bg-elevated);
    --bg-light: var(--color-bg-subtle);
    --bg-hover: var(--color-bg-hover);
    --bg-secondary: var(--color-bg-subtle);
    --bg-tertiary: var(--color-bg-muted);
    --bg-primary: var(--color-bg-elevated);
    --border: var(--color-border);
    --border-color: var(--color-border);
    --text: var(--color-text);
    --text-primary: var(--color-text);
    --text-secondary: var(--color-text-secondary);
    --text-tertiary: var(--color-text-muted);
    --text-light: var(--color-text-muted);
    --text-muted: var(--color-text-muted);
    --primary-color: var(--color-primary);
    --danger: var(--color-danger);
    --danger-bg: var(--color-danger-bg);
    --success: var(--color-success);
    --success-bg: var(--color-success-bg);
    --warning: var(--color-warning);
    --info: var(--color-info);
    --radius: var(--radius-lg);
    --border-radius: var(--radius-md);
    --card-bg: var(--color-bg-elevated);
    --shadow: var(--shadow-sm);
    --transition: all var(--transition-base);
}

/* ------------------------------------------------------------
   Dark Mode – ausschließlich über Tokens
   ------------------------------------------------------------ */
[data-theme="dark"] {
    --color-bg: #0f1420;
    --color-bg-elevated: #161c2a;
    --color-bg-subtle: #1d2434;
    --color-bg-muted: #283042;
    --color-bg-hover: #222a3b;
    --color-unread-bg: color-mix(in srgb, var(--color-primary) 24%, var(--color-bg-elevated));

    --color-text: #eef2f8;
    --color-text-secondary: #b9c2d3;
    --color-text-muted: #7f8ba0;
    --color-text-inverse: #ffffff;

    --color-border: #273044;
    --color-border-strong: #364158;

    --color-success-bg: #10311f;
    --color-warning-bg: #3a2a0f;
    --color-danger-bg: #3d1616;
    --color-info-bg: #14233f;

    --sidebar-bg: #0c1018;
    --sidebar-text: #eef2f8;
    --sidebar-text-muted: #8a95a8;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(255, 255, 255, 0.12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 14px 28px -8px rgba(0, 0, 0, 0.55);
    --shadow-xl: 0 28px 56px -12px rgba(0, 0, 0, 0.65);

    color-scheme: dark;
}

[data-theme="dark"] select option {
    background-color: var(--color-bg-elevated);
    color: var(--color-text);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

/* Smartphone: jede Schriftstufe eine Nummer größer, Fließtext und Eingabefelder 16 px.
   Am Telefon ist der Leseabstand größer als am Notebook; 16 px in Feldern verhindert außerdem,
   dass iOS beim Antippen in die Seite hineinzoomt. */
@media (max-width: 767px) {
    :root {
        --text-2xs: 0.75rem;     /* 12px */
        --text-xs: 0.8125rem;    /* 13px */
        --text-sm: 0.9375rem;    /* 15px */
        --text-base: 1rem;       /* 16px */
        --text-lg: 1.125rem;     /* 18px */
        --text-xl: 1.25rem;      /* 20px */
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
    select,
    textarea {
        font-size: 1rem !important;
    }
}

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

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Das Dashboard ist ein fester Vollbild-Rahmen, alle anderen Seiten scrollen normal */
body.app-shell {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

h1, h2, h3, h4 {
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    letter-spacing: -0.01em;
    color: var(--color-text);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

p { margin: 0; }

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-hover);
}

small,
.text-small {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

strong { font-weight: var(--font-semibold); }

code, kbd, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

img, svg {
    display: inline-block;
    vertical-align: middle;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

::selection {
    background: var(--color-primary-light);
    color: var(--color-text);
}

/* Fokus nur für Tastaturnutzer sichtbar */
:focus { outline: none; }
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Skip-Link (Barrierefreiheit) */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border-radius: var(--radius-md);
    z-index: var(--z-toast);
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-4);
}

/* Scrollbars dezent */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: var(--radius-full);
    border: 3px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-text-muted);
}

/* Safari: native Select-/Date-Optik abschalten (Styling in components.css) */
select,
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="search"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

/* SVG-Icons aus dem Sprite (assets/icons/icons.svg) */
.icon {
    width: 1.15em;
    height: 1.15em;
    flex-shrink: 0;
    vertical-align: -0.2em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-sm { width: 1em; height: 1em; }
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-xl { width: 2em; height: 2em; }
