:root {
    --bg: #eef2f6;
    --bg-accent: #d9e4f0;
    --surface: #ffffff;
    --surface-2: #f7fafc;
    --text: #18212f;
    --muted: #5b6b7c;
    --primary: #0f6a5a;
    --primary-hover: #0b5447;
    --danger: #b42318;
    --border: #d5dee8;
    --shadow: 0 12px 40px rgba(24, 33, 47, 0.08);
    --radius: 14px;
    --gap: 1rem;
    --font: "Segoe UI", "Helvetica Neue", sans-serif;
    --mono: Consolas, "Courier New", monospace;
    --msg-pad: 1rem;
    --sidebar-width: 300px;
}

html[data-theme='dark'] {
    --bg: #12171e;
    --bg-accent: #1b2430;
    --surface: #1a222d;
    --surface-2: #222b38;
    --text: #e8eef5;
    --muted: #9aa8b8;
    --primary: #3cbc9b;
    --primary-hover: #2fa887;
    --danger: #f97066;
    --border: #2d3948;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

html[data-theme='sepia'] {
    --bg: #f3ead7;
    --bg-accent: #e7d8b8;
    --surface: #fff8ea;
    --surface-2: #f7edd8;
    --text: #3b2f1f;
    --muted: #7a684d;
    --primary: #8a5a2b;
    --primary-hover: #70461f;
    --border: #dfd0b3;
}

html[data-font='ibm-plex'] { --font: "Segoe UI", Tahoma, sans-serif; }
html[data-font='literata'] { --font: Georgia, "Times New Roman", serif; }
html[data-font='jetbrains-mono'] { --font: Consolas, "Courier New", monospace; }
html[data-font='source-sans'] { --font: "Segoe UI", "Helvetica Neue", sans-serif; }

html[data-size='sm'] { font-size: 14px; }
html[data-size='md'] { font-size: 16px; }
html[data-size='lg'] { font-size: 18px; }

html[data-density='compact'] { --gap: 0.65rem; --msg-pad: 0.7rem; }
html[data-density='comfortable'] { --gap: 1rem; --msg-pad: 1rem; }
html[data-density='spacious'] { --gap: 1.35rem; --msg-pad: 1.25rem; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background:
        radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--bg-accent) 80%, transparent), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 55%),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    background-attachment: fixed;
}

body.chat-app {
    overflow: hidden;
}

.container {
    width: min(960px, 92%);
    margin: 0 auto;
}

.site-header,
.site-footer {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.site-footer {
    border-bottom: none;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
    padding: 1rem 0;
    color: var(--muted);
}

.site-header .container,
.site-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-header { padding: 1rem 0; }

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.site-nav a,
.site-nav button { margin-left: 0.75rem; }

a { color: var(--primary); }

main { padding: 2rem 0 3rem; }

.auth-card,
.dashboard-card,
.error-card,
.admin-page {
    max-width: 480px;
    margin: 0 auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.admin-page { max-width: 860px; }
.dashboard-card,
.error-card { max-width: 640px; }

h1, h2 { margin-top: 0; }

.subtitle { color: var(--muted); margin-top: 0; }

label {
    display: block;
    margin: 1rem 0 0.35rem;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface-2);
    color: var(--text);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.25rem;
    padding: 0.7rem 1rem;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: color-mix(in srgb, var(--border) 70%, var(--surface));
    color: var(--text);
}

.btn-danger {
    background: color-mix(in srgb, var(--danger) 18%, var(--surface));
    color: var(--danger);
}

.btn-sm {
    margin-top: 0;
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
    margin-top: 0.75rem;
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    margin: 1rem 0;
}

.alert-error {
    background: color-mix(in srgb, var(--danger) 14%, var(--surface));
    color: var(--danger);
}

.alert-success {
    background: color-mix(in srgb, var(--primary) 14%, var(--surface));
    color: var(--primary);
}

.hidden { display: none !important; }

.auth-switch { margin-top: 1.5rem; color: var(--muted); }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.65rem 0.4rem;
    border-bottom: 1px solid var(--border);
}

.admin-form {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.loading { color: var(--muted); margin-top: 1rem; }
.field-error { color: var(--danger); font-size: 0.875rem; margin-top: 0.25rem; }
.field-hint {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.45;
}

.link-btn {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
}

.link-btn:hover { color: var(--primary-hover); }

.app-dialog {
    width: min(440px, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--surface);
    color: var(--text);
}

.app-dialog-wide {
    width: min(560px, calc(100vw - 2rem));
}

.app-dialog::backdrop {
    background: rgba(12, 18, 28, 0.45);
    backdrop-filter: blur(2px);
}

.dialog-form {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 2rem);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.dialog-body {
    padding: 1rem 1.25rem 1.25rem;
    overflow: auto;
}

.dialog-body label:first-child {
    margin-top: 0;
}

.dialog-intro {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.65rem;
    padding: 0.85rem 1.25rem 1.15rem;
    border-top: 1px solid var(--border);
}

.dialog-footer .btn {
    margin-top: 0;
}

.dialog-close {
    flex-shrink: 0;
}

.prefs-save-status {
    margin-right: auto;
    font-size: 0.875rem;
    color: var(--muted);
}

.prefs-save-status.is-error {
    color: var(--danger);
}

.app-toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    padding: 0.65rem 1rem;
    border-radius: 999px;
    background: var(--text);
    color: var(--surface);
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    pointer-events: none;
}

.admin-list-wrap {
    overflow-x: auto;
}

@keyframes checkPop {
    0% { transform: scale(0.6); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

.upload-success {
    display: inline-block;
    color: var(--primary);
    animation: checkPop 0.35s ease;
}
