:root {
    --bg: #f2f4f7;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #101828;
    --muted: #667085;
    --line: #d0d5dd;
    --header-bg: #ffffff;
    --sidebar-bg: #f7f9fc;
    --brand-primary: #9b0000;
    --brand-primary-dark: #7a0000;
    --sidebar-active-start: #bd0f0f;
    --sidebar-active-end: #9b0000;
    --primary: #9b0000;
    --primary-dark: #7a0000;
    --success: #067647;
    --warning: #b54708;
    --danger: #b42318;
    --shadow-sm: 0 4px 14px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 10px 32px rgba(16, 24, 40, 0.1);
    --header-h: 74px;
    --sidebar-w: 284px;
    --sidebar-w-collapsed: 84px;
    --radius-md: 12px;
    --radius-lg: 18px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Manrope', 'Segoe UI', Tahoma, sans-serif;
}

html.theme-dark,
body.theme-dark {
    --bg: #0b1220;
    --surface: #101828;
    --surface-soft: #182230;
    --text: #eaecf0;
    --muted: #98a2b3;
    --line: #344054;
    --header-bg: #0f172a;
    --sidebar-bg: #0d1527;
    --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 32px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
}

.flash-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    width: min(380px, 90vw);
    z-index: 120;
    display: grid;
    gap: 10px;
}

.flash {
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    padding: 12px 14px;
    font-size: 0.92rem;
    font-weight: 600;
    color: #1d2939;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.flash-success {
    border-color: #a6f4c5;
    background: #ecfdf3;
}

.flash-error {
    border-color: #fecdca;
    background: #fef3f2;
}

.flash-info {
    border-color: #b2ddff;
    background: #eff8ff;
}

.flash-close {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: #475467;
}

.layout-panel .panel-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    height: var(--header-h);
    border-bottom: 1px solid var(--line);
    background: var(--header-bg);
    box-shadow: var(--shadow-sm);
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #fff;
    display: grid;
    place-items: center;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-badge {
    min-width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
    color: #fff;
    font-weight: 800;
    font-size: 0.95rem;
    display: grid;
    place-items: center;
    padding: 0 10px;
}

.brand-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.brand-copy strong {
    font-family: 'Sora', 'Manrope', sans-serif;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-copy span {
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: #344054;
    cursor: pointer;
    display: grid;
    place-items: center;
    position: relative;
    transition: all 0.18s ease;
}

.icon-button:hover {
    transform: translateY(-1px);
    background: #eef2f6;
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

.sidebar-toggle-desktop.is-collapsed svg {
    transform: scaleX(-1);
}

#themeToggle [data-theme-icon='light'] {
    display: none;
}

html.theme-dark #themeToggle [data-theme-icon='dark'],
body.theme-dark #themeToggle [data-theme-icon='dark'] {
    display: none;
}

html.theme-dark #themeToggle [data-theme-icon='light'],
body.theme-dark #themeToggle [data-theme-icon='light'] {
    display: block;
}

.icon-button .dot-alert {
    position: absolute;
    min-width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #f04438;
    right: 5px;
    top: 4px;
    border: 1px solid #fff;
    padding: 0 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.61rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

.menu-mobile {
    display: none;
}

.user-dropdown {
    position: relative;
    margin-left: 4px;
}

.user-trigger {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-soft);
    padding: 4px 9px 4px 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    min-width: 0;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
    color: #fff;
    font-size: 0.77rem;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.user-copy {
    display: grid;
    text-align: left;
    min-width: 0;
}

.user-copy strong {
    font-size: 0.83rem;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-copy small {
    font-size: 0.72rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-trigger .caret {
    color: #667085;
    font-size: 0.75rem;
}

.user-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 268px;
    border-radius: 13px;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: var(--shadow-md);
    padding: 0;
    display: none;
    z-index: 70;
    overflow: hidden;
}

.user-menu.open {
    display: block;
}

.user-menu-title {
    padding: 11px 14px;
    font-size: 0.88rem;
    font-weight: 700;
    color: #344054;
    border-bottom: 1px solid #eaecf0;
}

.user-menu-profile {
    padding: 12px 14px;
    border-bottom: 1px solid #eaecf0;
    display: grid;
    gap: 2px;
}

.user-menu-profile strong {
    font-size: 0.93rem;
    color: #101828;
}

.user-menu-role {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    border-radius: 999px;
    background: #eef4ff;
    color: #295fe0;
    padding: 2px 8px;
    font-size: 0.73rem;
    font-weight: 700;
}

.user-menu-profile small {
    font-size: 0.78rem;
    color: #667085;
}

.user-menu-actions {
    padding: 8px 6px;
    display: grid;
    gap: 2px;
}

.user-menu-footer {
    border-top: 1px solid #eaecf0;
    padding: 8px 6px;
}

.user-menu-item {
    padding: 9px 10px;
    border-radius: 9px;
    font-size: 0.89rem;
    font-weight: 600;
    color: #344054;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    width: 100%;
}

.user-menu-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: #667085;
}

.user-menu-item:hover {
    background: #f2f4f7;
}

.user-menu-item.danger {
    color: #b42318;
}

.user-menu-item.danger svg {
    color: #d92d20;
}

.panel-workspace {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: calc(100vh - var(--header-h));
}

.app-sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--line);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    overflow-x: visible;
}

.sidebar-brand {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    padding: 10px;
}

.sidebar-heading {
    padding: 8px 6px 2px;
    display: grid;
    gap: 2px;
}

.sidebar-heading strong {
    font-size: 1.05rem;
    line-height: 1.2;
}

.sidebar-heading small {
    color: var(--muted);
    font-size: 0.78rem;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.nav-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 10px;
    align-items: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 10px;
    color: #344054;
    transition: all 0.18s ease;
}

.nav-item:hover {
    background: #edf2f7;
    border-color: #e4e7ec;
}

.nav-item.active {
    background: linear-gradient(135deg, var(--sidebar-active-start), var(--sidebar-active-end));
    color: #fff;
    box-shadow: 0 10px 20px rgba(155, 0, 0, 0.18);
}

.nav-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.15);
    display: grid;
    place-items: center;
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.4px;
}

.nav-item:not(.active) .nav-icon {
    border: 1px solid #d0d5dd;
    background: #fff;
    color: #475467;
}

.nav-icon svg {
    width: 17px;
    height: 17px;
}

.nav-copy {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.nav-copy strong {
    font-size: 0.95rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-copy small {
    font-size: 0.78rem;
    line-height: 1.2;
    opacity: 0.9;
}

.nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #fff;
}

.sidebar-mode-card {
    margin-top: auto;
    border-radius: 12px;
    border: 1px solid #e9d7d7;
    background: #fef2f2;
    padding: 12px;
    display: grid;
    gap: 3px;
}

.sidebar-mode-card strong {
    color: var(--danger);
    font-size: 0.86rem;
}

.sidebar-mode-card small {
    color: #7a271a;
    font-size: 0.75rem;
}

@media (min-width: 981px) {
    body.sidebar-collapsed .panel-workspace {
        grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
    }

    body.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-w-collapsed);
        padding-inline: 10px;
        transition: width 0.2s ease, box-shadow 0.2s ease;
        z-index: 50;
    }

    body.sidebar-collapsed .app-sidebar:hover {
        width: var(--sidebar-w);
        box-shadow: var(--shadow-md);
    }

    body.sidebar-collapsed .sidebar-brand {
        padding: 8px;
    }

    body.sidebar-collapsed .sidebar-brand img {
        width: 100%;
        max-height: 30px;
        object-fit: contain;
    }

    body.sidebar-collapsed .sidebar-heading,
    body.sidebar-collapsed .sidebar-mode-card,
    body.sidebar-collapsed .nav-copy,
    body.sidebar-collapsed .nav-dot {
        display: none;
    }

    body.sidebar-collapsed .nav-item {
        grid-template-columns: 32px;
        justify-content: center;
        padding-inline: 8px;
    }

    body.sidebar-collapsed .app-sidebar:hover .sidebar-heading {
        display: grid;
        padding: 8px 6px 2px;
    }

    body.sidebar-collapsed .app-sidebar:hover .sidebar-mode-card {
        display: grid;
    }

    body.sidebar-collapsed .app-sidebar:hover .nav-item {
        grid-template-columns: 32px minmax(0, 1fr) 10px;
        justify-content: stretch;
        padding: 10px;
    }

    body.sidebar-collapsed .app-sidebar:hover .nav-copy {
        display: grid;
    }

    body.sidebar-collapsed .app-sidebar:hover .nav-dot {
        display: block;
    }
}

html.theme-dark .flash,
body.theme-dark .flash {
    background: #111b2e;
    border-color: #344054;
    color: #eaecf0;
}

html.theme-dark .flash-success,
body.theme-dark .flash-success {
    background: #052e1a;
    border-color: #166534;
}

html.theme-dark .flash-error,
body.theme-dark .flash-error {
    background: #3f1113;
    border-color: #7a271a;
}

html.theme-dark .flash-info,
body.theme-dark .flash-info {
    background: #102a43;
    border-color: #1d4f91;
}

html.theme-dark .brand-mark,
html.theme-dark .sidebar-brand,
html.theme-dark .user-trigger,
html.theme-dark .icon-button,
html.theme-dark .user-menu,
html.theme-dark .nav-item:not(.active) .nav-icon,
body.theme-dark .brand-mark,
body.theme-dark .sidebar-brand,
body.theme-dark .user-trigger,
body.theme-dark .icon-button,
body.theme-dark .user-menu,
body.theme-dark .nav-item:not(.active) .nav-icon {
    background: #111b2e;
    border-color: #344054;
    color: #d0d5dd;
}

html.theme-dark .icon-button:hover,
body.theme-dark .icon-button:hover {
    background: #1f2937;
}

html.theme-dark .user-menu-title,
html.theme-dark .user-menu-profile strong,
html.theme-dark .user-menu-item,
body.theme-dark .user-menu-title,
body.theme-dark .user-menu-profile strong,
body.theme-dark .user-menu-item {
    color: #d0d5dd;
}

html.theme-dark .user-menu-profile small,
body.theme-dark .user-menu-profile small {
    color: #98a2b3;
}

html.theme-dark .user-menu-title,
html.theme-dark .user-menu-profile,
html.theme-dark .user-menu-footer,
body.theme-dark .user-menu-title,
body.theme-dark .user-menu-profile,
body.theme-dark .user-menu-footer {
    border-color: #344054;
}

html.theme-dark .user-menu-role,
body.theme-dark .user-menu-role {
    background: #1d4f91;
    color: #dbeafe;
}

html.theme-dark .user-menu-item svg,
body.theme-dark .user-menu-item svg {
    color: #98a2b3;
}

html.theme-dark .user-menu-item:hover,
body.theme-dark .user-menu-item:hover {
    background: #1f2937;
}

html.theme-dark .user-menu-item.danger,
body.theme-dark .user-menu-item.danger {
    color: #fda29b;
}

html.theme-dark .user-menu-item.danger svg,
body.theme-dark .user-menu-item.danger svg {
    color: #f97066;
}

html.theme-dark .nav-item:hover,
body.theme-dark .nav-item:hover {
    background: #182230;
    border-color: #344054;
}

html.theme-dark .sidebar-mode-card,
body.theme-dark .sidebar-mode-card {
    background: rgba(180, 35, 24, 0.16);
    border-color: rgba(254, 205, 202, 0.28);
}

.panel-main {
    padding: 18px;
    display: grid;
    gap: 18px;
    align-content: start;
    min-width: 0;
    overflow-x: hidden;
}

.assistant-fab {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 80;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
    color: #fff;
    box-shadow: 0 12px 24px rgba(16, 24, 40, 0.24);
    padding: 7px 12px 7px 8px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.83rem;
    font-weight: 700;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.assistant-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px rgba(16, 24, 40, 0.28);
}

.assistant-fab.active {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55), 0 12px 24px rgba(16, 24, 40, 0.24);
}

.assistant-fab-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.28);
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.12);
}

.assistant-fab-icon svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 1180px) {
    .brand-copy span {
        display: none;
    }

    .panel-workspace {
        grid-template-columns: 255px minmax(0, 1fr);
    }
}

@media (max-width: 980px) {
    .sidebar-toggle-desktop {
        display: none;
    }

    .menu-mobile {
        display: grid;
    }

    .panel-workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .app-sidebar {
        position: fixed;
        left: -100%;
        top: var(--header-h);
        width: min(86vw, 320px);
        height: calc(100vh - var(--header-h));
        z-index: 55;
        transition: left 0.2s ease;
    }

    body.sidebar-open .app-sidebar {
        left: 0;
    }

    .user-copy {
        display: none;
    }
}

@media (max-width: 720px) {
    .app-header {
        padding-inline: 10px;
    }

    .user-menu {
        min-width: min(280px, calc(100vw - 16px));
    }

    .brand-copy strong {
        font-size: 0.85rem;
        max-width: 145px;
    }

    .brand-badge {
        min-width: 34px;
        height: 34px;
        font-size: 0.84rem;
        padding: 0 8px;
    }

    .icon-button {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    .icon-button svg {
        width: 16px;
        height: 16px;
    }

    .panel-main {
        padding: 12px;
        gap: 12px;
    }

    .assistant-fab {
        right: 12px;
        bottom: 12px;
        padding-right: 10px;
    }

    .assistant-fab-text {
        display: none;
    }
}
