:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #eef3f7;
    --text: #17202a;
    --muted: #667085;
    --line: #d9e0e7;
    --primary: #0f766e;
    --primary-strong: #0b5f59;
    --accent: #4f46e5;
    --warning: #b45309;
    --danger: #b42318;
    --success: #13795b;
    --shadow: 0 18px 50px rgba(22, 32, 42, .08);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101418;
    --surface: #171d23;
    --surface-soft: #222a32;
    --text: #f4f7fa;
    --muted: #aab5c0;
    --line: #2c3844;
    --primary: #2dd4bf;
    --primary-strong: #5eead4;
    --accent: #a5b4fc;
    --warning: #f6c453;
    --danger: #ff8a7c;
    --success: #6ee7b7;
    --shadow: 0 18px 50px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.material-symbols-rounded { font-size: 20px; line-height: 1; vertical-align: middle; }

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, .12), transparent 32%),
        linear-gradient(315deg, rgba(79, 70, 229, .12), transparent 34%),
        var(--bg);
}
.auth-shell { width: min(460px, calc(100vw - 32px)); }
.auth-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 34px;
}
.auth-panel h1 { margin: 28px 0 8px; font-size: 30px; letter-spacing: 0; }
.brand-lockup { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand-lockup small { display: block; color: var(--muted); margin-top: 2px; }
.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}
.sidebar-brand { padding: 18px; }
.app-body { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}
.nav-list { padding: 8px 12px; display: grid; gap: 4px; }
.nav-list a, .icon-text {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 8px;
    color: var(--muted);
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
}
.nav-list a.active, .nav-list a:hover, .icon-text:hover { background: var(--surface-soft); color: var(--text); }
.logout-form { margin-top: auto; padding: 12px; }
.danger { color: var(--danger) !important; }
.main-shell { min-width: 0; }
.topbar {
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: space-between;
    padding: 16px 28px;
    background: rgba(255,255,255,.8);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}
[data-theme="dark"] .topbar { background: rgba(23,29,35,.82); }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 600;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.avatar-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
}
.content { padding: 28px; max-width: 1440px; margin: 0 auto; width: 100%; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.metric-card, .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.metric-card { padding: 18px; display: grid; gap: 8px; min-height: 134px; }
.metric-card .material-symbols-rounded { color: var(--primary); font-size: 28px; }
.metric-card small, .muted, .compact-row small { color: var(--muted); }
.metric-card strong { font-size: 28px; letter-spacing: 0; overflow-wrap: anywhere; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 16px; }
.wide-left { grid-template-columns: minmax(0, 1.4fr) minmax(320px, .6fr); }
.panel { padding: 18px; min-width: 0; }
.panel-heading, .toolbar, .button-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.panel-heading { margin-bottom: 14px; }
.panel-heading h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.compact-list { display: grid; gap: 10px; }
.compact-row {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
.pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: var(--surface-soft);
}
.pill.youtube { color: var(--danger); }
.pill.facebook { color: var(--accent); }
.stack-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 600; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 11px 12px;
    outline: none;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.primary-button, .secondary-button, .ghost-button, .icon-button {
    min-height: 42px;
    border-radius: 8px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
    white-space: nowrap;
}
.primary-button { background: var(--primary); color: #fff; padding: 0 16px; }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { background: var(--surface-soft); color: var(--text); padding: 0 16px; border-color: var(--line); }
.ghost-button { background: transparent; color: var(--primary); padding: 0 10px; border-color: var(--line); }
.icon-button { width: 42px; background: var(--surface); color: var(--text); border-color: var(--line); }
.check-row, .switch-row { display: flex; align-items: center; gap: 9px; }
.check-row input, .switch-row input, .permission-grid input { width: auto; }
.alert { padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line); font-weight: 700; }
.alert.success { color: var(--success); background: rgba(19, 121, 91, .08); }
.alert.danger { color: var(--danger); background: rgba(180, 35, 24, .08); }
.subtle-link { justify-self: center; font-weight: 700; }
.generator-layout { display: grid; grid-template-columns: minmax(330px, .9fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.generator-form textarea { min-height: 360px; }
.radio-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.radio-grid label { position: relative; }
.radio-grid input { position: absolute; opacity: 0; }
.radio-grid span {
    display: grid;
    place-items: center;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: var(--surface);
}
.radio-grid input:checked + span { border-color: var(--primary); background: rgba(15,118,110,.1); color: var(--primary); }
.output-panel { min-height: 520px; }
.output-empty, .loading-box {
    min-height: 360px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    color: var(--muted);
    text-align: center;
}
.output-empty .material-symbols-rounded { font-size: 46px; color: var(--primary); }
.hidden { display: none !important; }
.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid var(--line);
    border-top-color: var(--primary);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.output-grid { display: grid; gap: 12px; }
.result-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface);
}
.result-card header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.result-card h3 { margin: 0; font-size: 15px; letter-spacing: 0; }
.result-card pre, .result-card ul { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); line-height: 1.55; }
.result-card ul { padding-left: 18px; }
.score-ring {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--primary) calc(var(--score) * 1%), var(--surface-soft) 0);
    color: var(--text);
    font-weight: 800;
}
.toolbar { margin-bottom: 14px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box span { position: absolute; top: 11px; left: 10px; color: var(--muted); }
.search-box input { padding-left: 38px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-soft); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0; }
td { color: var(--text); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; color: var(--muted); font-size: 13px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 20; }
.toast {
    min-width: min(340px, calc(100vw - 36px));
    padding: 12px 14px;
    border-radius: 8px;
    color: #fff;
    background: #17202a;
    box-shadow: var(--shadow);
}
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
.mobile-nav-toggle { display: none; }
.empty { color: var(--muted); margin: 0; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .generator-layout, .two-column, .wide-left { grid-template-columns: 1fr; }
    .form-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-body { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 10;
        width: min(280px, 86vw);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-nav-toggle { display: inline-flex; }
    .topbar { padding: 12px 16px; }
    .topbar h1 { font-size: 18px; }
    .content { padding: 16px; }
    .metric-grid, .form-grid, .form-grid.four, .permission-grid { grid-template-columns: 1fr; }
    .auth-panel { padding: 24px; }
    .user-chip span:last-child { display: none; }
}
