/* ============================================================================
   DemoExtractor design system
   A small shadcn-inspired system shared by every page. Neutral surfaces, one
   brand accent, light and dark themes. Brand colors are injected by theme.js as
   --brand-*-light / --brand-*-dark and resolved per active theme below.
   ============================================================================ */

:root {
    /* Brand (defaults; theme.js overrides from /api/branding) */
    --brand-primary-light: #2B88D8;
    --brand-accent-light:  #5AADE8;
    --brand-primary-dark:  #5AADE8;
    --brand-accent-dark:   #2B88D8;

    /* Light theme tokens */
    --bg:        #f7f8fa;
    --surface:   #ffffff;
    --surface-2: #f1f3f5;
    --border:    #e4e7ec;
    --border-strong: #d0d5dd;
    --text:      #101828;
    --muted:     #667085;
    --muted-2:   #98a2b3;
    --ring:      rgba(43, 136, 216, 0.35);
    --danger:    #d92d20;
    --danger-bg: #fef3f2;
    --success:   #067647;
    --success-bg:#ecfdf3;
    --warning:   #b54708;

    --brand-primary: var(--brand-primary-light);
    --brand-accent:  var(--brand-accent-light);

    --radius: 10px;
    --radius-sm: 7px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --sidebar-w: 248px;
}

/* Dark tokens: applied when the OS prefers dark and no explicit light override,
   and whenever data-theme="dark" is set. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:        #0b0e14;
        --surface:   #12161f;
        --surface-2: #171c26;
        --border:    #242b38;
        --border-strong: #313a4a;
        --text:      #e6e9ef;
        --muted:     #97a1b2;
        --muted-2:   #6b7688;
        --ring:      rgba(90, 173, 232, 0.4);
        --danger:    #f97066;
        --danger-bg: #2a1512;
        --success:   #47cd89;
        --success-bg:#0f2419;
        --warning:   #f79009;
        --brand-primary: var(--brand-primary-dark);
        --brand-accent:  var(--brand-accent-dark);
    }
}
:root[data-theme="dark"] {
    --bg:        #0b0e14;
    --surface:   #12161f;
    --surface-2: #171c26;
    --border:    #242b38;
    --border-strong: #313a4a;
    --text:      #e6e9ef;
    --muted:     #97a1b2;
    --muted-2:   #6b7688;
    --ring:      rgba(90, 173, 232, 0.4);
    --danger:    #f97066;
    --danger-bg: #2a1512;
    --success:   #47cd89;
    --success-bg:#0f2419;
    --warning:   #f79009;
    --brand-primary: var(--brand-primary-dark);
    --brand-accent:  var(--brand-accent-dark);
}

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

html { color-scheme: light dark; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

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

h1, h2, h3 { line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--brand-primary); color: #fff;
    font: 600 0.9rem var(--font); cursor: pointer;
    transition: filter .15s, background .15s, border-color .15s, opacity .15s;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--surface-2); filter: none; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); filter: none; }
.btn.danger { background: var(--danger); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 0.82rem; }
.btn.block { width: 100%; }

/* --- Form controls --- */
.label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.hint { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.field { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.input, .select, .textarea {
    width: 100%; height: 40px; padding: 0 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    font: 0.9rem var(--font); transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--ring);
}
.input.mono { font-family: var(--mono); font-size: 0.85rem; }
.select {
    appearance: none; cursor: pointer; padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%23667085' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger); }
input[type="color"].swatch {
    width: 100%; height: 40px; padding: 4px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}

/* --- Cards --- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-header { padding: 20px 22px 0; }
.card-title { font-size: 1.05rem; font-weight: 650; }
.card-desc { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.card-body { padding: 20px 22px; }
.card-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* --- Badges --- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font: 600 0.72rem var(--font); padding: 3px 9px; border-radius: 999px;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.brand { color: var(--brand-primary); background: color-mix(in srgb, var(--brand-primary) 12%, transparent); border-color: color-mix(in srgb, var(--brand-primary) 30%, transparent); }
.badge.success { color: var(--success); background: var(--success-bg); border-color: transparent; }
.badge.muted { color: var(--muted); }

/* --- Alerts --- */
.alert { display: none; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 0.86rem; margin-bottom: 16px; border: 1px solid transparent; }
.alert.error { display: block; background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.success { display: block; background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }

/* --- App shell (sidebar layout) --- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 14px;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; min-height: 40px; }
.sidebar-brand img { max-height: 30px; max-width: 170px; object-fit: contain; }
.sidebar-brand .name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--muted); font-size: 0.9rem; font-weight: 550; cursor: pointer;
    background: none; border: none; width: 100%; text-align: left; font-family: var(--font);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--brand-primary) 12%, transparent); color: var(--brand-primary); }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 32px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 1.2rem; }
.content { padding: 28px 32px; max-width: 960px; }
.content.wide { max-width: 1200px; }

/* --- Tabs (top style) --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; overflow-x: auto; }
.tab { padding: 10px 14px; border: none; background: none; color: var(--muted); font: 600 0.88rem var(--font); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

/* --- Theme toggle --- */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); cursor: pointer; }
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-toggle .icon-dark { display: block; } :root:not([data-theme="light"]) .theme-toggle .icon-light { display: none; } }

/* --- Auth / wizard centered layout --- */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 440px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head img { max-height: 44px; max-width: 240px; object-fit: contain; margin-bottom: 12px; }
.auth-head .name { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.auth-head .sub { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }

.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; border: none; padding: 0; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
    .form-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
