/* ============================================================
   QS - Shared base styles
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    color-scheme: light;
    /* Colors */
    --bg: #edeef3;
    --bg-elevated: #f5f5fa;
    --panel: #ffffff;
    --panel-alt: #f7f7fc;
    --accent: #5b6ec7;
    --accent-dark: #4a5db6;
    --accent-light: #eef0ff;
    --accent-rgb: 91, 110, 199;
    --accent-faint: rgba(91,110,199,0.08);
    --accent-text: #fff;
    --panel-bg: #ffffff;
    --green: #3bae6f;
    --green-dark: #2f9a5e;
    --red: #d94848;
    --red-bright: #e04040;
    --orange: #e0a020;
    --green-script: #5CA65C;
    --entity-accent: #c06ae0;

    /* Input fields — white with visible border on light backgrounds */
    --input-bg: #ffffff;
    --input-border: #c8c9d4;
    --surface: #f0f1f6;

    /* Dark preview areas */
    --preview-bg: #1a1a2e;
    --preview-bg-deep: #111;
    --text: #2a2a3a;
    --text-sec: #5c5c72;
    --border: #e2e3eb;
    --border-strong: #c8c9d4;
    --hover: #f3f4fa;
    --active-bg: #e8eaff;
    --text-dim: #8b8ba0;
    --accent-hover: #4a5db6;

    /* Toast */
    --toast-bg: #2a2a3e;
    --toast-text: #ffffff;

    /* Radius */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 4px rgba(60, 60, 100, 0.08);
    --shadow-md: 0 4px 16px rgba(60, 60, 100, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.18);

    /* Transitions */
    --transition-fast: 100ms ease;
    --transition-base: 150ms ease;

    /* Breakpoints — used as numeric values in @media queries.
       CSS custom properties cannot be interpolated into @media itself,
       so these are documentation for consistency across the project.
       Use them as the values below:
         --bp-desktop: 1280px  (full desktop layouts)
         --bp-tablet:  1024px  (sidebars collapse, panels narrow)
         --bp-mobile:   640px  (single-column, touch-first)
    */
    --bp-desktop: 1280px;
    --bp-tablet: 1024px;
    --bp-mobile: 640px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #1a1b26;
        --bg-elevated: #1f2030;
        --panel: #24253a;
        --panel-alt: #2a2b42;
        --accent: #7582d5;
        --accent-dark: #5a68b8;
        --accent-hover: #8a96e0;
        --accent-light: rgba(117,130,213,0.12);
        --accent-rgb: 117, 130, 213;
        --accent-faint: rgba(117,130,213,0.06);
        --accent-text: #ffffff;
        --panel-bg: #24253a;
        --green: #4ade80;
        --green-dark: #2f9a5e;
        --red: #f87171;
        --red-bright: #ef4444;
        --orange: #fbbf24;
        --green-script: #5eba5e;
        --preview-bg: #12121e;
        --preview-bg-deep: #0a0a14;
        --text: #cdd0e0;
        --text-sec: #8888a8;
        --text-dim: #606078;
        --border: #363850;
        --border-strong: #484a68;
        --hover: rgba(255,255,255,0.05);
        --active-bg: rgba(117,130,213,0.15);
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
        --shadow-lg: 0 8px 28px rgba(0,0,0,0.5);
        --input-bg: #2a2b42;
        --input-border: #484a68;
        --surface: #1f2030;
        --toast-bg: #363850;
        --toast-text: #cdd0e0;
    }
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1a1b26;
    --bg-elevated: #1f2030;
    --panel: #24253a;
    --panel-alt: #2a2b42;
    --accent: #7582d5;
    --accent-dark: #5a68b8;
    --accent-hover: #8a96e0;
    --accent-light: rgba(117,130,213,0.12);
    --accent-faint: rgba(117,130,213,0.06);
    --accent-text: #ffffff;
    --panel-bg: #24253a;
    --green: #4ade80;
    --green-dark: #2f9a5e;
    --red: #f87171;
    --red-bright: #ef4444;
    --orange: #fbbf24;
    --green-script: #5eba5e;
    --preview-bg: #12121e;
    --preview-bg-deep: #0a0a14;
    --text: #cdd0e0;
    --text-sec: #8888a8;
    --text-dim: #606078;
    --border: #363850;
    --border-strong: #484a68;
    --hover: rgba(255,255,255,0.05);
    --active-bg: rgba(117,130,213,0.15);
    --input-bg: #2a2b42;
    --input-border: #484a68;
    --surface: #1f2030;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 28px rgba(0,0,0,0.5);
    --toast-bg: #363850;
    --toast-text: #cdd0e0;
}

[data-theme="light"] {
    color-scheme: light;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

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

/* Global form element baseline — ensures visible contrast on any panel */
input[type="text"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="password"],
input:not([type]),
select,
textarea {
    background: var(--input-bg, #fff);
    color: var(--text);
    border-color: var(--input-border, var(--border));
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-sec); }

/* ---- Shared tooltip ---- */
#qs-tooltip {
    display: none;
    position: fixed;
    background: var(--bg-2, var(--panel));
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius, 6px);
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    white-space: normal;
    max-width: 240px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    z-index: 99999;
    pointer-events: none;
}

/* ---- Toast notification system (driven by engine/ui.js) ---- */
#qs-toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.qs-toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--toast-text);
    background: var(--toast-bg);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    pointer-events: auto;
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px) scale(0.95);
    transition: opacity 200ms ease, transform 200ms ease;
    max-width: 400px;
}
.qs-toast-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.qs-toast-hide {
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
}
.qs-toast-icon { display: flex; flex-shrink: 0; }
.qs-toast-success { --t-bg: #1a3a2a; --t-bdr: #2d6b45; --t-icon: #4ade80; }
.qs-toast-error   { --t-bg: #3a1a1a; --t-bdr: #6b2d2d; --t-icon: #f87171; }
.qs-toast-warning { --t-bg: #3a2e1a; --t-bdr: #6b5a2d; --t-icon: #fbbf24; }
.qs-toast-info    { --t-bg: #1a2a3a; --t-bdr: #2d4a6b; --t-icon: #60a5fa; }
.qs-toast-success,
.qs-toast-error,
.qs-toast-warning,
.qs-toast-info {
    background: var(--t-bg);
    border: 1px solid var(--t-bdr);
}
.qs-toast-success .qs-toast-icon,
.qs-toast-error .qs-toast-icon,
.qs-toast-warning .qs-toast-icon,
.qs-toast-info .qs-toast-icon {
    color: var(--t-icon);
}

/* ---- Confirm dialog (driven by QS.confirmDialog in engine/ui.js) ---- */
.qs-confirm-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: qs-confirm-fade-in 150ms ease;
}
.qs-confirm-panel {
    background: var(--panel, #222);
    color: var(--text, #eee);
    border-radius: var(--radius-lg, 10px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    width: 360px;
    max-width: 90vw;
    animation: qs-confirm-scale-in 180ms ease;
}
.qs-confirm-body {
    padding: 20px 20px 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}
.qs-confirm-panel .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 16px 16px;
}
.qs-confirm-panel .modal-btn {
    padding: 8px 16px;
    border-radius: var(--radius-md, 6px);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border, #444);
    background: var(--bg, #2a2a2a);
    color: var(--text, #eee);
    transition: filter 120ms ease;
}
.qs-confirm-panel .modal-btn:hover { filter: brightness(1.15); }
.qs-confirm-panel .modal-btn-apply {
    background: var(--accent, #4a90e2);
    color: var(--accent-text, #fff);
    border-color: transparent;
}
.qs-confirm-panel .modal-btn-danger {
    background: var(--danger, #e04040);
    color: #fff;
    border-color: transparent;
}
@keyframes qs-confirm-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes qs-confirm-scale-in {
    from { opacity: 0; transform: scale(0.96) translateY(6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============================================================
   QS.TemplatePicker — 16:9-Karten-Karussell
   Horizontal scrollbar, versteckte Scrollbar, Snap-Zentrierung,
   Live-HTML-Preview (stage = 640×360, CSS-skaliert auf Kartenbreite).
   ============================================================ */

.qs-tpick-host {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    height: 100%;
    padding: 28px 0 32px;
    color: var(--text);
}

.qs-tpick-header {
    padding: 0 32px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.qs-tpick-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.qs-tpick-subtitle {
    font-size: 13px;
    color: var(--text-sec);
}

.qs-tpick-strip {
    display: flex;
    gap: 18px;
    padding: 6px 50% 24px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.qs-tpick-strip::-webkit-scrollbar { display: none; }

.qs-tpick-card {
    flex: 0 0 auto;
    width: 320px;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    transition: transform 160ms ease;
}
.qs-tpick-card:hover { transform: translateY(-3px); }

.qs-tpick-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--preview-bg, #12121e);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid transparent;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}
.qs-tpick-card:hover .qs-tpick-frame {
    border-color: rgba(255, 255, 255, 0.18);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.38);
}
.qs-tpick-card-active .qs-tpick-frame {
    border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(var(--accent-rgb), 0.35);
}

.qs-tpick-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    /* Width/height set inline to 640×360. Scaled via --qs-tpick-scale set
       on the frame when card width isn't 320, or fall back to 0.5 (320/640). */
    transform: scale(0.5);
    pointer-events: none;
}

.qs-tpick-caption {
    padding: 0 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.qs-tpick-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.qs-tpick-sub {
    font-size: 12px;
    color: var(--text-sec);
}

/* Plus-Karte am Ende des Strips */
.qs-tpick-card-plus .qs-tpick-frame {
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.03) 0 10px,
        rgba(255, 255, 255, 0.06) 10px 20px
    );
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed rgba(255, 255, 255, 0.18);
}
.qs-tpick-card-plus:hover .qs-tpick-frame {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb), 0.08);
}
.qs-tpick-plus-glyph {
    font-size: 64px;
    font-weight: 200;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1;
}
.qs-tpick-card-plus:hover .qs-tpick-plus-glyph {
    color: var(--accent);
}
