/* ─── Design tokens ─── */
:root {
    --bg: #f7f4fc;
    --surface: #ffffff;
    --surface-raised: #fdf9ff;
    --surface-inset: #f4f0fa;
    --text: #1a1228;
    --muted: #6b5c85;
    --accent: #663399;
    --accent-hover: #4e2177;
    --accent-gold: #f2b84b;
    --accent-gold-hover: #d9a038;
    --border: #e2d9f0;
    --danger: #b91c1c;
    --success: #166634;
    --shadow: 0 8px 28px rgba(102,51,153,0.10);
    --sidebar-bg: #ffffff;
    --sidebar-text: #5a3e85;
    --sidebar-hover: rgba(102,51,153,0.07);
    --sidebar-active-bg: rgba(102,51,153,0.10);
    --sidebar-active-color: #663399;
    --sidebar-border: #e2d9f0;
    --sidebar-width: 220px;
}

html[data-theme='dark'] {
    --bg: #111827;
    --surface: #151e2d;
    --surface-raised: #1a2540;
    --surface-inset: #0d1420;
    --text: #ede8f8;
    --muted: white;
    --accent: #9d5fe6;
    --accent-hover: #b57af0;
    --accent-gold: #f2b84b;
    --accent-gold-hover: #ffd077;
    --border: #2a3550;
    --danger: #f87171;
    --success: #86efac;
    --shadow: 0 10px 32px rgba(0,0,0,0.55);
    --sidebar-bg: #151e2d;
    --sidebar-text: white;
    --sidebar-hover: rgba(242,184,75,0.08);
    --sidebar-active-bg: rgba(242,184,75,0.16);
    --sidebar-active-color: #f2b84b;
    --sidebar-border: #2a3550;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ─── App shell ─── */
.app-shell { display: flex; min-height: 100vh; }

/* ─── Left Sidebar ─── */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 200;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.06) transparent;
    transition: width 0.25s ease, transform 0.25s ease;
}
.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 4px; }

.sidebar-brand {
    padding: 9px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
 
}
.sidebar-brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.sidebar-logo-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #663399 0%, #f2b84b 100%);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sidebar-logo-mark svg { width: 18px; height: 18px; fill: #fff; }
.sidebar-brand-name { font-size: 1rem; font-weight: 700; letter-spacing: 0.04em; color: #fff; }

.sidebar-section { padding: 12px 0 4px; }
.sidebar-section-label {
    padding: 0 16px 6px;
    font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em;
    text-transform: uppercase; color: rgba(255,255,255,0.28);
}
.sidebar-nav { list-style: none; }
.sidebar-nav-item a,
.sidebar-nav-item button {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 16px; width: 100%;
    border: none; background: none; text-decoration: none;
    color: var(--sidebar-text); font-size: 0.88rem; font-weight: 500;
    border-radius: 0; cursor: pointer;
    transition: background 0.15s, color 0.15s; text-align: left;
}
.sidebar-subnav { list-style: none; margin: 8px 0 0 20px; padding: 0; }
.sidebar-subnav-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0; color: rgba(255,255,255,0.65);
    font-size: 0.85rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: color 0.15s;
}
.sidebar-subnav-item:hover { color: #fff; }
.sidebar-subnav-item.active { color: var(--sidebar-active-color); }
.sidebar-subnav-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.2); flex-shrink: 0; }
.sidebar-subnav-item.active .sidebar-subnav-dot { background: var(--sidebar-active-color); }
.sidebar-subnav-add { margin-top: 8px; margin-right: 19px; }
.sidebar-subnav-add a {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; border: 1px dashed rgba(242,184,75,0.45);
    border-radius: 8px; color: rgba(242,184,75,0.9);
    font-size: 0.84rem; text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}
.sidebar-subnav-add a:hover { background: rgba(242,184,75,0.08); border-color: rgba(242,184,75,0.8); color: #f2b84b; }
.sidebar-nav-item a:hover,
.sidebar-nav-item button:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav-item a.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-color); font-weight: 600; }
.sidebar-nav-item a.active .nav-icon { opacity: 1; }
.nav-icon { width: 16px; height: 16px; opacity: 0.55; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--sidebar-border); padding: 10px 0; }

/* ─── Main content ─── */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex; flex-direction: column;
    min-height: 100vh; min-width: 0; height: 100vh;
    transition: margin-left 0.25s ease;
}

.app-topbar {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 10px; padding: 0 20px;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
    position: sticky; top: 0; z-index: 100;
    height: 51px;
}
.app-topbar .muted { color: var(--sidebar-text); }
.app-topbar .sidebar-toggle { color: var(--sidebar-text); }

.app-content {
    flex: 1; padding: 30px; margin: 0;
    min-width: 0; display: flex; flex-direction: column; overflow: auto;
}
.app-content--no-pad { padding: 0; height: 100%; overflow: hidden; }
.app-content .workspace { flex: 1; width: 100%; height: 100%; }

/* ─── Sidebar collapse (Gmail style) ─── */
.app-shell.sidebar-collapsed .app-sidebar { width: 52px; overflow: hidden; }
.app-shell.sidebar-collapsed .app-main { margin-left: 52px; }
.app-shell.sidebar-collapsed .sidebar-brand-name,
.app-shell.sidebar-collapsed .sidebar-section-label,
.app-shell.sidebar-collapsed .sidebar-subnav,
.app-shell.sidebar-collapsed .sidebar-subnav-add,
.app-shell.sidebar-collapsed #theme-label { display: none; }
.app-shell.sidebar-collapsed .sidebar-brand { padding: 10px 10px; justify-content: center; }
.app-shell.sidebar-collapsed .sidebar-brand-link { justify-content: center; }
.app-shell.sidebar-collapsed .sidebar-nav-item a,
.app-shell.sidebar-collapsed .sidebar-nav-item button {
    justify-content: center; padding: 10px 8px; font-size: 0; gap: 0;
}
.app-shell.sidebar-collapsed .sidebar-section { padding: 42px 0 4px; }
.app-shell.sidebar-collapsed .nav-icon { opacity: 1; flex-shrink: 0; }
.app-shell.sidebar-collapsed .sidebar-nav-item a.active,
.app-shell.sidebar-collapsed .sidebar-nav-item button.active {
    background: transparent;
    border-left: 3px solid var(--sidebar-active-color);
    padding-left: 5px;
}
.app-shell.sidebar-collapsed .sidebar-nav-item a.active .nav-icon,
.app-shell.sidebar-collapsed .sidebar-nav-item button.active .nav-icon {
    color: var(--sidebar-active-color);
    opacity: 1;
}

/* ─── Sidebar toggle button ─── */
.sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: none; border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; color: var(--text);
    flex-shrink: 0; margin-right: auto;
    font-size: 16px; font-weight: 700;
}
.sidebar-toggle:hover { background: var(--sidebar-hover); }

/* ─── Shared components ─── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow); padding: 24px;
}
.auth-card {
    max-width: 420px;
    width: min(560px, 100%);
    margin: 80px auto 0;
}
.muted { color: var(--muted); }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid transparent; border-radius: 9px;
    padding: 8px 14px; text-decoration: none; cursor: pointer;
    font-weight: 600; font-size: 0.88rem;
    background: var(--accent); color: #fff; transition: background 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.gold { background: var(--accent-gold); color: #1a0a2e; }
.btn.gold:hover { background: var(--accent-gold-hover); }
.btn.secondary { background: var(--surface-raised); border-color: var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--border); border-color: var(--accent); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 0.80rem; border-radius: 7px; }

.grid { display: grid; gap: 16px; }
label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 0.88rem; }

input[type='text'],
input[type='email'],
input[type='password'],
input[type='date'],
select,
textarea {
    width: 100%; border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface-raised); color: var(--text);
    padding: 9px 12px; margin-bottom: 14px!Important;
    font-size: 0.9rem; font-family: inherit; outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(102,51,153,0.12);
}
html[data-theme='dark'] input:focus,
html[data-theme='dark'] select:focus,
html[data-theme='dark'] textarea:focus { box-shadow: 0 0 0 3px rgba(157,95,230,0.18); }
input[type='date'] { color-scheme: light; padding-right: 15px; }
html[data-theme='dark'] input[type='date'] { color-scheme: dark; }
input[type='date']::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.9; }
html[data-theme='dark'] input[type='date']::-webkit-calendar-picker-indicator { filter: none; }
textarea { min-height: 110px; resize: vertical; }
select option { color: var(--text); background: var(--surface); }

.error { color: var(--danger); margin: 0 0 12px; font-size: 0.88rem; }
.ok    { color: var(--success); margin-bottom: 12px; font-size: 0.88rem; }
.small { font-size: 0.88rem; }

/* ─── Toast ─── */
#dl-toast {
    position: fixed; bottom: 28px; right: 28px; z-index: 9999;
    display: flex; align-items: center; gap: 10px;
    padding: 13px 20px;
    background: #1a2e1a; border: 1px solid #2d6a2d;
    border-left: 4px solid var(--success); border-radius: 10px;
    color: var(--success); font-size: 0.9rem; font-weight: 500;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
    opacity: 1; transform: translateY(0);
    transition: opacity 0.45s ease, transform 0.45s ease;
    pointer-events: none;
}
[data-theme="light"] #dl-toast {
    background: #f0fdf4; border-color: #86efac;
    border-left-color: #166634; color: #166634;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
#dl-toast.dl-toast-hide { opacity: 0; transform: translateY(12px); }
#dl-toast svg { flex-shrink: 0; width: 18px; height: 18px; }

/* ─── Mobile ─── */
@media (max-width: 800px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .app-content { padding: 16px; }
}

/* ─── Light mode overrides ─── */
html[data-theme='light'] .app-sidebar { background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border); box-shadow: 2px 0 12px rgba(102,51,153,0.06); }
html[data-theme='light'] .app-sidebar::-webkit-scrollbar-thumb { background: rgba(102,51,153,0.1); }
html[data-theme='light'] .sidebar-brand, html[data-theme='light'] .sidebar-section { border-color: var(--sidebar-border); }
html[data-theme='light'] .sidebar-brand-name { color: #1a0a2e; }
html[data-theme='light'] .sidebar-section-label { color: rgba(102,51,153,0.45); }
html[data-theme='light'] .sidebar-nav-item a, html[data-theme='light'] .sidebar-nav-item button { color: var(--sidebar-text); }
html[data-theme='light'] .sidebar-nav-item a:hover, html[data-theme='light'] .sidebar-nav-item button:hover { background: var(--sidebar-hover); color: #1a0a2e; }
html[data-theme='light'] .sidebar-nav-item a.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-color); }
html[data-theme='light'] .sidebar-subnav-item { color: rgba(26,10,46,0.6); }
html[data-theme='light'] .sidebar-subnav-item:hover { color: #1a0a2e; }
html[data-theme='light'] .sidebar-subnav-dot { background: rgba(102,51,153,0.2); }
html[data-theme='light'] .sidebar-subnav-add a { border-color: rgba(102,51,153,0.3); color: #663399; }
html[data-theme='light'] .sidebar-subnav-add a:hover { background: rgba(102,51,153,0.06); border-color: #663399; color: #4e2177; }
html[data-theme='light'] .sidebar-nav-item a.active { color: #663399; }
html[data-theme='light'] body { background: var(--bg); color: var(--text); }
html[data-theme='light'] .card { background: var(--surface); border-color: var(--border); }
html[data-theme='light'] .btn { background: var(--accent); color: #fff; }
html[data-theme='light'] .btn:hover { background: var(--accent-hover); }
html[data-theme='light'] .btn.secondary { background: var(--surface-raised); border-color: var(--border); color: var(--text); }
html[data-theme='light'] input, html[data-theme='light'] select, html[data-theme='light'] textarea { background: var(--surface-raised); border-color: var(--border); color: var(--text); }
html[data-theme='light'] label { color: var(--text); }
html[data-theme='light'] h1, html[data-theme='light'] h2, html[data-theme='light'] h3 { color: var(--text); }
