/* Minimal styles for VPR training frontend — based on rus7-vpr.sdamgia.ru */

:root {
    --text-color: #333;
    --bg: #fff;
    --border: #ddd;
    --accent: #006;
    --accent-light: #eef;
    --muted: #888;
    --solution-bg: #f7f7f7;
    --criteria-bg: #fffef0;
    --correct: #e0ffe0;
    --wrong: #ffe0e0;
}

* { box-sizing: border-box; }

body {
    font-family: 'Times New Roman', Times, serif;
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg);
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
}

.main-container {
    display: grid;
    grid-template-columns: 1fr 6px 1fr;
    height: 100vh;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    padding-bottom: 20px;
}

.work-panel {
    height: 100vh;
    overflow-y: auto;
    padding: 20px 30px 28px 30px;
    position: relative;
}

/* Resize handle */
.resize-handle {
    background: var(--border);
    cursor: col-resize;
    transition: background 0.2s;
    user-select: none;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent);
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--accent);
}

header h1 { font-size: 24px; margin: 0 0 10px 0; }
header p { color: var(--muted); margin: 0; }

.variant-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    padding: 15px;
    background: var(--accent-light);
    border-radius: 6px;
}

.variant-selector label { font-weight: bold; white-space: nowrap; }

.variant-selector select {
    font-size: 18px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Timer */

.timer-bar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 2px solid var(--border);
    padding: 12px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.timer-bar.active { display: block; }

.timer-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 16px;
}

.timer-table td {
    padding: 4px 12px;
    vertical-align: middle;
    white-space: nowrap;
}

.timer-table .timer-label {
    text-align: right;
    color: var(--muted);
    white-space: nowrap;
}

.timer-table .timer-value {
    font-family: 'Courier New', Courier, monospace;
    font-size: 22px;
    font-weight: bold;
    white-space: nowrap;
}

.timer-table .timer-value.warning {
    color: #c00;
    animation: timer-pulse 1s infinite;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.timer-btn {
    padding: 4px 14px;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f0f0f0;
    color: var(--accent);
    white-space: nowrap;
}

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

.timer-btn-finish {
    background: #fff3e0;
    color: #e65100;
    border-color: #e65100;
    font-weight: bold;
}
.timer-btn-finish:hover { background: #ffe0b2; }

.timer-btn-start {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: bold;
}
.timer-btn-start:hover { background: var(--accent-hover, #1565c0); }

.progress-toggle-btn {
    padding: 6px 16px;
    font-size: 15px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f0f0f0;
    color: var(--accent);
    white-space: nowrap;
}
.progress-toggle-btn:hover { background: var(--accent-light); }

/* Progress table */
.progress-section {
    margin-top: 30px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafafa;
}

.progress-section h2 {
    font-size: 20px;
    margin: 0;
    color: var(--accent);
}

.progress-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 15px;
}

.progress-table th,
.progress-table td {
    border: 1px solid var(--border);
    padding: 8px 6px;
    text-align: center;
    vertical-align: middle;
}

.progress-table th {
    background: #f5f5f5;
    font-weight: bold;
    font-size: 13px;
    color: var(--muted);
}

.progress-table thead th:first-child {
    width: 60px;
}

.pt-vnum {
    font-weight: bold;
    color: var(--accent);
    background: var(--accent-light);
}

.pt-score {
    font-weight: bold;
    color: var(--text-color);
}

.pt-empty {
    color: #ccc;
}

.pt-finish-col {
    background: #f8f8ff;
    font-size: 13px;
    white-space: nowrap;
    color: var(--muted);
}

.text-block {
    margin-bottom: 30px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafafa;
}

.text-block h3 {
    text-align: center;
    margin: 0 0 15px 0;
    font-size: 20px;
}

.task {
    margin-bottom: 25px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.task-header {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--accent);
}

.task-content { margin-bottom: 15px; }
.task-content p { margin: 0.5em 0; }

.task-answer {
    width: 100%;
    min-height: 80px;
    font-family: inherit;
    font-size: 17px;
    line-height: 1.5;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    resize: vertical;
}

.task-answer:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 3px rgba(0,0,102,0.2);
}

.save-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 6px 20px;
    font-size: 15px;
    cursor: pointer;
    border: 1px solid #2a7d2a;
    border-radius: 4px;
    background: #e8f5e8;
    color: #2a7d2a;
    font-weight: bold;
}

.save-btn:hover { background: #c8e6c8; }

.save-btn.saved {
    background: #c8e6c8;
    color: #1b5e1b;
    border-color: #1b5e1b;
    cursor: default;
}

.toggle-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 6px 16px;
    font-size: 15px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f0f0f0;
    color: var(--accent);
}

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

.solution {
    margin-top: 15px;
    padding: 15px 20px;
    background: var(--solution-bg);
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
}

.solution b { color: var(--accent); }

.criteria {
    margin-top: 10px;
    padding: 15px 20px;
    background: var(--criteria-bg);
    border: 1px solid #e8e0c0;
    border-radius: 6px;
    font-size: 16px;
}

.criteria table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.criteria td, .criteria th {
    border: 1px solid var(--border);
    padding: 6px 10px;
    vertical-align: top;
}

.criteria th {
    background: #f5f5f5;
    font-weight: bold;
}

sup { font-size: 0.75em; }

.loading { text-align: center; color: var(--muted); padding: 40px; }
.error { color: #c00; padding: 20px; background: #fff0f0; border-radius: 6px; }

/* Reset confirmation modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: var(--bg);
    padding: 30px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    text-align: center;
}

.modal-text {
    font-size: 20px;
    margin: 0 0 25px 0;
    color: var(--text-color);
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.modal-btn {
    padding: 8px 30px;
    font-size: 17px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.modal-btn-yes {
    background: #c00;
    color: #fff;
    border-color: #a00;
}
.modal-btn-yes:hover { background: #a00; }

.modal-btn-no {
    background: #f0f0f0;
    color: var(--text-color);
}
.modal-btn-no:hover { background: #e0e0e0; }

/* ── Chat panel ─────────────────────────────────────────────────────────── */

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 2px solid var(--accent);
    background: var(--bg);
    flex-shrink: 0;
}

.chat-header h2 {
    font-size: 20px;
    margin: 0;
    color: var(--accent);
}

.chat-settings-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 15px;
    cursor: pointer;
    color: var(--muted);
}

.chat-settings-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg.user {
    align-self: flex-end;
    background: #e3f2fd;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: #fff8e1;
    border-bottom-left-radius: 4px;
}

.chat-msg.system-msg {
    background: transparent;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
    padding: 6px 0;
    border: none;
    margin: 4px 0;
}

.chat-msg.typing {
    align-self: flex-start;
    background: #f5f5f5;
    color: var(--muted);
    font-style: italic;
}

.chat-msg p { margin: 0.3em 0; }
.chat-msg p:first-child { margin-top: 0; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}
.chat-msg pre {
    background: rgba(0,0,0,0.08);
    padding: 8px 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.9em;
}
.chat-msg strong { font-weight: bold; }
.chat-msg em { font-style: italic; }
.chat-msg ul, .chat-msg ol { padding-left: 20px; margin: 0.3em 0; }
.chat-msg li { margin: 0.15em 0; }
.chat-msg h1, .chat-msg h2, .chat-msg h3,
.chat-msg h4, .chat-msg h5, .chat-msg h6 {
    margin: 0.5em 0 0.25em;
    line-height: 1.3;
}
.chat-msg table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}
.chat-msg th, .chat-msg td {
    border: 1px solid #ccc;
    padding: 4px 8px;
    text-align: left;
}
.chat-msg th {
    background: #f0f0f0;
    font-weight: 600;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.4;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    min-height: 40px;
    max-height: 200px;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 3px rgba(0,0,102,0.2);
}

.chat-send-btn {
    align-self: flex-end;
    width: 44px;
    height: 44px;
    font-size: 22px;
    cursor: pointer;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-send-btn:hover { background: #003; }
.chat-send-btn:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

/* ── API key modal ──────────────────────────────────────────────────────── */

.api-key-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.api-key-box {
    background: var(--bg);
    padding: 30px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
    max-width: 420px;
    width: 90%;
}

.api-key-box h3 {
    margin: 0 0 10px;
    font-size: 20px;
    color: var(--accent);
}

.api-key-box p {
    margin: 0 0 15px;
    color: var(--muted);
    font-size: 15px;
}

.api-key-box input {
    width: 100%;
    padding: 8px 12px;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 15px;
}

.api-key-box input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 3px rgba(0,0,102,0.2);
}

.api-key-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.api-key-btn {
    padding: 8px 20px;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 4px;
}

.api-key-btn.save {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
}
.api-key-btn.save:hover { background: #003; }

.api-key-btn.cancel {
    background: #f0f0f0;
    color: var(--text-color);
    border: 1px solid var(--border);
}
.api-key-btn.cancel:hover { background: #e0e0e0; }

/* ── AI review blocks ───────────────────────────────────────────────────── */

.review-block {
    margin: 12px 0;
    padding: 14px 16px;
    background: #f0f7e6;
    border-radius: 8px;
    border-left: 4px solid #6aaa3a;
    font-size: 14px;
    line-height: 1.5;
}

.review-score {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 10px;
}

.review-score.high { background: #c8f7c5; color: #1a6b1a; }
.review-score.mid { background: #fff3cd; color: #856404; }
.review-score.low { background: #ffe0e0; color: #a00; }

.review-strengths,
.review-weaknesses,
.review-recommendation {
    margin: 8px 0;
    padding-left: 20px;
}

.review-strengths::before {
    content: "✓ ";
    color: #2a7a2a;
    font-weight: bold;
    margin-left: -16px;
}

.review-weaknesses::before {
    content: "⚡ ";
    margin-left: -16px;
}

.review-recommendation::before {
    content: "📖 ";
    margin-left: -16px;
}

.review-textbook-refs {
    margin-top: 8px;
    font-size: 13px;
    color: var(--muted);
}

.review-textbook-ref {
    display: inline-block;
    margin: 2px 4px;
    padding: 2px 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 4px;
    font-size: 12px;
}

.review-error {
    margin: 12px 0;
    padding: 12px 16px;
    background: #fff0f0;
    border-radius: 8px;
    border-left: 4px solid #d33;
    color: #a00;
    font-size: 14px;
}

/* ── Review loading overlay ─────────────────────────────────────────────── */

.review-loading-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255,255,255,0.82);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    z-index: 100;
    border-radius: 8px;
    padding: 20px;
    gap: 12px;
}

.review-log {
    width: 100%;
    max-height: 70%;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.review-log-entry {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 3px 8px;
    background: rgba(0,0,0,0.03);
    border-radius: 4px;
    line-height: 1.5;
}

.review-log-time {
    color: var(--muted);
    font-size: 11px;
    flex-shrink: 0;
    min-width: 52px;
}

.review-log-msg {
    color: var(--text-color);
    flex: 1;
}

.review-log-tokens {
    color: var(--accent);
    font-weight: bold;
    font-size: 12px;
    flex-shrink: 0;
}

.review-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

/* ── Token status bar ───────────────────────────────────────────────────── */

.token-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20px;
    padding: 0 12px;
    background: #f8f8f8;
    border-top: 1px solid var(--border);
    font-size: 11px;
    line-height: 20px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 500;
    font-family: 'Courier New', monospace;
}

.token-bar-label {
    white-space: nowrap;
}

.token-bar-status {
    white-space: nowrap;
    color: var(--accent);
}
