:root {
    --font-display: "Space Grotesk", sans-serif;
    --font-mono: "IBM Plex Mono", monospace;
    --radius-2xl: 34px;
    --radius-xl: 26px;
    --radius-lg: 20px;
    --radius-md: 16px;
    --shadow-panel: 0 30px 80px rgba(0, 0, 0, 0.18);
    --shadow-card: 0 16px 44px rgba(0, 0, 0, 0.14);
    --transition-fast: 180ms ease;
    --transition-slow: 280ms ease;
}

body[data-theme="hacker"] {
    --bg: #06120f;
    --bg-panel: rgba(7, 17, 14, 0.8);
    --bg-card: rgba(6, 13, 11, 0.92);
    --bg-soft: rgba(14, 34, 26, 0.7);
    --line: rgba(86, 255, 170, 0.14);
    --line-strong: rgba(86, 255, 170, 0.28);
    --text: #e4fff0;
    --muted: #8eb9a2;
    --accent: #4cff9c;
    --accent-strong: #10ca69;
    --accent-soft: rgba(76, 255, 156, 0.14);
    --secondary: #79ddff;
    --warning: #ffd25f;
    --danger: #ff6b8d;
    --surface-highlight: linear-gradient(180deg, rgba(76, 255, 156, 0.12), rgba(5, 13, 10, 0));
    --glow-left: rgba(18, 255, 153, 0.26);
    --glow-right: rgba(0, 194, 255, 0.16);
    --button-text: #04130c;
}

body[data-theme="minimal"] {
    --bg: #efe7dc;
    --bg-panel: rgba(253, 249, 243, 0.82);
    --bg-card: rgba(255, 253, 249, 0.95);
    --bg-soft: rgba(242, 235, 225, 0.84);
    --line: rgba(42, 56, 74, 0.08);
    --line-strong: rgba(42, 56, 74, 0.18);
    --text: #1f2430;
    --muted: #67707c;
    --accent: #177d67;
    --accent-strong: #0d6451;
    --accent-soft: rgba(23, 125, 103, 0.1);
    --secondary: #3458d1;
    --warning: #9c6a0d;
    --danger: #bf4e68;
    --surface-highlight: linear-gradient(180deg, rgba(23, 125, 103, 0.08), rgba(255, 255, 255, 0));
    --glow-left: rgba(23, 125, 103, 0.16);
    --glow-right: rgba(52, 88, 209, 0.12);
    --button-text: #f7f4ee;
}

body[data-theme="cyberpunk"] {
    --bg: #0d0221;
    --bg-panel: rgba(18, 4, 48, 0.82);
    --bg-card: rgba(14, 3, 36, 0.94);
    --bg-soft: rgba(30, 8, 68, 0.78);
    --line: rgba(255, 42, 200, 0.16);
    --line-strong: rgba(255, 42, 200, 0.3);
    --text: #f0e6ff;
    --muted: #a088c4;
    --accent: #ff2ac8;
    --accent-strong: #d616a8;
    --accent-soft: rgba(255, 42, 200, 0.14);
    --secondary: #00f0ff;
    --warning: #ffb830;
    --danger: #ff4466;
    --surface-highlight: linear-gradient(180deg, rgba(255, 42, 200, 0.12), rgba(0, 0, 0, 0));
    --glow-left: rgba(255, 42, 200, 0.26);
    --glow-right: rgba(0, 240, 255, 0.18);
    --button-text: #0d0221;
}

body[data-theme="ocean"] {
    --bg: #041220;
    --bg-panel: rgba(6, 22, 42, 0.82);
    --bg-card: rgba(5, 18, 34, 0.94);
    --bg-soft: rgba(10, 36, 62, 0.78);
    --line: rgba(56, 196, 220, 0.16);
    --line-strong: rgba(56, 196, 220, 0.3);
    --text: #e0f4ff;
    --muted: #7db8cc;
    --accent: #38c4dc;
    --accent-strong: #1a9ab6;
    --accent-soft: rgba(56, 196, 220, 0.14);
    --secondary: #6c8cff;
    --warning: #f0c050;
    --danger: #ff6b7a;
    --surface-highlight: linear-gradient(180deg, rgba(56, 196, 220, 0.12), rgba(0, 0, 0, 0));
    --glow-left: rgba(56, 196, 220, 0.26);
    --glow-right: rgba(108, 140, 255, 0.18);
    --button-text: #041220;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
    height: 100%;
    margin: 0;
}

body {
    position: relative;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-display);
}

body.app-locked {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

body.auth-only {
    overflow: hidden;
}

button,
textarea {
    font: inherit;
}

button {
    border: none;
}

.ambient {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.ambient-glow {
    position: absolute;
    border-radius: 999px;
    filter: blur(26px);
}

.glow-left {
    top: -6rem;
    left: -5rem;
    width: 28rem;
    height: 28rem;
    background: var(--glow-left);
}

.glow-right {
    right: -7rem;
    bottom: -8rem;
    width: 24rem;
    height: 24rem;
    background: var(--glow-right);
}

.ambient-noise {
    position: absolute;
    inset: 0;
}

.ambient-noise {
    opacity: 0.32;
    background:
        radial-gradient(circle at 18% 26%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 26%),
        radial-gradient(circle at 80% 78%, color-mix(in srgb, var(--secondary) 8%, transparent), transparent 22%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.012), rgba(0, 0, 0, 0.06));
}

.auth-screen {
    position: relative;
    z-index: 2;
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 32px;
}

.auth-panel {
    width: min(940px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
    gap: 14px;
    padding: 14px;
    border-radius: 30px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
    border-color: color-mix(in srgb, var(--line) 70%, transparent);
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.34);
}

.auth-copy,
.auth-form,
.user-card,
.admin-panel {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
}

.auth-copy,
.auth-form {
    padding: 28px;
}

.auth-copy h1 {
    margin: 0;
    font-size: clamp(3rem, 5vw, 4.8rem);
    line-height: 0.9;
    max-width: 8ch;
    letter-spacing: -0.04em;
}

.auth-copy p,
.auth-message,
.user-role,
.admin-user-meta {
    color: var(--muted);
}

.auth-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 360px;
    position: relative;
    background:
        radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 18%, transparent), transparent 42%),
        radial-gradient(circle at bottom right, color-mix(in srgb, var(--secondary) 12%, transparent), transparent 38%),
        linear-gradient(145deg, rgba(255, 255, 255, 0.012), rgba(255, 255, 255, 0.02)),
        var(--bg-card);
}

.auth-copy::after {
    content: "";
    position: absolute;
    right: -60px;
    bottom: -60px;
    width: 220px;
    height: 220px;
    border-radius: 999px;
    background: radial-gradient(circle, color-mix(in srgb, var(--secondary) 18%, transparent), transparent 66%);
    pointer-events: none;
}

.auth-kicker,
.auth-form-kicker {
    margin: 0 0 14px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.76rem;
    color: var(--accent);
}

.auth-kicker {
    margin-bottom: 18px;
}

.auth-lead {
    max-width: 48ch;
    margin: 16px 0 0;
    font-size: 1.02rem;
    line-height: 1.7;
}

.auth-feature-list {
    display: grid;
    gap: 14px;
    margin-top: 28px;
}

.auth-feature-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
}

.auth-feature-item strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text);
}

.auth-feature-item p {
    margin: 0;
    line-height: 1.55;
}

.auth-feature-dot {
    width: 10px;
    height: 10px;
    margin-top: 8px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 14%, transparent);
}

.auth-form {
    align-content: start;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0.006)),
        color-mix(in srgb, var(--bg-card) 95%, transparent);
}

.auth-form-head {
    margin-bottom: 10px;
}

.auth-form-head h2 {
    margin: 0;
    font-size: 2.25rem;
    line-height: 0.98;
}

.auth-form-head p {
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.65;
    max-width: 28ch;
}

.auth-hint,
.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.auth-form,
.admin-form {
    display: grid;
    gap: 12px;
}

.field-label {
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.76rem;
    color: var(--muted);
}

.field-input {
    width: 100%;
    padding: 15px 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-soft) 78%, transparent);
    color: var(--text);
    outline: none;
}

.field-input:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-button {
    width: 100%;
    margin-top: 8px;
    min-height: 56px;
    box-shadow: 0 14px 30px color-mix(in srgb, var(--accent) 20%, transparent);
}

.auth-message {
    margin: 8px 0 0;
    min-height: 1.3rem;
}

.auth-message.is-error {
    color: var(--danger);
}

.auth-message.is-success {
    color: var(--accent);
}

.layout {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: var(--sidebar-width, 332px) minmax(0, 1fr);
    gap: 24px;
    height: calc(100dvh - 48px);
    min-height: 0;
    padding: 24px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-panel);
    backdrop-filter: blur(24px);
}

.sidebar,
.workspace {
    min-height: 0;
    height: 100%;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 22px;
    padding-right: 14px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    position: sticky;
    top: 0;
    align-self: start;
}

.sidebar > * {
    flex-shrink: 0;
}

.sidebar-mobile-head,
.mobile-menu-button {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--accent-soft);
}

.brand-card,
.card-block,
.hero-card,
.console-card,
.composer-card,
.message-card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
    transition: border-color 220ms ease, background 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.brand-card,
.card-block,
.hero-card,
.console-card,
.composer-card {
    position: relative;
    overflow: hidden;
}

.sidebar .brand-card,
.sidebar .card-block {
    overflow: hidden;
}

.brand-card::before,
.card-block::before,
.hero-card::before,
.console-card::before,
.composer-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--surface-highlight);
    pointer-events: none;
}

.brand-card,
.card-block {
    padding: 18px;
}

.eyebrow,
.card-label,
.prompt-hint,
.message-role,
.message-time,
.console-pill {
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.76rem;
}

.eyebrow,
.card-label,
.prompt-hint,
.message-time {
    color: var(--muted);
}

.brand-card h1,
.hero-card h2,
.empty-state h3 {
    margin: 0;
    line-height: 0.94;
}

.brand-card h1 {
    font-size: clamp(2.8rem, 5vw, 4.3rem);
}

.hero-card h2 {
    font-size: clamp(2rem, 4vw, 3.2rem);
}

.brand-copy,
.hero-copy,
.system-card p,
.theme-desc,
.empty-state p,
.console-info {
    color: var(--muted);
}

.brand-badges,
.quick-prompts,
.theme-options,
.metrics-grid,
.hero-actions,
.console-pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.badge,
.chip,
.console-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
}

.badge,
.console-pill {
    color: var(--text);
}

.chip {
    color: var(--text);
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.chip:hover,
.ghost-button:hover,
.primary-button:hover,
.message-copy:hover {
    transform: translateY(-1px);
}

.chip:hover,
.ghost-button:hover,
.message-copy:hover {
    border-color: var(--line-strong);
    background: var(--accent-soft);
}

.status-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.user-card {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.user-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.user-name {
    margin: 6px 0 4px;
    font-size: 1.3rem;
    font-weight: 700;
}

.user-role {
    margin: 0;
}

.settings-toggle {
    width: 46px;
    height: 46px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.settings-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.18rem;
    transform: translateY(-0.5px);
}

.settings-panel {
    display: grid;
    gap: 14px;
    padding-top: 2px;
}

.settings-group {
    display: grid;
    gap: 8px;
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.settings-actions .ghost-button {
    flex: 1 1 120px;
}

.status-text {
    margin: 6px 0 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.status-text.is-online {
    color: var(--accent);
}

.status-text.is-busy,
.status-text.is-connecting {
    color: var(--warning);
}

.status-text.is-offline,
.status-text.is-error {
    color: var(--danger);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-tile {
    padding: 14px;
    border-radius: var(--radius-lg);
    background: var(--bg-soft);
    border: 1px solid var(--line);
}

.metric-value {
    margin: 10px 0 0;
    font-size: 2rem;
    font-weight: 700;
}

.metric-text {
    font-size: 1rem;
}

.admin-panel {
    display: grid;
    gap: 14px;
}

.history-panel {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 220px;
    flex: 1;
}

.history-panel::before {
    display: none;
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.history-new {
    padding: 8px 12px;
    font-size: 0.9rem;
}

.history-search {
    margin: 4px 0 8px;
    position: relative;
    z-index: 2;
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: auto;
    margin-top: 2px;
    padding-right: 8px;
    padding-bottom: 8px;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.chat-history-list::-webkit-scrollbar {
    width: 8px;
}

.chat-history-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--accent-soft);
}

.history-item {
    width: 100%;
    text-align: left;
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    overflow: hidden;
    flex-shrink: 0;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.history-item:hover,
.history-item.is-active {
    border-color: var(--line-strong);
    background: var(--accent-soft);
}

.history-open {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: inherit;
    display: grid;
    gap: 4px;
    cursor: pointer;
    padding: 0;
}

.history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.history-action {
    padding: 6px 10px;
    font-size: 0.8rem;
    flex: 1 1 92px;
}

.history-title {
    font-weight: 700;
    line-height: 1.2;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-preview,
.history-meta,
.history-empty {
    color: var(--muted);
    font-size: 0.9rem;
}

.history-preview {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.history-empty {
    margin: 0;
    padding: 8px 2px;
}

.admin-user-list {
    display: grid;
    gap: 10px;
}

.admin-user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-soft);
}

.admin-user-name {
    margin: 0 0 4px;
    font-weight: 700;
}

.admin-user-meta {
    margin: 0;
    font-size: 0.9rem;
}

.admin-user-badge {
    white-space: nowrap;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.theme-options {
    display: grid;
}

.theme-select {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    font-family: var(--font-display);
    font-size: 0.98rem;
    outline: none;
}

.theme-select:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.theme-option {
    width: 100%;
    text-align: left;
    padding: 15px;
    border-radius: var(--radius-lg);
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.theme-name {
    display: block;
    margin-bottom: 4px;
    font-weight: 700;
}

.workspace {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 18px;
    padding: 18px;
    overflow: hidden;
}

.hero-card,
.console-card,
.composer-card {
    padding: 18px;
}

.hero-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.hero-left {
    display: flex;
    align-items: center;
}

.hero-actions {
    justify-content: flex-end;
}

.ghost-button,
.primary-button,
.message-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    overflow: hidden;
    background-clip: padding-box;
    cursor: pointer;
    transition: transform 220ms ease, border-color 220ms ease, background 220ms ease, opacity 220ms ease, box-shadow 220ms ease, color 220ms ease;
}

.ghost-button,
.message-copy {
    background: var(--bg-soft);
    color: var(--text);
    text-decoration: none;
}

.primary-button {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--button-text);
    font-weight: 700;
}

.ghost-button:disabled,
.primary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.console-card {
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 16px;
    overflow: hidden;
}

.empty-state {
    padding: 18px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--line-strong);
    background: var(--bg-soft);
}

.empty-state[hidden] {
    display: none;
}

.empty-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.empty-prompts .chip {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.88rem;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.empty-prompts .chip:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.export-dropdown {
    position: relative;
}

.export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    padding: 8px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    display: grid;
    gap: 4px;
    z-index: 10;
    min-width: 160px;
}

.export-option {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 0.88rem;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.export-option:hover {
    background: var(--accent-soft);
    border-color: var(--line);
}

.offline-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    margin-bottom: 10px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, var(--bg-card));
    color: var(--danger);
    font-weight: 500;
}

.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 3;
    transition: background var(--transition-fast);
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.is-dragging {
    background: var(--accent-soft);
}

.empty-kicker {
    margin: 0 0 8px;
    color: var(--accent);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.76rem;
}

.chat-feed {
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 6px 10px 2px;
}

.chat-feed::-webkit-scrollbar {
    width: 10px;
}

.chat-feed::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--accent-soft);
}

.message-card {
    max-width: min(86ch, 92%);
    padding: 14px 16px;
    animation: rise-in var(--transition-slow) both;
    transform-origin: left bottom;
    transition: max-width 420ms cubic-bezier(0.22, 1, 0.36, 1), min-width 420ms cubic-bezier(0.22, 1, 0.36, 1), border-color 240ms ease, background 240ms ease, box-shadow 240ms ease, transform 240ms ease;
}

.message-card.is-pending {
    min-width: min(320px, calc(100% - 12px));
    max-width: min(420px, 92%);
}

.message-card.is-resolving {
    transform: scale(0.985);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.message-card.is-expanding {
    min-width: 0;
    max-width: min(86ch, 92%);
}

.message-card.is-resolved {
    animation: settle-in 320ms ease both;
}

.message-card[data-role="assistant"] {
    align-self: flex-start;
    border-color: color-mix(in srgb, var(--accent) 24%, var(--line));
}

.message-card[data-role="user"] {
    align-self: flex-end;
    background: linear-gradient(180deg, color-mix(in srgb, var(--secondary) 10%, transparent), var(--bg-card));
    border-color: color-mix(in srgb, var(--secondary) 24%, var(--line));
}

.message-card[data-role="system"] {
    align-self: center;
    max-width: 70ch;
    background: linear-gradient(180deg, var(--accent-soft), var(--bg-card));
}

.message-body {
    white-space: normal;
    word-break: break-word;
    line-height: 1.68;
    overflow: hidden;
    transition: opacity 180ms ease, transform 220ms ease, height 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.message-card.is-resolving .message-body {
    opacity: 1;
    transform: translateY(0);
}

.message-card.is-resolved .message-body {
    opacity: 1;
    transform: translateY(0);
}

.message-body p {
    margin: 0;
}

.message-body p + p,
.message-body p + ul,
.message-body ul + p,
.message-body ul + ul {
    margin-top: 12px;
}

.message-body ul {
    margin: 0;
    padding-left: 1.1rem;
}

.message-body li + li {
    margin-top: 6px;
}

.message-body strong {
    color: var(--text);
    font-weight: 700;
}

.message-card.is-pending .message-body {
    display: flex;
}

.pending-shell {
    display: grid;
    width: 100%;
}

.thinking-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 28px;
    max-width: 100%;
    transition: opacity 180ms ease, transform 220ms ease, max-height 320ms ease, margin 320ms ease;
    max-height: 48px;
}

.message-card.is-expanding .thinking-pill {
    opacity: 0;
    transform: translateY(-2px) scale(0.985);
    max-height: 0;
    margin: 0;
}

.thinking-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
    animation: pulse 1s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 120ms;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 240ms;
}

.thinking-label {
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    max-width: 0;
    animation: reveal-thinking 700ms ease forwards 120ms;
}

.message-card.is-expanding .thinking-label {
    animation: none;
    max-width: 0;
}

.pending-response {
    opacity: 0;
    transform: translateY(8px);
    max-height: 0;
    overflow: hidden;
    transition: opacity 260ms ease 100ms, transform 320ms ease 100ms, max-height 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.message-card.is-expanding .pending-response {
    opacity: 1;
    transform: translateY(0);
    max-height: 1200px;
}

.message-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 2px 6px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
    border: 1px solid var(--line);
}

.message-body .code-block {
    margin: 0;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-soft) 82%, transparent);
    overflow-x: auto;
}

.message-body .code-block + p,
.message-body p + .code-block,
.message-body .code-block + ul,
.message-body ul + .code-block,
.message-body .code-block + .code-block {
    margin-top: 12px;
}

.message-body .code-block code {
    display: block;
    border: none;
    background: transparent;
    padding: 0;
    white-space: pre;
    line-height: 1.55;
    font-size: 0.88rem;
}

.message-body .code-block[data-lang]::before {
    content: attr(data-lang);
    display: inline-block;
    margin-bottom: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.message-body blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    border-left: 3px solid var(--accent);
    background: var(--bg-soft);
    border-radius: 0 12px 12px 0;
    color: var(--muted);
}

.message-body hr {
    border: none;
    height: 1px;
    background: var(--line-strong);
    margin: 16px 0;
}

.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.94rem;
}

.message-body th,
.message-body td {
    padding: 8px 12px;
    border: 1px solid var(--line);
    text-align: left;
}

.message-body th {
    background: var(--bg-soft);
    font-weight: 700;
}

.message-body del {
    text-decoration: line-through;
    opacity: 0.7;
}

.typing-indicator {
    display: none !important;
}

.typing-indicator[hidden] {
    display: none !important;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
    animation: pulse 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 120ms;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 240ms;
}

.typing-indicator p {
    margin: 0 0 0 4px;
    color: var(--muted);
    line-height: 1;
}

.composer-card {
    position: sticky;
    bottom: 0;
    z-index: 2;
}

.composer-shell {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 0;
}

.composer-input-wrap {
    display: flex;
    align-items: flex-end;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 68px;
    padding: 0 18px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--bg-soft) 94%, transparent), color-mix(in srgb, var(--bg-card) 88%, transparent)),
        var(--bg-soft);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.composer-input-wrap:focus-within {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

#messageInput {
    width: 100%;
    min-width: 0;
    min-height: 64px;
    max-height: 220px;
    padding: 18px 0 14px;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    line-height: 1.6;
}

#messageInput::placeholder {
    color: color-mix(in srgb, var(--muted) 88%, transparent);
}

#sendButton,
.attach-button {
    flex-shrink: 0;
}

#sendButton {
    min-width: 118px;
    min-height: 68px;
    padding: 0 22px;
    border-radius: 22px;
    box-shadow: 0 18px 34px color-mix(in srgb, var(--accent) 26%, transparent);
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes reveal-thinking {
    from {
        max-width: 0;
        opacity: 0.45;
    }
    to {
        max-width: 240px;
        opacity: 1;
    }
}

@keyframes settle-in {
    from {
        opacity: 0.72;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1160px) {
    body {
        overflow: hidden;
        overflow-x: hidden;
    }

    body.auth-only {
        overflow: auto;
    }

    .auth-panel {
        grid-template-columns: 1fr;
    }

    .auth-copy {
        min-height: auto;
        justify-content: flex-start;
    }

    .layout {
        grid-template-columns: 1fr;
        height: calc(100dvh - 24px);
        min-height: 0;
    }

    .sidebar-resize-handle {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: 12px;
        left: 12px;
        bottom: 12px;
        width: min(84vw, 360px);
        max-height: none;
        z-index: 42;
        transform: translateX(calc(-100% - 24px));
        opacity: 0;
        pointer-events: none;
        transition: transform var(--transition-slow), opacity var(--transition-fast);
    }

    .sidebar-mobile-head {
        display: flex;
        justify-content: flex-end;
    }

    .sidebar-close {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .mobile-menu-button {
        display: none;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 40;
        background: rgba(0, 0, 0, 0.42);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-fast);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .workspace {
        min-height: 0;
        height: 100%;
        grid-template-rows: auto minmax(0, 1fr) auto;
        overflow: hidden;
    }

    .console-card {
        min-height: 0;
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    .chat-feed {
        overscroll-behavior: contain;
    }

    .composer-shell {
        align-items: flex-end;
    }

    .composer-input-wrap {
        min-height: 60px;
        padding: 0 16px;
    }

    #messageInput {
        min-height: 56px;
        padding: 14px 0 10px;
    }
}

@media (max-width: 720px) {
    .layout {
        padding: 0;
        gap: 0;
        height: 100dvh;
    }

    .auth-screen {
        padding: 0;
        min-height: 100dvh;
    }

    .auth-panel {
        padding: 12px;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }

    .auth-copy,
    .auth-form {
        padding: 20px;
    }

    .auth-copy h1 {
        max-width: none;
        font-size: clamp(2.4rem, 10vw, 3.5rem);
    }

    .sidebar,
    .workspace {
        padding: calc(12px + env(safe-area-inset-top))
            calc(12px + env(safe-area-inset-right))
            calc(12px + env(safe-area-inset-bottom))
            calc(12px + env(safe-area-inset-left));
        border-radius: 0;
    }

    .sidebar {
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: min(88vw, 360px);
    }

    .sidebar.panel,
    .workspace.panel {
        border-radius: 0;
        box-shadow: none;
        border: none;
        backdrop-filter: none;
    }

    .settings-toggle {
        width: 42px;
        height: 42px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .workspace {
        gap: 10px;
    }

    .hero-card {
        padding: 10px 12px;
        border-radius: 18px;
        gap: 8px;
    }

    .hero-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }

    .mobile-menu-button,
    .hero-actions .ghost-button {
        padding: 6px 10px;
        font-size: 0.78rem;
        line-height: 1;
    }

    .mobile-menu-button {
        display: inline-flex;
    }

    .console-card {
        gap: 10px;
        padding: 12px;
        border-radius: 18px;
    }

    .composer-card {
        padding: 10px;
        border-radius: 18px;
    }

    .composer-shell {
        display: flex;
        align-items: flex-end;
        gap: 10px;
        padding: 0;
    }

    .composer-input-wrap {
        min-height: 52px;
        padding: 0 14px;
        border-radius: 18px;
    }

    #messageInput {
        min-height: 48px;
        max-height: 120px;
        padding: 12px 0 10px;
        font-size: 16px;
        line-height: 1.45;
    }

    .field-input,
    #messageInput,
    #historySearchInput {
        font-size: 16px;
    }

    #sendButton {
        min-width: 88px;
        min-height: 52px;
        padding: 0 16px;
        font-size: 0.92rem;
        border-radius: 18px;
    }

    .message-card {
        max-width: 100%;
    }

    .chat-history-list {
        gap: 10px;
        padding-right: 6px;
    }

    .history-item {
        padding: 11px 12px;
        border-radius: 14px;
    }

    .history-title {
        font-size: 1.08rem;
    }

    .history-preview,
    .history-meta {
        display: none;
    }

    .history-actions {
        margin-top: 8px;
    }
}

/* ── Section Navigation ─────────────────────────────────────────── */

.section-nav {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
}

.section-tab {
    padding: 8px 18px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: all var(--transition-fast);
}

.section-tab:hover {
    color: var(--text);
}

.section-tab.is-active {
    background: var(--accent-soft);
    border-color: var(--line-strong);
    color: var(--accent);
}

/* ── File Attachments ───────────────────────────────────────────── */

.attach-button {
    width: 56px;
    height: 56px;
    padding: 0;
    font-size: 1.2rem;
    flex-shrink: 0;
    border-radius: 18px;
    background: color-mix(in srgb, var(--bg-soft) 92%, transparent);
}

.attachment-area {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 14px 0;
}

.attachment-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    font-size: 0.88rem;
    animation: rise-in var(--transition-slow) both;
}

.attachment-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-size {
    color: var(--muted);
    font-size: 0.78rem;
    font-family: var(--font-mono);
}

.attachment-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 0 2px;
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.attachment-remove:hover {
    opacity: 1;
}

@media (max-width: 720px) {
    .section-nav {
        padding: 3px;
    }

    .section-tab {
        padding: 6px 12px;
        font-size: 0.74rem;
    }

    .attach-button {
        width: 52px;
        height: 52px;
        border-radius: 16px;
        font-size: 1rem;
    }
}

/* ── Token Quota Sidebar ───────────────────────────────────────── */

.token-quota-card {
    border-top: 1px solid var(--line);
}

.token-quota-card .section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.token-display {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 6px 0 8px;
}

.token-balance-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--accent);
    line-height: 1;
}

.token-balance-label {
    font-size: 0.78rem;
    color: var(--muted);
}

.token-progress-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--bg-soft);
    overflow: hidden;
    margin-bottom: 6px;
}

.token-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease, background 0.3s ease;
    background: var(--accent);
}

.token-progress-fill.green  { background: #22c55e; }
.token-progress-fill.yellow { background: #f59e0b; }
.token-progress-fill.red    { background: #ef4444; }

.token-badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.token-badge.unlimited {
    background: rgba(168,85,247,0.12);
    color: #a855f7;
    border: 1px solid #a855f7;
}
.token-badge.active {
    background: rgba(34,197,94,0.12);
    color: #22c55e;
    border: 1px solid #22c55e;
}
.token-badge.low {
    background: rgba(245,158,11,0.12);
    color: #f59e0b;
    border: 1px solid #f59e0b;
}
.token-badge.exhausted {
    background: rgba(239,68,68,0.12);
    color: #ef4444;
    border: 1px solid #ef4444;
}

.token-warning {
    font-size: 0.78rem;
    color: #ef4444;
    margin-top: 4px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.2);
}

.composer-blocked {
    opacity: 0.5;
    pointer-events: none;
}

.quota-block-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    margin-bottom: 8px;
    border-radius: 14px;
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.2);
    color: #ef4444;
    font-size: 0.88rem;
    font-weight: 500;
}