:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: #f1f5f9;
  -webkit-font-smoothing: antialiased;
}
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
a { color: var(--brand); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-weight: 500; line-height: 1;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #e2e8f0; }
.btn.sm { padding: 5px 9px; font-size: 13px; border-radius: 6px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b, #0f172a); }
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: .5px; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.brandmark { font-weight: 800; letter-spacing: 3px; color: var(--brand); font-size: 26px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line-strong);
  border-radius: 9px; outline: none;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }

/* ---------- App chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: #0f172a; color: #fff; padding: 0 18px; height: 56px;
  position: sticky; top: 0; z-index: 40;
}
.topbar .logo { font-weight: 800; letter-spacing: 3px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .85; }
.topbar .pill { background: rgba(255,255,255,.14); padding: 3px 9px; border-radius: 999px; font-size: 12px; }
.topbar button { color: #fff; }
.topbar .btn { background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.18); }
.topbar .btn:hover { background: rgba(255,255,255,.18); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 18px 64px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .spacer { flex: 1; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.card .card-pad { padding: 18px; }

/* ---------- Tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--line); }
table.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f8fafc; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: #fafcff; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.draft { background: #fef3c7; color: #92400e; }
.tag.submitted { background: #dcfce7; color: #166534; }
.tag.off { background: #f1f5f9; color: #64748b; }
.tag.on { background: #dbeafe; color: #1e40af; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 80; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.modal h3 { margin: 0; padding: 18px 20px; border-bottom: 1px solid var(--line); font-size: 17px; }
.modal .body { padding: 18px 20px; }
.modal .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.code-pill { font-family: ui-monospace, monospace; background: #f1f5f9; padding: 2px 6px; border-radius: 5px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { border: none; background: none; padding: 10px 14px; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* =====================================================================
   EDITOR
   ===================================================================== */
.editor { display: flex; flex-direction: column; height: calc(100vh - 56px); }
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; align-items: center; gap: 6px; padding-inline-end: 8px; border-inline-end: 1px solid var(--line); }
.toolbar .group:last-child { border-inline-end: none; }
.tool-btn {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 8px;
  width: 38px; height: 38px; display: grid; place-items: center; font-size: 17px;
}
.tool-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tool-btn[disabled] { opacity: .4; cursor: not-allowed; }
.title-input { border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; min-width: 180px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 2px var(--brand); }
.save-state { font-size: 13px; color: var(--muted); min-width: 90px; }

.editor-main { flex: 1; display: flex; min-height: 0; }
.stage-scroll { flex: 1; overflow: auto; background: #e2e8f0; padding: 22px; }
.stage {
  position: relative; margin: 0 auto; background: #fff; box-shadow: var(--shadow);
  user-select: none; -webkit-user-select: none;
}
.stage img { display: block; width: 100%; height: auto; pointer-events: none; -webkit-user-drag: none; }
.overlay { position: absolute; inset: 0; }
.overlay.tool-highlight { cursor: crosshair; }
.overlay.tool-text { cursor: text; }
.overlay.tool-select { cursor: default; }

.hl {
  position: absolute; border: 2px solid; border-radius: 2px; box-sizing: border-box;
}
.hl.selected { outline: 2px dashed var(--brand); outline-offset: 2px; }
.hl .badge {
  position: absolute; top: -10px; left: -2px; background: var(--brand); color: #fff;
  font-size: 10px; line-height: 1; padding: 2px 5px; border-radius: 5px; white-space: nowrap;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.txt {
  position: absolute; font-weight: 600; line-height: 1.15; white-space: pre-wrap;
  padding: 1px 2px; min-width: 8px; transform: translate(0, 0);
}
.txt.selected { outline: 2px dashed var(--brand); outline-offset: 2px; background: rgba(37,99,235,.06); }
.txt[contenteditable="true"] { outline: 2px solid var(--brand); background: #fff; cursor: text; }
.handle {
  position: absolute; width: 12px; height: 12px; right: -7px; bottom: -7px;
  background: #fff; border: 2px solid var(--brand); border-radius: 3px; cursor: nwse-resize;
}
.annot-move { cursor: move; }

/* Inspector */
.inspector {
  width: 290px; background: #fff; border-inline-start: 1px solid var(--line);
  overflow: auto; padding: 16px; flex-shrink: 0;
}
.inspector h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.inspector .hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.inspector textarea, .inspector input[type=text] {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px; resize: vertical;
}
.inspector .row { margin-bottom: 14px; }
.summary-item { font-size: 13px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.summary-item .k { font-weight: 700; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

@media (max-width: 820px) {
  .inspector { position: fixed; inset-inline-start: 0; top: 56px; bottom: 0; z-index: 30; box-shadow: 8px 0 24px rgba(0,0,0,.12); }
  .inspector.hidden { display: none; }
}
