:root {
    color-scheme: light;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --background: #f5f7fb;
    --surface: #ffffff;
    --surface-alt: #eef2ff;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #d6deff;
    --shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
    --assistant-bg: #e2e8f0;
    --user-bg: #2563eb;
    --user-text: #f8fafc;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--background);
    color: #0f172a;
}

body {
    display: flex;
}

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

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

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    width: 100%;
    min-height: 100vh;
}

.app-sidebar {
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    gap: 32px;
}

.sidebar-header {
    display: flex;
    justify-content: center;
}

.sidebar-settings {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 16px;
    display: grid;
    gap: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 -1px 0 rgba(15, 23, 42, 0.3);
}

.sidebar-settings__title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(226, 232, 240, 0.8);
    font-weight: 600;
}

.language-toggle {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    background: rgba(15, 23, 42, 0.4);
    border-radius: 16px;
    padding: 4px;
    gap: 4px;
}

.language-toggle__option {
    border: none;
    border-radius: 12px;
    padding: 8px 10px;
    color: rgba(226, 232, 240, 0.85);
    background: transparent;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.language-toggle__option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.language-toggle__option[aria-pressed="true"] {
    background: rgba(255, 255, 255, 0.9);
    color: #0f172a;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.25);
    transform: translateY(-1px);
}

.mode-toggle {
    display: grid;
    gap: 6px;
}

.mode-toggle__options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(226, 232, 240, 0.2);
    border-radius: 14px;
    padding: 3px;
    gap: 4px;
}

.mode-toggle__option {
    border: none;
    border-radius: 10px;
    padding: 8px 10px;
    background: transparent;
    color: rgba(226, 232, 240, 0.85);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.mode-toggle__option:hover {
    background: rgba(255, 255, 255, 0.12);
}

.mode-toggle__option--active,
.mode-toggle__option[aria-pressed="true"] {
    background: rgba(255, 255, 255, 0.9);
    color: #0f172a;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.22);
    transform: translateY(-1px);
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    white-space: nowrap;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.12);
    color: #bfdbfe;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.app-brand__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2563eb;
    color: white;
    font-size: 16px;
}

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

.sidebar-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, transform 0.15s ease;
}

.sidebar-link:hover {
    background: rgba(148, 163, 184, 0.18);
    transform: translateX(4px);
}

.sidebar-link--active {
    background: rgba(59, 130, 246, 0.22);
    color: #e0f2fe;
}

/* v2.1: Admin Dashboard 特殊样式 */
.sidebar-link--admin {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(5, 150, 105, 0.15));
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
    font-weight: 600;
}

.sidebar-link--admin:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(5, 150, 105, 0.25));
    border-color: rgba(16, 185, 129, 0.5);
    transform: translateX(6px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.sidebar-link--admin.sidebar-link--active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.35), rgba(5, 150, 105, 0.35));
    border-color: rgba(16, 185, 129, 0.6);
    color: #d1fae5;
}

.admin-badge {
    margin-left: auto;
    font-size: 16px;
    opacity: 0.9;
}

.sidebar-link--disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.sidebar-link__icon {
    font-size: 18px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.sidebar-footer__link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #bfdbfe;
    font-weight: 500;
}

.app-main {
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    position: relative;
}

.back-to-top {
    position: fixed;
    right: 4px;
    bottom: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(37, 99, 235, 0.88);
    color: #f8fafcf1;
    font-size: 1.4rem;
    font-weight: 700;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 120;
}

.back-to-top:hover {
    transform: translateY(-4px);
    background: rgba(29, 78, 216, 0.9);
}

.chat-workspace {
    width: min(900px, 100%);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 20px;
}

.chat-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.chat-header__titles h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 600;
}

.chat-header__titles p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.chat-header__controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field {
    display: grid;
    gap: 6px;
}

.field--compact {
    min-width: 220px;
}

.field__label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field__control {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: inherit;
    transition: border 0.15s ease, box-shadow 0.15s ease;
}

.field__control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field--checkbox {
    grid-template-columns: 1fr auto;
    align-items: center;
}

.field--checkbox .field__label {
    margin: 0;
}

.field--checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    justify-self: end;
}

.field__control--textarea {
    resize: vertical;
    min-height: 120px;
}

.chat-transcript {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-height: min(70vh, 640px);
    overflow-y: auto;
}

.chat-placeholder {
    text-align: center;
    color: var(--muted);
    display: grid;
    gap: 12px;
}

.chat-placeholder h2 {
    margin: 0;
    color: #1f2937;
}

.chat-placeholder ul {
    margin: 0;
    padding-left: 18px;
    text-align: left;
}

.chat-message {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: flex-start;
}

.chat-message__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: #0f172a;
    background: var(--assistant-bg);
}

.chat-message--user .chat-message__avatar {
    background: var(--user-bg);
    color: var(--user-text);
}

.chat-message__body {
    background: var(--assistant-bg);
    border-radius: 16px;
    padding: 16px;
    position: relative;
    overflow: hidden;
}

.chat-message--user .chat-message__body {
    background: linear-gradient(135deg, var(--user-bg), #1d4ed8);
    color: var(--user-text);
}

.chat-message__content {
    font-size: 0.98rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.chat-message__meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.chat-message--user .chat-message__meta {
    display: none;
}

.copy-button {
    border: 1px solid rgba(15, 23, 42, 0.1);
    background: rgba(255, 255, 255, 0.7);
    color: #1f2937;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.copy-button:hover {
    background: rgba(226, 232, 240, 0.9);
    transform: translateY(-1px);
}

.chat-composer {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 24px;
    display: grid;
    gap: 16px;
}

.chat-composer__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.chat-hint {
    font-size: 0.85rem;
    color: var(--muted);
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    align-items: end;
}

@media (max-width: 720px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.primary-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 12px 20px rgba(37, 99, 235, 0.22);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.primary-button:not(:disabled):hover {
    transform: translateY(-1px);
}

.ghost-button {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.65);
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.ghost-button:hover {
    transform: translateY(-1px);
    background: rgba(226, 232, 240, 0.7);
}

.markdown-body pre {
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    padding: 12px;
    border-radius: 12px;
    overflow-x: auto;
}

.markdown-body code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.2rem;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin-top: 1.2em;
    margin-bottom: 0.6em;
}

.markdown-body p {
    margin: 0.6em 0;
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: 220px 1fr;
    }
}


.hidden {
    display: none !important;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 18px;
        padding: 18px 20px;
    }

    .sidebar-nav {
        display: flex;
        gap: 8px;
    }

    .sidebar-link,
    .sidebar-link--disabled {
        padding: 10px 12px;
    }

    .sidebar-footer {
        border-top: none;
        margin-top: 0;
    }

    .app-main {
        padding: 24px;
    }

    .chat-workspace {
        gap: 16px;
    }

    .chat-transcript {
        max-height: none;
    }
}
