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

:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #0f3460;
    --accent: #0f3460;
    --accent-bright: #e94560;
    --text: #eee;
    --text-muted: #aab;
    --success: #00ff88;
    --warning: #ffc107;
    --error: #e94560;
    --border: #233554;
    --radius: 8px;
}

html {
    font-size: 14px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Header ===== */
header {
    text-align: center;
    padding: 2rem 1rem 1.5rem;
    background: linear-gradient(135deg, var(--bg-card), var(--accent));
    border-bottom: 2px solid var(--accent-bright);
}

.header-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.header-logo {
    width: 44px;
    height: 44px;
}

header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.3rem;
}

header .description {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.6rem;
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
    opacity: 0.75;
}

/* ===== Main & Cards ===== */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2.5rem 2rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
}

.card h2 {
    font-size: 1.15rem;
    margin-bottom: 1.5rem;
    color: var(--accent-bright);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
}

.hidden {
    display: none !important;
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 0.55rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}

.btn:hover:not(:disabled) {
    background: #174580;
    border-color: var(--accent-bright);
}

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

.btn.primary {
    background: var(--accent-bright);
    border-color: var(--accent-bright);
    color: #fff;
    font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
    background: #c73a52;
}

.btn.small {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
}

.upload-area.dragover {
    border-color: var(--accent-bright);
    background: rgba(233, 69, 96, 0.08);
}

.upload-hint {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.file-inputs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 480px;
    margin: 0 auto 2rem;
}

.file-box {
    position: relative;
    padding: 1.2rem 1.5rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-dark);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.file-box:hover {
    border-color: var(--accent-bright);
    background: rgba(233, 69, 96, 0.05);
}

.file-box.has-file {
    border-color: var(--success);
    border-style: solid;
    background: rgba(0, 255, 136, 0.05);
}

.file-box-icon {
    font-size: 1.8rem;
    line-height: 1;
    flex-shrink: 0;
}

.file-box-info {
    flex: 1;
    min-width: 0;
}

.file-box-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.file-box-name {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-box.has-file .file-box-name {
    color: var(--success);
}

.file-box input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ===== Status Messages ===== */
.status {
    margin-top: 0.75rem;
    padding: 0.5rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.status.success {
    background: rgba(0, 255, 136, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.status.error {
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
}

.status.loading {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid var(--warning);
    color: var(--warning);
}

/* ===== Detection Summary ===== */
#detection-summary {
    margin-top: 1.5rem;
}

#detection-summary h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

#summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.summary-item {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.summary-item strong {
    color: var(--text);
}

.summary-item span {
    color: var(--accent-bright);
    font-weight: 600;
}

/* ===== Review Layout ===== */
.review-layout {
    display: flex;
    gap: 1.5rem;
    min-height: 600px;
}

/* Left panel */
.question-list-panel {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.question-list-panel h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.section-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tab-btn:hover {
    background: var(--bg-input);
    color: var(--text);
}

.tab-btn.active {
    background: var(--accent-bright);
    border-color: var(--accent-bright);
    color: #fff;
}

.question-list {
    flex: 1;
    overflow-y: auto;
    max-height: 520px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-dark);
}

.question-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    transition: background 0.15s;
}

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

.question-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.question-item.selected {
    background: rgba(233, 69, 96, 0.15);
    border-left: 3px solid var(--accent-bright);
}

.question-item .q-num {
    font-weight: 700;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.question-item .q-subject {
    flex: 1;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.question-item .q-answer {
    font-weight: 600;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

/* Status colors */
.question-item.status-ok .q-num {
    color: var(--success);
}

.question-item.status-warning .q-num {
    color: var(--warning);
}

.question-item.status-error .q-num {
    color: var(--error);
}

/* Center panel */
.page-viewer-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

#page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 100px;
    text-align: center;
}

.canvas-container {
    position: relative;
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #111;
}

.canvas-container canvas {
    display: block;
}

#page-canvas {
    max-width: 100%;
    height: auto;
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    max-width: 100%;
    height: auto;
    pointer-events: none;
}

/* Right panel */
.preview-panel {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preview-panel h3 {
    font-size: 0.95rem;
}

#question-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#question-preview img {
    max-width: 100%;
    height: auto;
    display: block;
}

#question-preview .placeholder {
    color: #888;
    font-size: 0.85rem;
}

.meta-info {
    font-size: 0.8rem;
    line-height: 1.7;
    color: var(--text-muted);
}

.meta-info p strong {
    color: var(--text);
}

/* Adjust controls */
.adjust-controls h4 {
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: var(--accent-bright);
}

.adjust-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.adjust-fields label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.adjust-fields input[type="number"] {
    width: 100%;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-dark);
    color: var(--text);
    font-size: 0.8rem;
}

/* ===== Export ===== */
.export-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    align-items: center;
}

.export-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-status {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.step-status.loading {
    color: var(--warning);
}

.step-status.done {
    color: var(--success);
}

.step-status.error {
    color: var(--error);
}

/* ===== Progress Bar ===== */
.progress {
    margin-top: 1rem;
    height: 6px;
    background: var(--bg-dark);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-bright), var(--success));
    border-radius: 3px;
    transition: width 0.3s ease;
}

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

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

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

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

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .review-layout {
        flex-direction: column;
    }

    .question-list-panel,
    .preview-panel {
        width: 100%;
    }

    .question-list {
        max-height: 200px;
    }

    .review-layout {
        min-height: auto;
    }
}

@media (max-width: 600px) {
    header h1 {
        font-size: 1.2rem;
    }

    .file-inputs {
        flex-direction: column;
        align-items: center;
    }

    .export-options {
        flex-direction: column;
    }
}
