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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #eef2ff;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --text: #1e293b;
    --text-secondary: #64748b;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "Microsoft JhengHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
}

/* ── Navbar ─────────────────────────────── */
.navbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
}
.nav-inner {
    max-width: 1280px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px;
}
.nav-brand { font-size: 18px; font-weight: 700; color: var(--primary); text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-link { color: var(--text-secondary); text-decoration: none; font-size: 14px; transition: color .2s; }
.nav-link:hover { color: var(--primary); }
.nav-user { color: var(--text); font-weight: 500; font-size: 14px; }
.nav-logout { color: var(--danger) !important; }

.main-content { max-width: 1280px; margin: 0 auto; padding: 24px; min-height: calc(100vh - 56px); }

/* ── Auth Card ──────────────────────────── */
.auth-card {
    background: var(--card); padding: 40px; border-radius: 16px;
    box-shadow: var(--shadow-lg); width: 100%; max-width: 420px;
}
.auth-title { text-align: center; font-size: 28px; color: var(--primary); margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); }
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Form Elements ──────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 14px; font-weight: 600; color: var(--text); }
.form-group input {
    padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 15px; transition: border-color .2s, box-shadow .2s;
    outline: none; background: var(--bg);
}
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; }

/* ── Buttons ────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius);
    font-size: 15px; font-weight: 600; cursor: pointer;
    transition: all .2s; text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ── Review Page ────────────────────────── */
.review-container { max-width: 100%; }
.review-header { margin-bottom: 20px; }
.review-header h2 { font-size: 24px; color: var(--text); }
.review-desc { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.review-input-area {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.input-toolbar {
    display: flex; gap: 12px; margin-bottom: 12px; align-items: center;
}
.input-title {
    flex: 1; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 14px; outline: none;
    background: var(--bg);
}
.input-title:focus { border-color: var(--primary); }
#review-text {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px; font-size: 15px; line-height: 1.8; resize: vertical;
    min-height: 200px; outline: none; font-family: inherit; background: var(--bg);
}
#review-text:focus { border-color: var(--primary); }
.input-footer { text-align: right; margin-top: 8px; }
#char-count { font-size: 12px; color: var(--text-secondary); }

/* ── Loading ────────────────────────────── */
.loading-area { text-align: center; padding: 40px; }
.spinner {
    width: 40px; height: 40px; border: 4px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-area p { color: var(--text-secondary); font-size: 14px; }

/* ── Error Area ─────────────────────────── */
.error-area {
    background: var(--danger-light); color: var(--danger);
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}

/* ── Result Split View ──────────────────── */
.result-split { display: flex; gap: 20px; }
.result-panel {
    flex: 1; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; min-height: 300px;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.panel-header h3 { font-size: 16px; }
.panel-body { padding: 20px; max-height: 600px; overflow-y: auto; }
.original-text { white-space: pre-wrap; line-height: 1.9; font-size: 15px; }

/* ── Score Badge ────────────────────────── */
.score-badge {
    display: inline-block; padding: 4px 12px; border-radius: 20px;
    font-size: 13px; font-weight: 700;
}
.score-high { background: var(--success-light); color: #15803d; }
.score-mid { background: var(--warning-light); color: #92400e; }
.score-low { background: var(--danger-light); color: #b91c1c; }

/* ── Highlight Marks ────────────────────── */
.highlight { padding: 1px 2px; border-radius: 3px; cursor: help; }
.hl-high { background: #fecaca; border-bottom: 2px solid var(--danger); }
.hl-mid { background: #fde68a; border-bottom: 2px solid var(--warning); }
.hl-low { background: #bfdbfe; border-bottom: 2px solid var(--primary); }

/* ── Overall Comment ────────────────────── */
.comment-box {
    padding: 14px 16px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: 14px; line-height: 1.7;
}
.comment-good { background: var(--success-light); border-left: 4px solid var(--success); }
.comment-ok { background: var(--warning-light); border-left: 4px solid var(--warning); }
.comment-bad { background: var(--danger-light); border-left: 4px solid var(--danger); }

/* ── Issue Cards ────────────────────────── */
.issues-list { display: flex; flex-direction: column; gap: 12px; }
.issue-card {
    border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden;
}
.issue-card.severity-high { border-left: 4px solid var(--danger); }
.issue-card.severity-mid { border-left: 4px solid var(--warning); }
.issue-card.severity-low { border-left: 4px solid var(--primary); }
.issue-header {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.issue-number { font-weight: 700; color: var(--text-secondary); font-size: 13px; }
.issue-type { font-weight: 600; font-size: 14px; flex: 1; }
.issue-severity { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.severity-tag-high { background: var(--danger-light); color: var(--danger); }
.severity-tag-mid { background: var(--warning-light); color: #92400e; }
.severity-tag-low { background: var(--primary-light); color: var(--primary); }
.issue-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.issue-row { display: flex; gap: 4px; font-size: 14px; line-height: 1.6; }
.issue-label { font-weight: 600; color: var(--text-secondary); white-space: nowrap; min-width: 48px; }
.issue-text { color: var(--text); }
.issue-suggestion { background: var(--success-light); padding: 10px 12px; border-radius: 6px; margin-top: 4px; }
.suggestion-text { color: #15803d; font-weight: 500; }

.no-issues { text-align: center; padding: 30px; color: var(--text-secondary); font-size: 15px; }
.empty-hint { color: var(--text-secondary); font-style: italic; }

/* ── History Page ───────────────────────── */
.history-container { max-width: 900px; margin: 0 auto; }
.history-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.history-header h2 { font-size: 24px; }
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item {
    display: flex; align-items: center; gap: 16px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 20px;
    transition: box-shadow .2s;
}
.history-item:hover { box-shadow: var(--shadow); }
.history-item-main { flex: 1; min-width: 0; }
.history-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.history-preview { color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-time { font-size: 12px; color: var(--text-secondary); margin-top: 4px; display: block; }
.history-item-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Pagination ─────────────────────────── */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 24px; }
.page-btn {
    width: 36px; height: 36px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--card);
    cursor: pointer; font-size: 14px; color: var(--text);
    display: flex; align-items: center; justify-content: center;
    transition: all .2s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Empty State ────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state p { font-size: 18px; color: var(--text-secondary); margin-bottom: 20px; }

/* ── Modal ──────────────────────────────── */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 200; }
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); }
.modal-content {
    position: relative; margin: 40px auto; max-width: 800px; max-height: 85vh;
    background: var(--card); border-radius: 16px; overflow: hidden;
    box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none; border: none; font-size: 24px; cursor: pointer;
    color: var(--text-secondary); padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; overflow-y: auto; }
.detail-section { margin-bottom: 20px; }
.detail-section h4 { font-size: 15px; margin-bottom: 8px; color: var(--text); }
.detail-text { white-space: pre-wrap; background: var(--bg); padding: 14px; border-radius: var(--radius); font-size: 14px; line-height: 1.8; }

/* ── Responsive ─────────────────────────── */
@media (max-width: 768px) {
    .result-split { flex-direction: column; }
    .review-header h2 { font-size: 20px; }
    .input-toolbar { flex-direction: column; }
    .input-toolbar .btn { width: 100%; }
}

/* ── Settings Page ──────────────────────── */
.settings-container { max-width: 700px; margin: 0 auto; }
.settings-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow);
}
.settings-card h2 { font-size: 24px; margin-bottom: 8px; }
.settings-desc { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }
.settings-section { margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-section h3 { font-size: 16px; color: var(--text); margin-bottom: 12px; }
.settings-info { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.settings-info a { color: var(--primary); }
.settings-current { font-size: 14px; margin-bottom: 16px; }
.settings-label { color: var(--text-secondary); }
.key-status-none { color: var(--danger); font-weight: 600; }
.key-status-set { color: var(--success); font-weight: 600; }
.input-with-toggle {
    display: flex; gap: 0;
}
.input-with-toggle input {
    flex: 1; border-top-right-radius: 0; border-bottom-right-radius: 0;
}
.btn-icon {
    padding: 10px 14px; border: 1px solid var(--border); border-left: none;
    border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius);
    background: var(--bg); cursor: pointer; font-size: 18px;
    transition: background .2s;
}
.btn-icon:hover { background: var(--border); }
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.form-hint code {
    background: var(--primary-light); color: var(--primary);
    padding: 1px 6px; border-radius: 4px; font-size: 12px;
}
.form-success {
    color: #15803d; font-size: 14px; font-weight: 600;
    padding: 10px 14px; background: var(--success-light);
    border-radius: var(--radius); margin-bottom: 12px;
}
.steps-list { padding-left: 20px; }
.steps-list li { margin-bottom: 8px; font-size: 14px; color: var(--text); line-height: 1.8; }
.steps-list li code {
    background: var(--bg); padding: 1px 6px; border-radius: 4px;
    font-size: 12px; color: var(--text-secondary);
}
.steps-list a { color: var(--primary); }

/* ── API Key Warning ────────────────────── */
.api-key-warning {
    background: var(--warning-light); border: 1px solid var(--warning);
    color: #92400e; padding: 14px 20px; border-radius: var(--radius);
    margin-bottom: 20px; font-size: 14px; font-weight: 500;
}
.api-key-warning a {
    color: var(--primary); font-weight: 700; margin-left: 8px;
    text-decoration: underline;
}
