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

:root {
    --bg: #111111;
    --nav-bg: #161616;
    --card-bg: #1c1c1c;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-muted: #888;
    --accent: #4f8ef7;
    --flash-bg: #2a1f1f;
    --flash-border: #5a2a2a;
    --flash-text: #e88;
}

html[data-theme="light"] {
    --bg: #f6f6f6;
    --nav-bg: #ffffff;
    --card-bg: #ffffff;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-muted: #666666;
    --accent: #2b6fe0;
    --flash-bg: #fff3f3;
    --flash-border: #fca5a5;
    --flash-text: #b91c1c;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

nav {
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-brand svg {
    display: block;
    flex-shrink: 0;
}

.nav-brand-text {
    font-size: 17px;
    letter-spacing: -0.3px;
    color: var(--text);
    line-height: 1;
}

.nav-brand-text strong {
    font-weight: 700;
}

.nav-brand-light {
    font-weight: 400;
    opacity: 0.55;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 24px;
}

.hero {
    padding: 60px 0 40px;
}

.hero h1 {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 12px;
}

.hero .subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

input, select {
    color-scheme: dark;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
}

html[data-theme="light"] input,
html[data-theme="light"] select {
    color-scheme: light;
}

/* Unauthenticated nav (sign in + theme toggle) */
.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Portal shortcut links (desktop center) */
.nav-portals {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    justify-content: flex-end;
    padding-right: 8px;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 9px;
    border-radius: 5px;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
    background: none;
    border: none;
    cursor: pointer;
}

.nav-link:hover {
    color: var(--text);
    background: var(--border);
}

.nav-link-admin {
    color: var(--accent);
    font-weight: 600;
}

.nav-search {
    display: flex;
    align-items: center;
    margin-right: 4px;
}

.nav-search input {
    padding: 5px 10px;
    font-size: 0.82rem;
    border-radius: 5px;
    width: 160px;
    color-scheme: dark;
}

/* User avatar dropdown */
.nav-user {
    position: relative;
    flex-shrink: 0;
}

.nav-user-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 4px 8px 4px 4px;
    cursor: pointer;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
}

.nav-user-btn:hover {
    background: var(--border);
    border-color: var(--border);
}

.nav-avatar {
    border-radius: 50%;
    display: block;
    flex-shrink: 0;
    background: var(--border);
}

.nav-username {
    font-size: 0.85rem;
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.15s;
}

.nav-user-btn[aria-expanded="true"] .nav-chevron {
    transform: rotate(180deg);
}

/* Dropdown panel */
.nav-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 230px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    z-index: 200;
    overflow: hidden;
}

.nav-dropdown[hidden] { display: none !important; }

.nav-dd-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
}

.nav-dd-avatar {
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--border);
}

.nav-dd-identity { min-width: 0; }

.nav-dd-name {
    font-size: 0.88rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-dd-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-dd-sep {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.nav-dd-section {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 8px 16px 4px;
}

.nav-dd-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--text);
    text-decoration: none;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
    box-sizing: border-box;
}

.nav-dd-item:hover {
    background: var(--border);
}

.nav-dd-signout {
    color: var(--text-muted);
    margin-bottom: 4px;
}

.nav-dd-signout:hover {
    color: var(--text);
}

/* Mobile panel (revealed by hamburger) */
.nav-mobile {
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-mobile[hidden] { display: none !important; }

.nav-search-full {
    width: 100%;
    margin-bottom: 4px;
}

.nav-search-full input {
    width: 100%;
}

.nav-mobile-section {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 10px 4px 2px;
}

.nav-mobile .nav-link {
    width: 100%;
    padding: 9px 4px;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
}

/* Hamburger (mobile only) */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    margin-left: 8px;
}

.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 2px;
    transition: background 0.15s;
}

.nav-hamburger:hover span { background: var(--text); }

@media (max-width: 768px) {
    nav {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 16px;
        gap: 8px;
    }

    .nav-portals { display: none; }
    .nav-user { display: none; }
    .nav-hamburger { display: flex; }

    .nav-search input { color-scheme: dark; }
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: color 0.15s;
}

.theme-toggle:hover {
    color: var(--text);
}

/* Impersonation banner */
.impersonate-bar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: #7c4a00;
    color: #ffe8b0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 18px;
    font-size: 0.83rem;
    gap: 12px;
}

.impersonate-bar-label {
    display: flex;
    align-items: center;
    gap: 7px;
}

.impersonate-bar-role {
    background: rgba(0,0,0,0.25);
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
}

.impersonate-bar-exit {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,220,100,0.35);
    color: #ffe8b0;
    border-radius: 5px;
    padding: 3px 12px;
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.impersonate-bar-exit:hover {
    background: rgba(0,0,0,0.5);
}
