:root {
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 72px;
    --primary-blue: #2c5282;
    --bg-light: #f7fafc;
    --text-dark: #2d3748;
    --agent-gray: #edf2f7;
    --user-blue: #ebf8ff;
    --surface: #ffffff;
    --border-light: #e2e8f0;
    --muted-text: #718096;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100vh;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
}

#app-root {
    display: flex;
    height: 100vh;
    min-height: 100vh;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 30px;
}

.header-left {
    display: flex;
    align-items: center;
}

.chat-session-wrap {
    position: relative;
}

.chat-session-toggle {
    border: 1px solid #cbd5e0;
    background: #ffffff;
    color: #1f2937;
    border-radius: 10px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chat-session-toggle.is-open {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.22);
}

.chat-session-popover {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 360px;
    max-height: 420px;
    border: 1px solid #dbe3ec;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 14px 38px rgba(15, 23, 42, 0.18);
    padding: 10px;
    display: none;
    z-index: 40;
}

.chat-session-popover.open {
    display: block;
}

.chat-session-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 2px 8px;
    font-size: 13px;
    font-weight: 700;
}

.chat-session-new-btn {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.chat-session-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 350px;
    overflow-y: auto;
}

.chat-session-item {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fbff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px;
    gap: 6px;
}

.chat-session-item.active {
    border-color: #93c5fd;
    background: #eff6ff;
}

.chat-session-item-main {
    flex: 1;
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 6px 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.chat-session-item-main.active {
    background: #e0edff;
}

.chat-session-item-content {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    text-align: left;
    cursor: pointer;
}

.chat-session-item-title {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
}

.chat-session-item-meta {
    font-size: 11px;
    color: #64748b;
}

.chat-session-item-more {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.chat-session-item-more:hover {
    background: #e2e8f0;
}

.chat-session-item-summary {
    font-size: 12px;
    color: #334155;
}

.chat-session-empty {
    font-size: 12px;
    color: #64748b;
    padding: 10px 4px;
}

.chat-session-context-menu {
    position: fixed;
    min-width: 160px;
    border: 1px solid #dbe3ec;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 4px;
    z-index: 70;
}

.chat-session-context-item {
    width: 100%;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #0f172a;
    text-align: left;
    font-size: 13px;
    padding: 7px 10px;
    cursor: pointer;
}

.chat-session-context-item:hover {
    background: #eff6ff;
}

.chat-session-context-item.danger {
    color: #dc2626;
}

.chat-session-context-item.danger:hover {
    background: #fee2e2;
}

.chat-session-context-item.disabled {
    color: #94a3b8;
    cursor: not-allowed;
}

body.theme-dark .chat-session-context-menu {
    border-color: #334155;
    background: #111827;
}

body.theme-dark .chat-session-context-item {
    color: #e2e8f0;
}

body.theme-dark .chat-session-context-item:hover {
    background: #1e293b;
}

body.theme-dark .chat-session-context-item.danger {
    color: #fca5a5;
}

body.theme-dark .chat-session-context-item.danger:hover {
    background: #7f1d1d;
}

body.theme-dark .chat-session-context-item.disabled {
    color: #64748b;
}

body.theme-dark .chat-session-item-main.active {
    background: #1e3a5f;
}

body.theme-dark .chat-session-item-more {
    color: #cbd5e1;
}

body.theme-dark .chat-session-item-more:hover {
    background: #334155;
}

#module-title {
    display: block;
    max-width: min(70vw, 800px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    justify-self: center;
    text-align: center;
}

.header-right {
    display: flex;
    align-items: center;
    justify-self: end;
}

.chat-side-toggle-btn {
    width: 34px;
    height: 34px;
    border: 1px solid #cbd5e0;
    border-radius: 10px;
    background: #ffffff;
    color: #1f2937;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.chat-section {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.module-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-mode .footer {
    display: none;
}

.welcome-mode .sidebar {
    display: none;
}

.welcome-mode header {
    display: none;
}

.welcome-mode .chat-section {
    display: none;
}

.welcome-mode .welcome-view {
    display: block;
}

.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-light);
    padding: 12px 30px;
    font-size: 12px;
    color: var(--muted-text);
}

.footer-inner {
    max-width: 1000px;
    margin: 0 auto;
    text-align: center;
    line-height: 1.6;
}

.btn-primary {
    border: none;
    background: var(--primary-blue);
    color: white;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

.btn-secondary {
    border: 1px solid #cbd5e0;
    background: var(--surface);
    color: #2d3748;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
}

body.theme-dark {
    --bg-light: #0f172a;
    --text-dark: #e2e8f0;
    --agent-gray: #1e293b;
    --user-blue: #1e3a5f;
    --surface: #111827;
    --border-light: #334155;
    --muted-text: #94a3b8;
}

body.theme-dark .btn-secondary {
    color: #e2e8f0;
    border-color: #475569;
}

body.theme-dark .chat-side-toggle-btn {
    background: #1f2937;
    color: #e2e8f0;
    border-color: #475569;
}

body.theme-dark .chat-session-toggle {
    background: #1f2937;
    color: #e2e8f0;
    border-color: #475569;
}

body.theme-dark .chat-session-popover {
    background: #111827;
    border-color: #334155;
}

body.theme-dark .chat-session-new-btn {
    background: #1e3a8a;
    border-color: #3b82f6;
    color: #dbeafe;
}

body.theme-dark .chat-session-item {
    background: #0f172a;
    border-color: #334155;
}

body.theme-dark .chat-session-item.active {
    background: #1d4f91;
    border-color: #60a5fa;
}

body.theme-dark .chat-session-item-title {
    color: #e2e8f0;
}

body.theme-dark .chat-session-item-meta,
body.theme-dark .chat-session-empty {
    color: #94a3b8;
}

body.theme-dark .chat-session-item-summary {
    color: #cbd5e1;
}

@media (max-width: 768px) {
    body {
        position: relative;
    }

    header {
        position: relative;
        padding: 0 14px;
    }

    .chat-mode header {
        padding-left: 58px;
    }

    #module-title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100vw - 170px);
        max-width: calc(100vw - 170px);
        z-index: 1;
    }

    .header-right {
        position: absolute;
        right: 14px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 2;
    }

    .chat-side-toggle-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
}
