:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1d2430;
    --muted: #6b7684;
    --accent: #2b5fd9;
    --accent-soft: #e8eefc;
    --ok: #17803d;
    --ok-soft: #e4f5ea;
    --warn: #a15c00;
    --warn-soft: #fdf1dd;
    --bad: #b3261e;
    --bad-soft: #fdeceb;
    --radius: 8px;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

/* ---------- fejléc ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    height: 52px;
}

.topbar .brand {
    font-weight: 600;
    text-decoration: none;
    color: var(--text);
    white-space: nowrap;
}

.topbar nav {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.topbar nav a {
    padding: 6px 10px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    white-space: nowrap;
}

.topbar nav a:hover { background: var(--bg); color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }
main.wide { max-width: none; }

/* ---------- általános elemek ---------- */

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.subtitle { color: var(--muted); font-size: 13px; margin: 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- űrlapok ---------- */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 3px; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
select, textarea {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 13px; line-height: 1.45; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; font-weight: 400; }

button, .button {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button:hover:not(:disabled), .button:hover { background: var(--bg); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary, .button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
button.primary:hover:not(:disabled) { background: #2450b8; }

button.danger { color: var(--bad); border-color: #f0c6c3; }
button.small, .button.small { padding: 4px 9px; font-size: 13px; }

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 4px 6px;
    font: inherit;
}

/* ---------- táblázatok ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------- címkék, státuszok ---------- */

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--bg);
    color: var(--muted);
    white-space: nowrap;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.notice {
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 14px;
    margin-bottom: 12px;
}
.notice.warn { background: var(--warn-soft); border-color: #f0dcb6; color: var(--warn); }
.notice.bad { background: var(--bad-soft); border-color: #f2ccc9; color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: #c4e6d0; color: var(--ok); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---------- összehasonlító nézet ---------- */

.compare-scroll { overflow-x: auto; padding-bottom: 8px; }
.compare-track { display: flex; gap: 12px; align-items: flex-start; }

.run-column {
    flex: 0 0 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 170px);
}

.run-column.is-failed { border-color: #f0c6c3; }
.run-column.is-invalid { border-color: #f0dcb6; }

.run-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.run-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.run-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.run-meta b { color: var(--text); font-variant-numeric: tabular-nums; }

.run-checks { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.check-chip {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: help;
    background: var(--ok-soft);
    color: var(--ok);
}
.check-chip.failed { background: var(--bad-soft); color: var(--bad); }

.run-tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--border); }
.run-tabs button {
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 5px 8px;
    font-size: 12px;
    color: var(--muted);
    background: none;
}
.run-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.run-body { padding: 12px; overflow-y: auto; flex: 1; min-height: 160px; }
.run-foot { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--bg); }

.rating-row { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 4px; }
.rating-row span:first-child { flex: 0 0 110px; color: var(--muted); }
.stars { display: flex; gap: 2px; }
.stars button {
    border: none;
    background: none;
    padding: 0 2px;
    font-size: 15px;
    color: #cfd4da;
    cursor: pointer;
    line-height: 1;
}
.stars button.on { color: #e8a33d; }

/* ---------- feladatspecifikus renderelés ---------- */

.flashcard {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 11px;
    margin-bottom: 8px;
    cursor: pointer;
    background: var(--surface);
}
.flashcard.dupe { border-color: #f0c6c3; background: var(--bad-soft); }
.flashcard .front { font-weight: 600; font-size: 14px; }
.flashcard .back { margin-top: 6px; font-size: 13px; color: var(--text); }
.flashcard .meta { margin-top: 6px; font-size: 11px; color: var(--muted); }

.quiz-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.quiz-item:last-child { border-bottom: none; }
.quiz-q { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.quiz-options { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.quiz-options li { padding: 3px 6px; border-radius: 4px; }
.quiz-options li.correct { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.quiz-explain { font-size: 12px; color: var(--muted); margin-top: 6px; }

.cloze-item { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.cloze-item.bad { background: var(--bad-soft); border-radius: 4px; padding-left: 6px; padding-right: 6px; }
.cloze-blank {
    display: inline-block;
    min-width: 70px;
    border-bottom: 2px solid var(--accent);
    text-align: center;
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
}
.cloze-blank.revealed { border-bottom-style: dotted; }

.summary-key {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    padding: 8px 10px;
    border-radius: 0 4px 4px 0;
    font-size: 14px;
    margin-bottom: 10px;
}

.mindmap-tree { font-size: 13px; }
.mindmap-tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px dotted var(--border); }
.mindmap-tree li { padding: 2px 0; }
.mindmap-tree .label { font-weight: 600; }
.mindmap-tree .note { color: var(--muted); font-size: 12px; }

.term-table td { padding: 5px 7px; font-size: 13px; }

.tutor-steps { padding-left: 18px; font-size: 13px; }
.tutor-steps li { margin-bottom: 6px; }
.citation {
    font-size: 12px;
    color: var(--muted);
    border-top: 1px dashed var(--border);
    margin-top: 8px;
    padding-top: 6px;
}

pre.json {
    background: #1d2430;
    color: #e6e9ee;
    padding: 10px;
    border-radius: 6px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 12px;
    max-height: 420px;
    white-space: pre-wrap;
    word-break: break-word;
}

pre.plain {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 6px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 12px;
    max-height: 420px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- chunk lista ---------- */

.chunk-list { max-height: 460px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.chunk-item { display: flex; gap: 9px; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.chunk-item:last-child { border-bottom: none; }
.chunk-item:hover { background: var(--bg); }
.chunk-item input { margin-top: 3px; }
.chunk-item .chunk-head { font-weight: 600; font-size: 13px; }
.chunk-item .chunk-preview { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ---------- diff ---------- */

.diff { font-family: var(--mono); font-size: 12px; border: 1px solid var(--border); border-radius: 6px; overflow: auto; max-height: 420px; }
.diff div { padding: 1px 8px; white-space: pre-wrap; word-break: break-word; }
.diff .added { background: var(--ok-soft); }
.diff .removed { background: var(--bad-soft); }

/* ---------- chat ---------- */

.chat { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 260px); overflow-y: auto; padding-right: 6px; }
.chat-message { border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.chat-message.user { background: var(--accent-soft); align-self: flex-end; max-width: 80%; }
.chat-message.assistant { background: var(--surface); border: 1px solid var(--border); }
.chat-message .run-meta { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border); }

/* ---------- toast ---------- */

.toast-container { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
    background: var(--text);
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    max-width: 380px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- betöltés ---------- */

.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- belépés ---------- */

.login-wrap { max-width: 340px; margin: 12vh auto; }

/* ---------- diagram ---------- */

.chart-wrap { position: relative; height: 320px; }

/* ---------- kinyerés-összehasonlítás ---------- */

.extraction-panel { margin-top: 6px; }
.extraction-panel label.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; }
.extraction-panel tr.is-applied td { background: var(--accent-soft); }
.extraction-text { overflow: auto; padding: 8px 12px; }
.extraction-page { margin-bottom: 8px; }
.extraction-page pre.plain { max-height: none; margin: 4px 0 0; }
