/* ============================================
   AI Paper Reader — Styles
   Clean academic style with modern touches
   ============================================ */

/* ─── Reset & Base ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --border-color: #e0e3e8;
    --border-light: #eef0f4;
    --text-primary: #1a1a2e;
    --text-secondary: #5a6072;
    --text-muted: #949aab;
    --accent: #4f6ef7;
    --accent-light: #eef1fe;
    --accent-hover: #3b54d4;
    --green: #22c55e;
    --green-light: #dcfce7;
    --orange: #f59e0b;
    --orange-light: #fef3c7;
    --red: #ef4444;
    --red-light: #fee2e2;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Header ─── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    flex-shrink: 0;
}

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

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.subtitle {
    font-size: 13px;
    color: var(--text-muted);
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
}

.badge {
    font-size: 12px;
    background: var(--accent-light);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* ─── Layout ─── */
.container {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 0;
}

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

.panel-left {
    max-width: 45%;
    min-width: 350px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.panel-right {
    background: var(--bg-primary);
}

/* ─── Upload Zone ─── */
.upload-zone {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    margin: 24px;
    transition: all 0.2s;
    cursor: pointer;
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.upload-zone h3 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.upload-zone p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ─── PDF Preview ─── */
.pdf-preview {
    flex: 2;
    display: flex;
    flex-direction: column;
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.pdf-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-frame {
    flex: 1;
    border: none;
    width: 100%;
}

/* ─── Recent Papers ─── */
.recent-papers {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding: 12px 16px;
    overflow: hidden;
}

.recent-papers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.recent-papers-header h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.recent-papers-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.recent-empty {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 16px 0;
    margin: 0;
}

.recent-item {
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: all 0.15s;
}

.recent-item:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.recent-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}

.recent-item-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
    align-items: center;
}

.recent-item.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

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

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--accent);
}

.btn-outline:hover {
    background: var(--accent-light);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.btn-sm:hover {
    background: var(--border-light);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Empty State ─── */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-state h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.feature-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: 360px;
}

.feature-item {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-align: left;
}

/* ─── Workspace ─── */
.workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Tabs ─── */
.tabs {
    display: flex;
    gap: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    flex-shrink: 0;
}

.tab {
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    font-family: inherit;
}

.tab:hover {
    color: var(--accent);
    background: var(--accent-light);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab.running {
    position: relative;
}

.tab.running::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

/* ─── Action Bar ─── */
.action-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    flex-shrink: 0;
}

.status-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Result Area ─── */
.result-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 24px 24px;
}

.result-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ─── Markdown Content ─── */
.markdown-body {
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    line-height: 1.8;
}

.markdown-body h1 {
    font-size: 22px;
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-light);
}

.markdown-body h2 {
    font-size: 18px;
    margin: 20px 0 10px;
}

.markdown-body h3 {
    font-size: 15px;
    margin: 16px 0 8px;
    color: var(--text-secondary);
}

.markdown-body p {
    margin: 8px 0;
}

.markdown-body ul, .markdown-body ol {
    padding-left: 24px;
    margin: 8px 0;
}

.markdown-body li {
    margin: 4px 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13px;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.markdown-body th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.markdown-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.markdown-body pre {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    color: var(--text-secondary);
    margin: 12px 0;
}

.markdown-body strong {
    color: var(--text-primary);
}

/* ─── Mindmap ─── */
.mindmap-container {
    width: 100%;
    height: 600px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

#mindmapSvg {
    width: 100%;
    height: 100%;
}

/* ─── Translate Popup ─── */
.translate-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.translate-popup-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.translate-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 14px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-primary);
}

.translate-popup-body {
    padding: 16px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.7;
}

.translate-loading {
    color: var(--text-muted);
    text-align: center;
}

.translate-source {
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.translate-target {
    color: var(--text-primary);
}

/* ─── Loading Spinner ─── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Stream cursor ─── */
.stream-cursor::after {
    content: '▌';
    animation: blink 1s step-end infinite;
    color: var(--accent);
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ─── Footer ─── */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ─── Utility ─── */
.hidden {
    display: none !important;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    .panel-left {
        max-width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .tabs {
        overflow-x: auto;
    }
    .feature-list {
        grid-template-columns: 1fr;
    }
}

/* ─── Badge Clickable ─── */
.badge.clickable {
    cursor: pointer;
    transition: all 0.2s;
}
.badge.clickable:hover {
    background: var(--blue);
    color: white;
    transform: scale(1.05);
}

/* ─── Settings Panel ─── */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.settings-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    z-index: 1001;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}
.settings-header h2 {
    margin: 0;
    font-size: 18px;
    color: var(--text);
}
.settings-body {
    padding: 24px;
}
.form-group {
    margin-bottom: 18px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-hint {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.btn-full {
    width: 100%;
    margin-top: 8px;
}
.settings-status {
    text-align: center;
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
}

/* ─── Config Sections ─── */
.config-section {
    background: var(--bg, #f8fafc);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}
.config-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text, #1e293b);
    margin: 0 0 4px 0;
}
.config-section-desc {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin: 0 0 14px 0;
}
.optional-tag {
    font-size: 11px;
    font-weight: 500;
    background: #e0e7ff;
    color: #4338ca;
    padding: 1px 6px;
    border-radius: 4px;
}
.input-with-btn {
    display: flex;
    gap: 8px;
}
.input-with-btn input {
    flex: 1;
}
.btn-detect {
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 13px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-detect:hover {
    background: #4f46e5;
}
.btn-detect:disabled {
    background: #a5b4fc;
    cursor: not-allowed;
}
.models-dropdown {
    margin-top: 6px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
}
.models-empty {
    padding: 12px;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary, #64748b);
}
.model-item {
    padding: 8px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}
.model-item:hover {
    background: #eef2ff;
}
.model-item:last-child {
    border-bottom: none;
}
.model-id {
    font-size: 13px;
    font-weight: 500;
    color: var(--text, #1e293b);
}
.model-owner {
    font-size: 11px;
    color: var(--text-secondary, #94a3b8);
}

.models-error {
    padding: 10px 14px;
    font-size: 13px;
    color: #dc2626;
    background: #fef2f2;
    border-radius: 8px;
}

/* ─── Empty State Actions ─── */
.empty-actions {
    margin-top: 20px;
}

/* ─── Auth Modal ─── */
.auth-intro {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 16px;
}
.auth-intro code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}
.auth-status {
    text-align: center;
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
    color: var(--red);
}

/* ─── Snippet Translate Workspace ─── */
.snippet-translate-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 24px 24px;
    gap: 14px;
}

.snippet-input-wrap {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.snippet-input {
    width: 100%;
    min-height: 120px;
    max-height: 240px;
    padding: 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
}
.snippet-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}
.snippet-input::placeholder {
    color: var(--text-muted);
    line-height: 1.6;
}

.snippet-input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.snippet-char-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
}

.snippet-history-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    overflow: hidden;
}
.snippet-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}
.snippet-history-header h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}
.snippet-history-hint {
    font-size: 11px;
    color: var(--text-muted);
}
.snippet-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

/* 单条翻译历史 */
.snippet-item {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    overflow: hidden;
    background: var(--bg-primary);
    transition: border-color 0.15s;
}
.snippet-item:last-child {
    margin-bottom: 0;
}
.snippet-item:hover {
    border-color: var(--accent);
}

.snippet-block {
    padding: 12px 14px;
    position: relative;
}
.snippet-block + .snippet-block {
    border-top: 1px dashed var(--border-light);
}
.snippet-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.snippet-block-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.snippet-block-label.source { color: var(--text-secondary); }
.snippet-block-label.target { color: var(--accent); }

.snippet-block-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    user-select: text;
}
.snippet-block-text.source {
    color: var(--text-secondary);
    font-style: italic;
}

.snippet-copy-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 3px 9px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.snippet-copy-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.snippet-copy-btn.copied {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.snippet-item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-light);
    font-size: 11px;
    color: var(--text-muted);
}
.snippet-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: inherit;
}
.snippet-delete-btn:hover {
    color: var(--red);
    background: var(--red-light);
}

.snippet-loading {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.snippet-loading .spinner {
    margin-right: 6px;
    vertical-align: middle;
}

