:root {
    --danger: #dc2626;
    --success: #059669;
    --dark-bg: #1a1f35;
    --darker-bg: #141824;
    --accent-green: #00ff88;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'DM Sans', sans-serif; color: var(--text); background: var(--bg); }

/* ===== AUTH LOGIN (Onapers brand split screen) ===== */
.auth-body { min-height: 100vh; background: var(--darker-bg); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand {
    position: relative; overflow: hidden;
    background: var(--gradient-dark);
    display: flex; align-items: center; justify-content: center; padding: 3rem;
}
.auth-brand-overlay {
    position: absolute; inset: 0;
    background: radial-gradient(circle at 20% 80%, rgba(255,137,4,0.18), transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(0,212,255,0.08), transparent 40%);
}
.auth-brand-inner { position: relative; z-index: 1; color: #fff; max-width: 420px; }
.auth-brand-logo {
    margin-bottom: 1.5rem;
}
.auth-brand-logo img {
    display: block;
    max-height: 80px;
    max-width: 240px;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.25));
}
.auth-panel-logo {
    margin-bottom: 1.25rem;
}
.auth-panel-logo img {
    display: block;
    max-height: 64px;
    max-width: 220px;
    width: auto;
    height: auto;
    object-fit: contain;
}
.auth-brand h1 { font-size: 2rem; line-height: 1.2; margin-bottom: .5rem; }
.brand-sub { color: rgba(255,255,255,0.7); font-size: 1rem; margin-bottom: 2rem; }
.brand-features { display: grid; gap: .75rem; }
.brand-feature { display: flex; align-items: center; gap: .75rem; color: rgba(255,255,255,0.85); font-size: .95rem; }
.brand-feature span { color: var(--secondary); }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--card, #fff); }
.auth-panel-inner { width: 100%; max-width: 420px; position: relative; }
.auth-theme-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}
.auth-header { margin-bottom: 2rem; }
.auth-header h2 { font-size: 1.75rem; font-weight: 700; margin-bottom: .35rem; }
.auth-header p { color: var(--muted); }
.auth-alert { padding: .875rem 1rem; border-radius: 10px; margin-bottom: 1.25rem; font-size: .9rem; }
.auth-alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.auth-form { display: grid; gap: 1.25rem; }
.form-field label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .4rem; color: #374151; }
.form-field input {
    width: 100%; padding: .875rem 1rem; border: 1.5px solid var(--border);
    border-radius: 10px; font-size: .95rem; transition: border-color .2s, box-shadow .2s;
}
.form-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.auth-submit {
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    width: 100%; padding: .95rem; border: none; border-radius: 10px; cursor: pointer;
    background: var(--gradient-brand);
    color: #fff; font-size: 1rem; font-weight: 600; transition: transform .15s, box-shadow .2s;
    box-shadow: 0 4px 14px var(--primary-glow);
}
.auth-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255, 137, 4, 0.35); }
.auth-demo {
    margin-top: 1.75rem; padding: 1rem; background: #f9fafb;
    border-radius: 10px; border: 1px dashed var(--border); font-size: .85rem; color: #4b5563;
}
.auth-demo-title { font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.auth-back { display: inline-block; margin-top: 1.5rem; color: var(--primary); text-decoration: none; font-weight: 500; font-size: .9rem; }
.auth-back:hover { text-decoration: underline; }
.auth-legal { margin-top: 2rem; font-size: .78rem; color: var(--muted); }

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
}

/* ===== ADMIN DASHBOARD ===== */
.admin-body { min-height: 100vh; background: var(--bg); }
.admin-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.admin-sidebar {
    background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    border-right: 1px solid rgba(255, 137, 4, 0.12);
}
.sidebar-brand {
    display: flex; align-items: center; gap: .75rem; padding: 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: linear-gradient(180deg, rgba(255,137,4,0.08), transparent);
}
.sidebar-brand img { height: 36px; }
.sidebar-brand strong { display: block; color: #fff; font-size: .95rem; }
.sidebar-brand span { font-size: .75rem; color: var(--secondary); opacity: .85; }
.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.sidebar-nav .nav-top-link {
    display: block;
    padding: .7rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 600;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
}
.sidebar-nav .nav-top-link:hover,
.sidebar-nav .nav-top-link.active {
    background: rgba(255, 137, 4, 0.1);
    color: #fff;
    border-left-color: var(--primary);
}
.nav-group {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.nav-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .7rem 1.25rem;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: rgba(255, 255, 255, 0.92);
    font-family: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background .15s, color .15s, border-color .15s;
}
.nav-group-toggle:hover,
.nav-group.is-open > .nav-group-toggle {
    background: rgba(255, 137, 4, 0.08);
    color: #fff;
}
.nav-group.is-open > .nav-group-toggle {
    border-left-color: rgba(255, 137, 4, 0.45);
}
.nav-chevron {
    font-size: .55rem;
    opacity: .75;
    transition: transform .2s ease;
}
.nav-group.is-open .nav-chevron {
    transform: rotate(180deg);
}
.nav-submenu {
    display: none;
    padding: .15rem 0 .55rem;
    background: rgba(0, 0, 0, 0.12);
}
.nav-group.is-open .nav-submenu {
    display: block;
}
.sidebar-nav .nav-submenu a {
    display: block;
    padding: .5rem 1.25rem .5rem 2.15rem;
    color: rgba(255, 255, 255, 0.72);
    text-decoration: none;
    font-size: .84rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
}
.sidebar-nav .nav-submenu a:hover,
.sidebar-nav .nav-submenu a.active {
    background: rgba(255, 137, 4, 0.12);
    color: #fff;
    border-left-color: var(--primary);
}
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.08); display: grid; gap: .5rem; }
.sidebar-footer a { color: var(--sidebar-text); text-decoration: none; font-size: .85rem; }
.sidebar-footer a.logout { color: #f87171; }

.admin-main { display: flex; flex-direction: column; min-width: 0; }
.admin-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 2rem; background: var(--card); border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(255, 137, 4, 0.06);
}
.admin-topbar h1 { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.admin-topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.admin-theme-controls {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.theme-control-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: .8rem;
    font-family: inherit;
    transition: border-color .2s, box-shadow .2s;
}
.theme-control-btn:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.theme-dropdown { position: relative; }
.theme-dropdown-panel {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    padding: .85rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.12);
    z-index: 20;
}
.theme-dropdown:hover .theme-dropdown-panel,
.theme-dropdown:focus-within .theme-dropdown-panel {
    display: block;
}
.theme-dropdown-title {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: .65rem;
}
.theme-swatches { display: grid; gap: .45rem; }
.theme-swatch {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    padding: .55rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    cursor: pointer;
    font-family: inherit;
    font-size: .82rem;
    color: var(--text);
    text-align: left;
}
.theme-swatch::before {
    content: '';
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}
.theme-swatch-onapers::before { background: linear-gradient(135deg, #FF8904, #fbbf24); }
.theme-swatch-ocean::before { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.theme-swatch-forest::before { background: linear-gradient(135deg, #059669, #34d399); }
.theme-swatch-royal::before { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.theme-swatch.is-active,
.theme-swatch[data-admin-theme].is-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}
.mode-icon-dark { display: none; }
[data-mode="dark"] .mode-icon-light { display: none; }
[data-mode="dark"] .mode-icon-dark { display: inline; }
.theme-option-grid,
.mode-option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: .75rem;
}
.theme-option-card,
.mode-option-card {
    display: block;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .85rem;
    background: var(--bg);
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}
.theme-option-card input,
.mode-option-card input { display: none; }
.theme-option-card span,
.mode-option-card span {
    display: block;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
}
.theme-option-onapers { border-top: 4px solid #FF8904; }
.theme-option-ocean { border-top: 4px solid #0ea5e9; }
.theme-option-forest { border-top: 4px solid #059669; }
.theme-option-royal { border-top: 4px solid #7c3aed; }
.theme-option-card:has(input:checked),
.mode-option-card:has(input:checked) {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.admin-user { text-align: right; }
.admin-user span { display: block; font-weight: 600; font-size: .9rem; }
.admin-user small { color: var(--muted); font-size: .8rem; }
.admin-user-link { text-decoration: none; color: inherit; text-align: right; display: block; }
.admin-user-link:hover span { color: var(--primary); }
.admin-content { padding: 1.5rem 2rem 2rem; flex: 1; }
.admin-alert { margin: 0 2rem; padding: .875rem 1rem; border-radius: 8px; font-size: .9rem; }
.admin-alert-success { background: var(--alert-success-bg); color: var(--success); border: 1px solid var(--alert-success-border); }
.admin-alert-error { background: var(--alert-error-bg); color: var(--danger); border: 1px solid var(--alert-error-border); }

.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--card); border-radius: 12px; padding: 1.25rem;
    border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.stat-card span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .35rem; }
.stat-card strong { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-card.highlight { border-color: var(--primary); background: var(--highlight-bg); }

.panel-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 1.5rem; }
.panel { background: var(--card); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; }
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 1rem; font-weight: 600; }
.panel-head a { color: var(--primary); font-size: .85rem; text-decoration: none; }
.panel-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.panel-actions .btn { font-size: .85rem; padding: .45rem .9rem; }
.panel-body { padding: 1.25rem; }
.quick-links { display: grid; gap: .5rem; }
.quick-links a {
    display: block; padding: .75rem 1rem; background: var(--bg); border-radius: 8px;
    color: var(--text); text-decoration: none; font-size: .9rem; transition: background .15s;
}
.quick-links a:hover { background: var(--primary-glow); color: var(--primary); }

.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th, .data-table td { padding: .75rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.data-table.compact td, .data-table.compact th { padding: .5rem .75rem; }
.data-table code { font-size: .78rem; background: var(--bg); padding: .15rem .4rem; border-radius: 4px; }
.data-table .actions a { margin-right: .75rem; color: var(--primary); text-decoration: none; font-weight: 500; }
.data-table .actions a.danger { color: var(--danger); }
.message-preview { background: var(--bg); font-size: .85rem; color: var(--muted); }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; }
.badge-new { background: #dbeafe; color: #1d4ed8; }
.badge-read { background: #e5e7eb; color: #4b5563; }
.badge-replied { background: #d1fae5; color: #047857; }

.btn {
    display: inline-flex; align-items: center; padding: .6rem 1.1rem;
    border-radius: 8px; font-size: .875rem; font-weight: 600; text-decoration: none;
    border: none; cursor: pointer; transition: opacity .15s;
}
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: 0 2px 8px var(--primary-glow); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn:hover { opacity: .9; }

.admin-form { display: grid; gap: 1rem; max-width: 720px; }
.admin-form.grid-2 { grid-template-columns: 1fr 1fr; max-width: none; }
.admin-form .full { grid-column: 1 / -1; }
.form-row label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
.form-row input, .form-row textarea, .form-row select {
    width: 100%; padding: .7rem .875rem; border: 1px solid var(--border);
    border-radius: 8px; font-family: inherit; font-size: .9rem;
    background: var(--input-bg, #fff);
    color: var(--text);
}
.form-row small { display: block; margin-top: .25rem; color: var(--muted); font-size: .78rem; }
.form-row.inline label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.form-actions { display: flex; gap: .75rem; margin-top: .5rem; }
.form-actions.full { grid-column: 1 / -1; }
.muted { color: var(--muted); }

.media-upload-field { margin-bottom: 1rem; }
.media-preview {
    display: grid; gap: .5rem; margin-bottom: .75rem; padding: .75rem;
    background: var(--bg); border: 1px dashed var(--border); border-radius: 10px;
}
.media-preview.empty { color: var(--muted); font-size: .875rem; }
.media-preview img, .media-preview video {
    max-width: 280px; max-height: 160px; border-radius: 8px;
    object-fit: cover; background: #000;
}
.media-preview code { font-size: .75rem; word-break: break-all; }
.media-file-input {
    width: 100%; padding: .65rem; border: 1px solid var(--border);
    border-radius: 8px; background: var(--input-bg, #fff);
    color: var(--text);
}
.media-path-input {
    width: 100%; padding: .7rem .875rem; border: 1px solid var(--border);
    border-radius: 8px; font-family: inherit; font-size: .9rem; margin-top: .35rem;
}
.path-label { font-size: .78rem; color: var(--muted); margin-top: .5rem; }
.required-mark { color: var(--danger); }

.permission-groups { display: grid; gap: 1rem; margin: 1rem 0; }
.permission-group { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; background: var(--surface-muted, #fafbfc); }
.permission-group h4 { margin-bottom: .75rem; font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); }
.permission-list { display: grid; gap: .5rem; }
.permission-item {
    display: flex; gap: .75rem; align-items: flex-start; padding: .65rem .75rem;
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
}
.permission-item input { margin-top: .2rem; }
.permission-item strong { display: block; font-size: .9rem; }
.permission-item small { display: block; color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.icon-preview svg { width: 48px; height: 48px; margin-top: 10px; }

.icon-picker-row { grid-column: 1 / -1; }
.icon-picker-help { color: var(--muted); font-size: .85rem; margin: .35rem 0 .75rem; }
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: .75rem;
    max-height: 420px;
    overflow-y: auto;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-muted, #fafbfc);
}
.icon-picker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .45rem;
    padding: .75rem .5rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s, transform .15s;
    min-height: 108px;
}
.icon-picker-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px var(--primary-glow);
    transform: translateY(-1px);
}
.icon-picker-item.is-selected {
    border-color: var(--primary);
    background: var(--primary-glow);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.icon-picker-graphic {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
}
.icon-picker-graphic svg { width: 34px; height: 34px; display: block; }
.icon-picker-label {
    font-size: .72rem;
    line-height: 1.25;
    text-align: center;
    color: var(--text);
    font-weight: 500;
}
.thumb-cell img, .thumb-cell video {
    width: 72px; height: 48px; object-fit: cover; border-radius: 6px; background: #eee;
}
.thumb-cell { display: flex; align-items: center; gap: .5rem; }
.thumb-cell code { font-size: .7rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1024px) {
    .admin-shell { grid-template-columns: 1fr; }
    .admin-sidebar { position: relative; height: auto; }
    .panel-grid { grid-template-columns: 1fr; }
    .admin-form.grid-2 { grid-template-columns: 1fr; }
}
