:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e2e6ed;
  --text: #1c2430;
  --text-muted: #6b7684;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-bg: #eaf1fe;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --success: #16a34a;
  --success-bg: #eafaf0;
  --warn: #d97706;
  --warn-bg: #fef6e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 35, 0.06), 0 4px 14px rgba(20, 25, 35, 0.06);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.topbar .brand .sub { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.topbar .spacer { flex: 1; }
.save-status { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.save-status.saving { color: var(--warn); }
.save-status.saved { color: var(--success); }
.save-status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---- Buttons ---- */
button {
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-hover); }
button.danger { color: var(--danger); border-color: #f3c8c8; background: var(--danger-bg); }
button.danger:hover { background: #fbdada; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.icon { padding: 6px 8px; line-height: 1; }
.kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; color: var(--text-muted); }

/* ---- Layout: sidebar + content ---- */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
.sidebar .step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 2px;
}
.sidebar .step:hover { background: var(--surface-2); }
.sidebar .step.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.sidebar .step .num {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; flex-shrink: 0;
}
.sidebar .step.active .num { background: var(--primary); color: #fff; }
.sidebar .step.done .num { background: var(--success); color: #fff; }

.content { flex: 1; padding: 24px 32px 80px; max-width: 1100px; }

/* ---- Cards / form ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .desc { color: var(--text-muted); font-size: 12.5px; margin-bottom: 18px; }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin: 22px 0 10px; padding-top: 14px; border-top: 1px solid var(--border);
}
.section-title:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11px; color: var(--text-muted); }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=datetime-local],
.field select, .field textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus, .grid-cell input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg);
}

.checkbox-list { display: flex; flex-direction: column; gap: 8px; }
.checkbox-list label { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; font-weight: 400; cursor: pointer; }
.checkbox-list input { margin-top: 3px; }

.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; cursor: pointer; }

.step-nav { display: flex; justify-content: space-between; margin-top: 6px; }

/* ---- Criteria checklist ---- */
.criteria-row {
  display: grid;
  grid-template-columns: 1fr 160px;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.criteria-row:last-child { border-bottom: none; }
.criteria-row .label { font-size: 13px; }
.criteria-row select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.badge.na { background: var(--surface-2); color: var(--text-muted); }

/* ---- Grid (spreadsheet-like) ---- */
.grid-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid-toolbar .hint { font-size: 12px; color: var(--text-muted); }
.grid-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; min-width: 640px; }
table.grid th {
  background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 700;
  color: var(--text-muted); padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0;
}
table.grid td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; }
table.grid td:last-child { border-right: none; }
table.grid tr:hover td { background: #fbfcfe; }
.grid-cell input, .grid-cell select {
  width: 100%; border: none; background: transparent; padding: 7px 8px; font-size: 13px;
  font-family: inherit; color: var(--text); min-width: 70px;
}
.grid-cell input:focus, .grid-cell select:focus { background: var(--primary-bg); outline: none; }
.grid-cell.active { box-shadow: inset 0 0 0 2px var(--primary); }
.grid-rownum { text-align: center; color: var(--text-muted); font-size: 12px; user-select: none; width: 34px; }
.grid-rowdel { text-align: center; width: 34px; }
.grid-rowdel button { border: none; background: transparent; color: var(--text-muted); padding: 4px; }
.grid-rowdel button:hover { color: var(--danger); }

/* ---- Archive page ---- */
.archive-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
table.archive { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.archive th { text-align: left; font-size: 11.5px; text-transform: uppercase; color: var(--text-muted); padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
table.archive td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
table.archive tr:last-child td { border-bottom: none; }
table.archive .actions { display: flex; gap: 6px; justify-content: flex-end; }
.status-pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.status-pill.draft { background: var(--warn-bg); color: var(--warn); }
.status-pill.final { background: var(--success-bg); color: var(--success); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ---- Toast ---- */
#toast-host { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  background: #1c2430; color: #fff; padding: 12px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px; min-width: 220px;
  animation: toast-in .15s ease-out;
}
.toast button { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; padding: 4px 10px; font-size: 12px; }
.toast button:hover { background: rgba(255,255,255,.12); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.shortcut-bar {
  font-size: 11.5px; color: var(--text-muted); display: flex; gap: 16px; flex-wrap: wrap;
  padding: 8px 0 0;
}
