:root {
  --primary: #003264;
  --accent: #F08800;
  --bg: #F5F7FA;
  --card: #fff;
  --text: #1c2733;
  --muted: #6b7785;
  --border: #dbe1e8;
  --err: #c62828;
  --warn: #e07b00;
  --ok: #2e7d32;
  --shadow: 0 2px 8px rgba(0, 50, 100, .08);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, Arial, sans-serif; }
h1, h2, h3 { margin: 0; color: var(--primary); }
h2 { font-size: 20px; display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--accent); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.app-header { background: var(--primary); color: #fff; padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; border-bottom: 4px solid var(--accent); }
.app-header h1 { color: #fff; font-size: 22px; }
.subtitle { margin: 2px 0 0; opacity: .8; }
.health { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-gray { background: #9aa5b1; } .dot-green { background: #4caf50; } .dot-orange { background: var(--accent); } .dot-red { background: #ef5350; }

.status-bar { position: sticky; top: 0; z-index: 20; background: #fff4e0; border-bottom: 1px solid var(--accent); padding: 8px 24px; display: flex; gap: 10px; align-items: center; color: #6a3d00; font-weight: 600; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.layout { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }
.steps { display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); padding: 20px 24px; }
.num { background: var(--primary); color: #fff; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }

.row { display: flex; gap: 10px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.form-row { margin-top: 18px; }
.form-row select { min-width: 200px; }

input[type=text], textarea, select { font: inherit; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; background: #fff; color: var(--text); width: 100%; }
select { width: auto; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 6px; padding: 8px 16px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #00457f; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #d97a00; }
.btn-secondary { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: #eaf1f8; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-block { display: block; width: 100%; margin-top: 8px; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; padding: 3px 8px; color: var(--muted); }
.icon-btn:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tpl { border: 2px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.tpl.selected { border-color: var(--accent); background: #fffaf2; }
.tpl label { cursor: pointer; font-weight: 600; color: var(--primary); display: flex; gap: 8px; align-items: center; }
.tpl .meta { font-size: 12px; color: var(--muted); }
.tpl .btn { align-self: flex-start; padding: 4px 10px; font-size: 12px; }

.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); list-style: none; margin: 4px 0 0; padding: 4px; z-index: 30; min-width: 280px; }
.dropdown-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; font: inherit; cursor: pointer; border-radius: 4px; }
.dropdown-menu button:hover { background: #eaf1f8; }

.dropzone { border: 2px dashed var(--border); border-radius: 8px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: #fffaf2; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: #eaf1f8; color: var(--primary); border-radius: 14px; padding: 3px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0; font-size: 12px; }
.chip.ok { background: #e3f4e4; color: var(--ok); }
.chip.warn { background: #fff0d9; color: var(--warn); }
.chip.err { background: #fde7e7; color: var(--err); }

.plan-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 1200px) { .plan-grid { grid-template-columns: minmax(0, 1fr) 340px; } .plan-side { position: sticky; top: 56px; align-self: start; } }
.plan-slides { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.deck-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-bottom: 14px; }
.deck-meta label, .slide-card label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }

.slide-card { border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; padding: 12px; background: #fff; }
.slide-card.hl { animation: hl 1.6s ease-out; }
@keyframes hl { 0% { background: #ffe9c2; box-shadow: 0 0 0 3px var(--accent); } 100% { background: #fff; box-shadow: none; } }
.slide-head { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.slide-head .no { font-weight: 700; color: var(--primary); min-width: 28px; padding-bottom: 8px; }
.slide-head .grow { flex: 1; min-width: 180px; }
.slide-body { display: grid; gap: 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.kpi-row { display: flex; gap: 6px; margin-bottom: 4px; }
.badge { display: inline-block; background: var(--primary); color: #fff; border-radius: 4px; padding: 2px 8px; font-size: 12px; }
.slide-actions { display: flex; gap: 4px; }

.side-card { background: #f9fbfd; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.side-card h3 { margin-top: 0; }
.issues { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow: auto; }
.issues li { padding: 6px 8px; border-radius: 4px; border-left: 3px solid var(--muted); background: #fff; font-size: 13px; }
.issues li.clickable { cursor: pointer; }
.issues li.clickable:hover { background: #eef3f8; }
.issues li.error { border-color: var(--err); color: var(--err); }
.issues li.warning { border-color: var(--warn); color: #8a4b00; }
.issues li.info { border-color: #9aa5b1; color: var(--muted); }
.issues li.fixed { border-color: var(--ok); color: var(--ok); }
.error-box { background: #fde7e7; border: 1px solid var(--err); color: var(--err); border-radius: 6px; padding: 8px 10px; font-size: 13px; white-space: pre-wrap; }

.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.preview { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px; cursor: pointer; text-align: center; font: inherit; }
.preview:hover { border-color: var(--accent); }
.preview img { width: 100%; display: block; background: #eee; }
.preview span { font-size: 12px; color: var(--muted); }
.qa-ok { color: var(--ok); font-weight: 700; } .qa-bad { color: var(--err); font-weight: 700; }
.actions .btn { margin-top: 8px; }
.actions .btn:first-child { margin-top: 0; }

.collapse-btn { background: none; border: 0; font: inherit; font-size: 18px; font-weight: 700; color: var(--primary); cursor: pointer; padding: 0; display: flex; gap: 8px; align-items: center; }
.collapse-btn[aria-expanded=true] .chev { transform: rotate(90deg); }
.chev { display: inline-block; transition: transform .15s; }
.trace-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 480px; overflow: auto; font-size: 13px; }
.trace-list li { padding: 5px 0; border-bottom: 1px solid #eef1f4; }
.trace-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.trace-time { font-family: ui-monospace, Consolas, monospace; color: var(--muted); }
.stage { color: #fff; border-radius: 4px; padding: 1px 7px; font-size: 11px; text-transform: uppercase; background: #6b7785; }
.stage-ingest { background: #5c6bc0; } .stage-passport { background: #00897b; } .stage-plan, .stage-llm { background: var(--primary); }
.stage-check { background: #7cb342; } .stage-fit { background: #8e24aa; } .stage-render { background: var(--accent); } .stage-qa { background: #00838f; }
.trace-list details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.trace-list pre { background: #f3f5f8; padding: 8px; border-radius: 4px; overflow: auto; max-height: 220px; margin: 4px 0; font-size: 12px; }

.modal { position: fixed; inset: 0; background: rgba(0, 20, 40, .55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: #fff; border-radius: 10px; max-width: 1100px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; text-transform: none; color: var(--primary); }
.modal-body { padding: 16px 20px; overflow: auto; }
.table-wrap { overflow-x: auto; }
table.passport { border-collapse: collapse; width: 100%; font-size: 12px; }
table.passport th { background: var(--primary); color: #fff; text-align: left; padding: 6px 8px; position: sticky; top: 0; }
table.passport td { border-bottom: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }
.swatch { display: inline-block; width: 12px; height: 12px; border: 1px solid #999; vertical-align: middle; margin-right: 3px; }
.kv { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 12px; font-size: 13px; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lightbox figure { margin: 0; max-width: 85vw; max-height: 90vh; text-align: center; color: #fff; }
.lightbox img { max-width: 85vw; max-height: 82vh; background: #fff; }
.lb-btn { position: absolute; background: rgba(255, 255, 255, .15); color: #fff; border: 0; font-size: 32px; width: 52px; height: 52px; border-radius: 50%; cursor: pointer; }
.lb-prev { left: 20px; } .lb-next { right: 20px; } .lb-close { top: 20px; right: 20px; font-size: 20px; }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: #323a45; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); border-left: 4px solid #9aa5b1; }
.toast.error { border-color: var(--err); background: #4a1f1f; }
.toast.success { border-color: var(--ok); }
.toast.warn { border-color: var(--warn, #d9822b); background: #4a3a1f; }

@media (max-width: 600px) {
  .layout { padding: 12px; } .card { padding: 14px; }
  .app-header { padding: 12px; }
}

.status-timer { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--primary); }
.dz-hint { display: block; margin-top: 4px; }
.plan-timing { margin: 0 0 12px; font-size: 14px; color: var(--primary); font-weight: 600; }
.timings-card { margin-bottom: 14px; }
.timings-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.timings-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.timings-table td.t-val { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.timings-table .t-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.timings-table tr.t-total td { border-bottom: 0; border-top: 2px solid var(--primary); font-size: 20px; font-weight: 700; color: var(--primary); padding-top: 8px; }
.chip.gray { background: #eceff1; color: #455a64; }
.editor-hint { margin: 6px 0 0; text-align: center; }
#open-editor { line-height: 1.3; }
