:root {
  --red: #e50018;
  --red-dark: #ab0012;
  --red-deep: #8a0010;
  --red-tint: #fdecee;
  --ink: #1d1d1f;
  --ink-2: #4a4a4f;
  --muted: #76767c;
  --line: #dcdce0;
  --line-soft: #ececef;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --topbar: #1b1b1d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

/* ---------- Top bar ---------- */
.topbar { background: var(--topbar); border-bottom: 3px solid var(--red); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: #fff; }
.logo { height: 34px; width: auto; display: block; }
.brand-divider { width: 1px; height: 30px; background: rgba(255,255,255,.25); }
.brand-title { font-weight: 600; font-size: 16px; line-height: 1.15; display: flex; flex-direction: column; }
.brand-title small { font-weight: 400; font-size: 12px; color: rgba(255,255,255,.6); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.export-note { color: rgba(255,255,255,.6); font-size: 12px; }

.mode-toggle { display: inline-flex; background: #2c2c2f; border-radius: 999px; padding: 3px; }
.mode-toggle button {
  border: 0; background: transparent; color: rgba(255,255,255,.7);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.mode-toggle button[aria-pressed="true"] { background: var(--red); color: #fff; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 8px 16px;
  font-size: 14px; font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-light { background: #fff; color: var(--ink); }
.btn-light:hover { background: #eee; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }
.icon-btn.danger:hover { background: var(--red-tint); color: var(--red-dark); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- Page head ---------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; gap: 8px; }
.crumbs a { color: var(--red-dark); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; display: flex; align-items: center; gap: 6px; }
.page-head p { margin: 0; }

.mode-banner {
  background: var(--red-tint); color: var(--red-deep);
  border: 1px solid #f6c5cb; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; font-size: 14px;
}
.progress { min-width: 220px; }
.progress-label { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; text-align: right; }
.progress-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--red); }

/* ---------- Scenario list ---------- */
.search { margin-bottom: 16px; }
.search input {
  width: 100%; max-width: 420px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff;
}
.search input:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.scenario-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.scenario-card {
  display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line-soft);
  border-left: 4px solid var(--red); border-radius: var(--radius); box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s;
}
.scenario-card:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,.06), 0 10px 24px rgba(0,0,0,.08); }
.scenario-link { flex: 1; display: flex; align-items: center; gap: 16px; padding: 16px 18px; text-decoration: none; min-width: 0; }
.scenario-num {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--red-tint); color: var(--red-dark); font-weight: 700; font-size: 14px;
}
.scenario-text { flex: 1; min-width: 0; }
.scenario-name { font-weight: 600; font-size: 16px; display: block; overflow-wrap: anywhere; }
.scenario-meta { font-size: 13px; color: var(--muted); }
.scenario-chev { color: var(--muted); font-size: 22px; line-height: 1; }
.scenario-actions { display: flex; gap: 2px; padding-right: 10px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); background: #fff; border-radius: var(--radius); border: 1px dashed var(--line); }

/* ---------- Form replica ---------- */
.fsec { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 18px; overflow: hidden; box-shadow: var(--shadow); }
.fsec-head {
  background: linear-gradient(180deg, #c3101f, var(--red-deep)); color: #fff; font-weight: 600; font-size: 16px;
  padding: 9px 14px; display: flex; justify-content: space-between; align-items: center;
}
.fsec-head svg { width: 16px; height: 16px; opacity: .85; }
.fgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 28px; padding: 16px 18px 20px; }

.field {
  display: flex; flex-direction: column; gap: 4px; padding: 8px; margin: 0 -8px; border-radius: 8px;
  border: 1px solid transparent; text-align: left; background: transparent; min-width: 0;
}
.field.editable { cursor: pointer; }
.field.editable:hover, .field.editable:focus-visible { background: #fafafb; border-color: var(--line); outline: none; }
.field.editable:focus-visible { box-shadow: 0 0 0 2px var(--red); }
.field.editable.has-guide { background: #fff8f8; border-color: #f6d4d8; }
.field.active { box-shadow: 0 0 0 2px var(--red) !important; }

.flabel-row { display: flex; align-items: center; gap: 6px; min-height: 22px; }
.flabel { font-weight: 600; font-size: 14px; color: var(--ink); }
.req { color: var(--red); margin-left: 3px; }
.guide-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.edit-hint { margin-left: auto; font-size: 12px; color: var(--muted); opacity: 0; transition: opacity .12s; }
.field.editable:hover .edit-hint, .field.editable:focus-visible .edit-hint { opacity: 1; }

.info {
  flex: none; width: 20px; height: 20px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--red); color: #fff; font: italic 700 12px/20px Georgia, serif; text-align: center; padding: 0;
  box-shadow: 0 0 0 3px var(--red-tint);
}
.info:hover { background: var(--red-dark); }
.info:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.ctl {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 38px;
  padding: 7px 10px; border: 1px solid #b9b9bf; border-radius: 3px; background: #fff;
  font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden;
}
.ctl-value { overflow: hidden; text-overflow: ellipsis; }
.ctl-value.placeholder { color: var(--muted); }
.ctl svg { width: 14px; height: 14px; flex: none; color: var(--ink-2); }
.ctl[dir="rtl"] { justify-content: flex-start; }
.radios { display: flex; gap: 18px; min-height: 38px; align-items: center; font-size: 14px; }
.radio { display: inline-flex; align-items: center; gap: 6px; }
.radio i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #8a8a90; display: inline-block; position: relative; }
.radio.on i { border-color: var(--ink); }
.radio.on i::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--ink); }
.mock-btn {
  align-self: flex-start; background: linear-gradient(180deg, #d0182a, var(--red-dark)); color: #fff;
  border: 1px solid var(--red-deep); padding: 7px 14px; font-weight: 600; font-size: 14px; border-radius: 3px;
}

.span-full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 30px; font-size: 14px; font-weight: 600; }
.check i { width: 16px; height: 16px; border: 1.5px solid #8a8a90; border-radius: 3px; background: #fff; display: inline-grid; place-items: center; }
.check.on i { background: var(--red); border-color: var(--red); }
.check.on i::after { content: ""; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }

.ftable { border: 1px solid var(--line); border-radius: 4px; margin: 4px 0 8px; min-width: 0; }
.ftable-title { font-weight: 600; font-size: 14px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ftable-scroll { overflow-x: auto; }
.ftable table { border-collapse: collapse; width: 100%; min-width: 1120px; font-size: 14px; table-layout: fixed; }
.cell .check { min-height: 34px; padding-left: 8px; }
.ftable thead th:first-child { width: 170px; }
.ftable thead th { background: linear-gradient(180deg, #c3101f, var(--red-deep)); color: #fff; font-weight: 600; padding: 8px 10px; border-right: 1px solid rgba(255,255,255,.25); text-align: center; white-space: nowrap; }
.ftable tbody th { text-align: left; font-weight: 600; padding: 6px 12px; white-space: nowrap; border-top: 1px solid var(--line-soft); }
.ftable td { padding: 4px; border-top: 1px solid var(--line-soft); }
.cell { display: flex; align-items: center; gap: 6px; width: 100%; padding: 0; border: 1px solid transparent; border-radius: 6px; background: transparent; text-align: left; }
.cell .ctl { flex: 1; min-width: 0; min-height: 34px; }
.cell.editable { cursor: pointer; padding: 3px; }
.cell.editable:hover, .cell.editable:focus-visible { border-color: var(--line); background: #fafafb; outline: none; }
.cell.editable:focus-visible { box-shadow: 0 0 0 2px var(--red); }
.cell.editable.has-guide { background: #fff8f8; border-color: #f6d4d8; }
.cell.active { box-shadow: 0 0 0 2px var(--red) !important; }
.cell { position: relative; }
.cell .info, .cell .guide-dot { position: absolute; top: -5px; right: -5px; z-index: 1; }
.cell .info { width: 18px; height: 18px; font-size: 11px; line-height: 18px; box-shadow: 0 0 0 2px #fff; }
.cell .guide-dot { top: -3px; right: -3px; box-shadow: 0 0 0 2px #fff; }

/* ---------- Drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20,20,22,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: #fff; z-index: 50;
  box-shadow: -8px 0 32px rgba(0,0,0,.18); transform: translateX(100%); transition: transform .2s ease;
  display: flex; flex-direction: column; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--line-soft); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { margin: 0; font-size: 19px; line-height: 1.3; }
.eyebrow { margin: 0 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--red-dark); font-weight: 700; }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line-soft); display: flex; gap: 8px; }
.drawer-foot .spacer { flex: 1; }
.lbl { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.drawer #g-value {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; margin-bottom: 20px; background: #fff;
}
.drawer #g-value:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.drawer textarea {
  width: 100%; min-height: 170px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; line-height: 1.55; margin-bottom: 20px;
}
.drawer textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.doc-options { display: grid; gap: 8px; }
.doc-opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.doc-opt:hover { background: #fafafb; }
.doc-opt input { accent-color: var(--red); width: 16px; height: 16px; margin: 0; }
.doc-opt:has(input:checked) { border-color: var(--red); background: var(--red-tint); }
.doc-opt svg, .doc-item svg { width: 18px; height: 18px; color: var(--red-dark); flex: none; }

.guide-desc { white-space: pre-wrap; margin: 0 0 22px; overflow-wrap: anywhere; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.doc-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--red-tint); border-radius: 8px; font-weight: 600; font-size: 14px; }

/* ---------- Name dialog ---------- */
.name-dialog { border: 0; border-radius: 12px; padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.name-dialog::backdrop { background: rgba(20,20,22,.4); }
.name-dialog form { padding: 22px; }
.name-dialog h2 { margin: 0 0 14px; font-size: 18px; }
.name-dialog input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.name-dialog input:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; transition: .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red-dark); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) { .fgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) {
  .container { padding: 20px 16px 48px; }
  .topbar-inner { padding: 10px 16px; flex-wrap: wrap; }
  .brand-divider, .brand-title small { display: none; }
  .logo { height: 28px; }
  .fgrid { grid-template-columns: 1fr; padding: 12px 14px 16px; }
  .page-head h1 { font-size: 22px; }
  .progress { width: 100%; }
  .progress-label { text-align: left; }
}

@media print {
  .topbar { position: static; }
  .top-actions, .info { display: none; }
}
