/* ============================================================
   EDITOR.CSS — quiz, question bank and theme editors
   Uses the tokens.css palette (always the classic look, whatever
   theme the quiz being edited uses).
   ============================================================ */

body {
  background: var(--ink);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 15px;
  min-height: 100vh;
}

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

/* ── Header ───────────────────────────────────────────────── */
.ed-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--ink-raised);
  border-bottom: 3px solid var(--navy);
  flex-wrap: wrap;
}
.ed-header .ed-back {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--yellow);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ed-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-header nav { display: flex; gap: 8px; flex-wrap: wrap; }

.save-status {
  font-size: 13px;
  color: #9a9aa6;
  min-width: 90px;
  text-align: right;
}
.save-status.error { color: var(--red); font-weight: 600; }
.save-status.saving { color: var(--yellow); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--navy);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--navy-light); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--red); }
.btn-primary:hover { background: var(--red-deep); }
.btn-yellow { background: var(--yellow); color: var(--ink); }
.btn-yellow:hover { background: var(--yellow-deep); }
.btn-ghost { background: transparent; border: 2px solid rgba(255,255,255,0.2); }
.btn-ghost:hover { background: rgba(255,255,255,0.08); }
.btn-danger { background: transparent; color: var(--red); border: 2px solid var(--red); }
.btn-danger:hover { background: var(--red); color: var(--cream); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { padding: 4px 9px; font-size: 14px; border-radius: 8px; }

/* ── Layout ───────────────────────────────────────────────── */
.ed-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) minmax(320px, 520px);
  gap: 0;
  min-height: calc(100vh - 60px);
}
.ed-pane {
  padding: 20px;
  border-right: 1px solid rgba(255,255,255,0.07);
  min-width: 0;
}
.ed-pane:last-child { border-right: none; }
.ed-pane-sticky {
  position: sticky;
  top: 60px;
  align-self: start;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
}

@media (max-width: 1200px) {
  .ed-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .ed-layout .ed-preview-pane { grid-column: 1 / -1; position: static; max-height: none; border-top: 1px solid rgba(255,255,255,0.07); }
}
@media (max-width: 760px) {
  .ed-layout { grid-template-columns: 1fr; }
  .ed-pane-sticky { position: static; max-height: none; }
  .ed-pane { border-right: none; border-bottom: 1px solid rgba(255,255,255,0.07); }
}

.ed-page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }

.ed-section-title {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
}

/* ── Tree (quiz outline) ──────────────────────────────────── */
.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  border: 2px solid transparent;
}
.tree-item:hover { background: rgba(255,255,255,0.05); }
.tree-item.selected { background: var(--navy); }
.tree-item.drop-before { border-top-color: var(--yellow); }
.tree-item.drop-into { border-color: var(--yellow); }
.tree-item.dragging { opacity: 0.4; }
.tree-item .handle { cursor: grab; color: #77778a; font-size: 13px; }
.tree-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-round { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 8px; }
.tree-round .swatch { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.3); }
.tree-question { margin-left: 18px; font-size: 14px; }
.tree-question .num { color: #9a9aa6; font-size: 12px; min-width: 18px; }
.tree-add { margin: 4px 0 0 18px; }
.tree-static { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  white-space: nowrap;
}
.badge-warn { background: rgba(255,204,51,0.18); color: var(--yellow); }
.badge-bank { background: rgba(37,54,127,0.8); }
.badge-error { background: rgba(214,40,57,0.25); color: #ff8a95; }

/* ── Forms ────────────────────────────────────────────────── */
.form-card {
  background: var(--ink-raised);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}
.form-card h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 26px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row.single { grid-template-columns: 1fr; }
.form-row.thirds { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .form-row, .form-row.thirds { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field-label {
  font-size: 12px;
  font-weight: 600;
  color: #b5b5c2;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field .lang-tag { font-size: 10px; padding: 0 5px; border-radius: 4px; background: rgba(255,255,255,0.12); color: var(--cream); }
.field .hint { font-size: 12px; color: #8a8a99; }

input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%;
  background: var(--ink);
  color: var(--cream);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 15px;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--yellow); }
input.missing, textarea.missing { border-color: rgba(255,204,51,0.45); border-style: dashed; }
input[readonly] { opacity: 0.7; }
input[type=color] {
  flex-shrink: 0; width: 40px; height: 32px; padding: 0; border: 2px solid rgba(255,255,255,0.2);
  border-radius: 8px; background: none; cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--yellow); }
input[type=checkbox] { accent-color: var(--yellow); width: 16px; height: 16px; }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.form-actions .spacer { flex: 1; }

/* Lists of items (rules, sort items) */
.list-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.list-row { display: grid; grid-template-columns: 28px 1fr 1fr auto; gap: 6px; align-items: center; }
.list-row.single { grid-template-columns: 28px 1fr auto; }
.list-row .letter {
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); background: var(--yellow); color: var(--ink);
}
.order-list { display: flex; flex-direction: column; gap: 4px; }
.order-row { display: flex; align-items: center; gap: 8px; background: var(--ink); border-radius: 10px; padding: 4px 6px 4px 10px; }
.order-row .pos { color: #9a9aa6; font-size: 12px; min-width: 18px; }
.order-row .name { flex: 1; }

/* Media pickers */
.media-row { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.media-thumb {
  width: 70px; height: 46px; border-radius: 8px; background: var(--ink) center / cover no-repeat;
  border: 2px solid rgba(255,255,255,0.12);
}
.media-tag { font-family: var(--font-display); font-size: 14px; color: var(--yellow); text-transform: uppercase; }

/* ── Messages ─────────────────────────────────────────────── */
.error-box {
  background: rgba(214,40,57,0.15);
  border: 2px solid var(--red);
  color: #ffc2c8;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.error-box ul { margin: 4px 0 0 18px; }
.info-box {
  background: rgba(255,204,51,0.1);
  border: 2px solid rgba(255,204,51,0.4);
  color: var(--cream);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.empty {
  border: 2px dashed rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  color: #8a8a99;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(120px);
  background: var(--cream);
  color: var(--ink);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  z-index: 300;
  transition: transform 0.25s;
  max-width: 90vw;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); color: var(--cream); }

/* ── Preview ──────────────────────────────────────────────── */
.preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  border-radius: 12px;
  background: #000;
  display: block;
}
.preview-controls { display: flex; gap: 6px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.preview-controls .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--ink-raised); border-radius: var(--radius-pill); padding: 3px; }
.seg[hidden] { display: none; }
.seg button {
  border: none; background: transparent; color: var(--cream); padding: 4px 12px; border-radius: var(--radius-pill);
  font-family: var(--font-display); font-size: 13px; letter-spacing: 0.05em; cursor: pointer;
}
.seg button.on { background: var(--navy); }
.preview-grid { display: grid; gap: 12px; }
.preview-caption { font-size: 12px; color: #8a8a99; text-transform: uppercase; letter-spacing: 0.06em; margin: 8px 0 4px; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--ink-raised);
  border-radius: 20px;
  width: 100%;
  max-width: 760px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 {
  font-family: var(--font-display); font-weight: 400; font-size: 28px; text-transform: uppercase; margin-bottom: 14px;
}

/* ── Cards, tables ────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--ink-raised);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 2px solid rgba(255,255,255,0.05);
}
.card h3 { font-family: var(--font-display); font-weight: 400; font-size: 22px; text-transform: uppercase; }
.card .meta { font-size: 13px; color: #9a9aa6; }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatches span { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.25); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
.toolbar label { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.toolbar .spacer { flex: 1; }

.bank-list { display: flex; flex-direction: column; gap: 8px; }
.bank-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: var(--ink-raised);
  border-radius: 12px;
  padding: 10px 14px;
}
.bank-row .q-main { min-width: 0; }
.bank-row .q-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bank-row .q-answer { font-size: 13px; color: #9a9aa6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bank-row .q-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.bank-row .q-actions { display: flex; gap: 6px; }
.bank-row.selectable { cursor: pointer; }
.bank-row.selectable:hover { background: #33333d; }
.bank-row.checked { outline: 2px solid var(--yellow); }

/* Theme editor */
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.color-field { display: flex; align-items: center; gap: 8px; }
.color-field label { font-size: 12px; color: #b5b5c2; text-transform: uppercase; letter-spacing: 0.04em; flex: 1; }
.color-field code { font-size: 12px; color: #8a8a99; }
.style-card { background: var(--ink); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.style-card .style-head { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 10px; }
.style-sample {
  border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; margin-top: 10px;
  font-family: var(--font-display); font-size: 20px; text-transform: uppercase;
}
.style-sample .pill-sample { font-size: 12px; padding: 3px 10px; border-radius: var(--radius-pill); }
.contrast-warn { font-size: 12px; color: var(--yellow); margin-top: 6px; }
