/* ========== Theme Variables ========== */
:root {
    --bg-color: #fcfcfc;
    --bg-secondary: #f7f7f7;
    --text-main: #1a1a1a;
    --text-muted: #888888;
    --text-faint: #cccccc;
    --accent: #222222;
    --accent-hover: #000000;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --sidebar-width: 260px;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --annotation-red: #c0392b;
    --annotation-red-light: #e74c3c;
    --original-bg: #fff0f0;
    --original-text: #cc0000;
    --correction-bg: #f0fbf0;
    --correction-text: #006600;
    --highlight-bg: #fff8e1;
    --copy-success: #006600;
    --toggle-bg: #f0f0f0;
    --toggle-active-bg: #222222;
    --toggle-active-text: #ffffff;
    --toggle-inactive-text: #666666;
    --google-blue: #4285f4;
}

[data-theme="dark"] {
    --bg-color: #141414;
    --bg-secondary: #1c1c1c;
    --text-main: #e0e0e0;
    --text-muted: #777777;
    --text-faint: #444444;
    --accent: #e0e0e0;
    --accent-hover: #ffffff;
    --border: #2a2a2a;
    --border-light: #222222;
    --annotation-red: #e07060;
    --annotation-red-light: #f08070;
    --original-bg: #2a1a1a;
    --original-text: #f08070;
    --correction-bg: #1a2a1a;
    --correction-text: #70c070;
    --highlight-bg: #2a2820;
    --copy-success: #70c070;
    --toggle-bg: #2a2a2a;
    --toggle-active-bg: #e0e0e0;
    --toggle-active-text: #141414;
    --toggle-inactive-text: #888;
}

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

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-main);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========== Layout ========== */
.app-container {
    display: flex;
    height: 100vh;
}

.split-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 1;
    min-width: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    padding: 3rem 4rem;
    height: 100%;
    overflow-y: auto;
}

.left-pane {
    border-right: 1px solid var(--border);
}

/* ========== History Sidebar ========== */
.history-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}

.history-sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    user-select: none;
}

.sidebar-new-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
    color: var(--text-muted);
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: all 0.15s;
    font-family: inherit;
}

.sidebar-new-btn:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
    background: var(--toggle-bg);
}

.sidebar-close-btn {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    transition: color 0.15s;
}

.sidebar-close-btn:hover {
    color: var(--text-main);
    background: none;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.history-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.15s;
}

.history-item:hover {
    background: var(--toggle-bg);
}

.history-item.active {
    background: var(--border);
}

.history-preview {
    font-size: 0.8rem;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.history-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.history-empty {
    padding: 2rem 1rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-faint);
}

.sidebar-toggle {
    position: fixed;
    top: 1.25rem;
    left: 0.75rem;
    z-index: 10;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 0;
    transition: opacity 0.2s, color 0.15s, background 0.15s;
}

.sidebar-toggle:hover {
    color: var(--text-main);
    background: var(--toggle-bg);
}

.sidebar-toggle.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ========== Theme Toggle ========== */
.theme-toggle {
    position: fixed;
    top: 1.25rem;
    right: 1rem;
    z-index: 10;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    padding: 0;
    transition: color 0.15s, background 0.15s, border-color 0.3s;
}

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

/* ========== Header ========== */
header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    user-select: none;
}

/* ========== Input Areas ========== */
.input-group {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 0;
}

.intent-section {
    flex-shrink: 0;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border);
}

.intent-label,
.draft-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 0.5rem;
    display: block;
    user-select: none;
}

#chinese-intent {
    width: 100%;
    border: none;
    background: transparent;
    resize: none;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
    min-height: 3.5em;
    max-height: 8em;
}

#chinese-intent::placeholder {
    color: var(--text-faint);
    font-weight: 300;
}

#editor {
    flex-grow: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 1.1rem;
    line-height: 1.7;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
}

#editor::placeholder {
    color: var(--text-faint);
    font-weight: 300;
}

/* ========== Action Bar ========== */
.action-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

button.primary-btn {
    padding: 0.75rem 1.5rem;
    background-color: var(--accent);
    color: var(--bg-color);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    transition: background-color 0.2s ease, color 0.2s ease;
}

button.primary-btn:hover {
    background-color: var(--accent-hover);
}

button.primary-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shortcut-hint {
    font-size: 0.7rem;
    color: var(--text-faint);
    user-select: none;
}

/* ========== Model Toggle ========== */
.model-toggle {
    display: inline-flex;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    user-select: none;
    flex-shrink: 0;
}

.model-toggle-btn {
    padding: 0.45rem 0;
    width: 5rem;
    text-align: center;
    border: none;
    background: var(--toggle-bg);
    color: var(--toggle-inactive-text);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.model-toggle-btn.active {
    background: var(--toggle-active-bg);
    color: var(--toggle-active-text);
}

.model-toggle-btn:not(.active):hover {
    background: var(--border);
}

/* ========== Output / Right Pane ========== */
#output {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 1.05rem;
    line-height: 1.6;
}

.empty-state {
    color: var(--text-muted);
    font-weight: 300;
}

.error-state {
    color: var(--original-text);
    font-weight: 400;
}

/* ========== Corrected Text ========== */
.corrected-section {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.copy-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.copy-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.35rem 0.7rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: all 0.15s;
}

.copy-btn:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
    background: var(--toggle-bg);
}

.copy-btn.copied {
    color: var(--copy-success);
    border-color: var(--copy-success);
}

.corrected-text {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-main);
}

.corrected-text sup {
    color: var(--annotation-red);
    font-weight: 600;
    font-size: 0.7em;
    cursor: pointer;
    margin-left: 1px;
    transition: color 0.15s;
}

.corrected-text sup:hover {
    color: var(--annotation-red-light);
}

/* ========== Annotations / Footnotes ========== */
.annotations-section {
    counter-reset: annotation;
}

.annotations-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    user-select: none;
}

.annotation-item {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.3s ease;
    border-radius: 4px;
}

.annotation-item:last-child {
    border-bottom: none;
}

.annotation-number {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--annotation-red);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.15rem;
}

.annotation-body {
    flex: 1;
}

.annotation-comparison {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.annotation-original {
    font-size: 0.85rem;
    color: var(--original-text);
    background: var(--original-bg);
    text-decoration: line-through;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    display: inline;
    margin-right: 0.5rem;
}

.annotation-correction {
    font-size: 0.85rem;
    color: var(--correction-text);
    background: var(--correction-bg);
    font-weight: 500;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    display: inline;
}

.annotation-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.annotation-explanation {
    font-size: 0.92rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ========== All-clear & Loading ========== */
.success-state {
    color: var(--correction-text);
    font-weight: 400;
    font-size: 1.05rem;
}

.loading-dots::after {
    content: '';
    animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }
}

/* ========== Sidebar Footer / Auth ========== */
.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.auth-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-main);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.auth-btn:hover {
    border-color: var(--text-muted);
    background: var(--toggle-bg);
}

.auth-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--google-blue);
    color: white;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 700;
    flex-shrink: 0;
}

.auth-label {
    flex: 1;
    text-align: left;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.user-email {
    flex: 1;
    font-size: 0.7rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sign-out-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 0.65rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    transition: all 0.15s;
    font-family: inherit;
    flex-shrink: 0;
}

.sign-out-btn:hover {
    color: var(--text-main);
    background: var(--toggle-bg);
}

.sync-indicator {
    font-size: 0.6rem;
    color: var(--text-faint);
    text-align: center;
    padding: 0.25rem 0 0;
    letter-spacing: 0.03em;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .history-sidebar {
        position: fixed;
        z-index: 20;
        height: 100%;
    }

    .split-container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .left-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .pane {
        padding: 1.5rem 2rem;
    }

    .action-bar {
        flex-wrap: wrap;
    }
}