:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1b2130;
  --muted: #667085;
  --line: #e3e8f0;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --yes: #12a150;
  --yes-bg: #e7f7ee;
  --no: #d92d20;
  --no-bg: #fdecec;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117; --panel: #171b23; --ink: #e6e9ef; --muted: #98a2b3;
    --line: #262c38; --brand: #7c74ff; --yes: #3ecf8e; --yes-bg: #14311f;
    --no: #ff6b6b; --no-bg: #3a1717; --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h2 { margin: 0 0 .4rem; font-size: 1.25rem; }
h3 { margin: 1.4rem 0 .5rem; font-size: 1rem; }
code { background: rgba(127,127,127,.15); padding: .05em .35em; border-radius: 5px; font-size: .9em; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.grow { flex: 1; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.logo { color: var(--brand); font-size: 1.4rem; }
.title { font-weight: 700; }
.subtitle { color: var(--muted); font-size: .8rem; }
.tabs { display: flex; gap: .3rem; }
.tab {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: .5rem .9rem; border-radius: 9px; font-size: .92rem; font-weight: 600;
}
.tab:hover { background: rgba(127,127,127,.1); }
.tab.active { background: var(--brand); color: var(--brand-ink); }

main { max-width: 920px; margin: 0 auto; padding: 1.2rem; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.3rem; margin-bottom: 1rem;
}
.centered { text-align: center; max-width: 520px; margin: 3rem auto; }

/* Login */
.login-row { display: flex; gap: .5rem; margin-top: 1rem; }
#code-input, #pass-input, #name-input {
  width: 100%; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 1rem;
}

/* Sign in / register switch */
.authswitch {
  display: inline-flex; gap: .2rem; padding: .25rem; margin-bottom: 1rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 11px;
}
.authtab {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: .4rem .9rem; border-radius: 8px; font-weight: 700; font-size: .88rem;
}
.authtab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.authform { text-align: left; display: flex; flex-direction: column; gap: .35rem; }
.authform label { font-size: .85rem; font-weight: 600; }
.authform .hint { margin: 0 0 .5rem; }
.authform > button { margin-top: .9rem; }
#name-wrap { display: flex; flex-direction: column; gap: .35rem; margin-top: .5rem; }
button.full { width: 100%; }
button.primary {
  background: var(--brand); color: var(--brand-ink); border: none; cursor: pointer;
  padding: .7rem 1.1rem; border-radius: 10px; font-weight: 700; font-size: .95rem;
}
button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.ghost, .btnlink {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: .5rem .8rem; border-radius: 9px; cursor: pointer; font-weight: 600;
  font-size: .85rem; text-decoration: none; display: inline-block;
}
button.ghost:hover { color: var(--ink); }
.error { color: var(--no); }

/* Status bar */
.statusbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; font-size: .9rem;
}
.progress-wrap { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 180px; }
.bar { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--brand); transition: width .3s; }

/* Emotion picker */
.filterbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-bottom: .8rem; font-size: .9rem;
}
.filterbar label { font-weight: 600; }
#emotion-filter {
  padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit; max-width: 100%;
}

/* Comment card */
.comment-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; }
.badge {
  background: var(--brand); color: var(--brand-ink); padding: .2rem .7rem;
  border-radius: 99px; font-size: .8rem; font-weight: 700; text-transform: capitalize;
}
blockquote {
  margin: 0 0 1rem; padding: .9rem 1.1rem; background: var(--bg);
  border-left: 4px solid var(--brand); border-radius: 8px; font-size: 1.08rem;
}
.instructions { font-size: .9rem; color: var(--muted); margin-bottom: .8rem; }

/* Dimension table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.jcol, th.jcol { text-align: right; white-space: nowrap; }
#dim-table td:first-child { font-weight: 600; text-transform: capitalize; }
.val { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ⓘ info icon + tooltip */
.dimcell { display: inline-flex; align-items: center; gap: .4rem; }
.info-icon, .info-icon-demo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; flex: none; padding: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--bg); color: var(--muted);
  font: 700 11px/1 Georgia, "Times New Roman", serif; font-style: italic;
  cursor: help; text-transform: none;
}
.info-icon:hover, .info-icon:focus-visible {
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
  outline: none;
}
.info-icon-demo { cursor: default; vertical-align: -2px; }

.dimtip {
  position: fixed; z-index: 60; width: min(340px, calc(100vw - 24px));
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: .8rem .9rem;
  box-shadow: 0 8px 28px rgba(16,24,40,.18);
  font-size: .85rem; line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  .dimtip { box-shadow: 0 8px 28px rgba(0,0,0,.5); }
}
.dimtip-head {
  font-weight: 800; text-transform: capitalize; margin-bottom: .3rem;
  display: flex; align-items: center; gap: .4rem;
}
.dimtip-def { margin: 0 0 .5rem; }
.dimtip-poles {
  display: flex; flex-direction: column; gap: .15rem;
  background: var(--bg); border-radius: 8px; padding: .4rem .55rem;
  font-size: .82rem; color: var(--muted);
}
.dimtip-poles b { color: var(--ink); font-variant-numeric: tabular-nums; }
.dimtip-caution {
  margin: .5rem 0 0; padding: .4rem .55rem; border-radius: 8px;
  background: var(--no-bg); color: var(--no); font-size: .8rem; font-weight: 600;
}
.dimtip-ex { margin-top: .6rem; }
.dimtip-exlabel {
  font-size: .68rem; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: .25rem;
}
.dimtip-ex blockquote {
  margin: 0 0 .35rem; padding: .45rem .6rem; font-size: .85rem;
  border-left-width: 3px;
}
.dimtip-ex p { margin: 0; color: var(--muted); }

.lbl {
  display: inline-block; padding: .12rem .55rem; border-radius: 99px;
  font-size: .8rem; font-weight: 700;
}
.lbl.vlow { background: #fde3e1; color: #b42318; }
.lbl.low  { background: #fdeee0; color: #b54708; }
.lbl.med  { background: #eceef2; color: #475467; }
.lbl.high { background: #e4f2e4; color: #197a3b; }
.lbl.vhigh{ background: #dcefe4; color: #12703a; }
@media (prefers-color-scheme: dark) {
  .lbl.vlow{background:#4a1a17;color:#ff9c94}.lbl.low{background:#4a2e14;color:#f7b267}
  .lbl.med{background:#2b313d;color:#aeb6c4}.lbl.high{background:#173a24;color:#7fe0a2}
  .lbl.vhigh{background:#13331f;color:#6fe0a0}
}

/* Bulk set-all bar */
.bulkbar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem .7rem; margin-bottom: .6rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.bulk {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .3rem .7rem; border-radius: 8px; cursor: pointer;
  font-weight: 700; font-size: .82rem;
}
.bulk:hover { border-color: var(--brand); color: var(--brand); }
#bulk-yes:hover { border-color: var(--yes); color: var(--yes); background: var(--yes-bg); }
#bulk-no:hover  { border-color: var(--no);  color: var(--no);  background: var(--no-bg); }

/* Yes/No toggle */
.yn { display: inline-flex; gap: .3rem; }
.yn button {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  padding: .35rem .8rem; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: .85rem;
}
.yn button.sel-yes { background: var(--yes-bg); color: var(--yes); border-color: var(--yes); }
.yn button.sel-no  { background: var(--no-bg);  color: var(--no);  border-color: var(--no); }

/* Correction row (shown when "No") */
.dim-correction > td { background: var(--bg); padding-top: .3rem; padding-bottom: .6rem; }
.correction { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.reclabel { display: inline-flex; gap: .3rem; }
.reclabel button {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  padding: .3rem .7rem; border-radius: 8px; cursor: pointer; font-weight: 700;
  font-size: .82rem; text-transform: capitalize;
}
.reclabel button.sel-rec { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.note-input {
  flex: 1; min-width: 160px; padding: .35rem .6rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink); font-size: .85rem;
}
.comment-note-wrap { margin-top: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.comment-note-wrap label { font-size: .85rem; font-weight: 600; }
#comment-note {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; resize: vertical;
}

/* Action bar */
.actionbar {
  display: flex; align-items: center; gap: .7rem; position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: .8rem 0; margin-top: -.4rem;
}

/* Guide */
.prose p { color: var(--ink); }
.mapping td, .mapping th { vertical-align: middle; }
.defs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.def { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; background: var(--bg); }
.def h3 {
  margin: 0 0 .3rem; font-size: .98rem; display: flex; align-items: center;
  gap: .4rem; text-transform: capitalize;
}
.def p { margin: 0; font-size: .88rem; color: var(--muted); }
.def .poles {
  margin-top: .4rem; padding: .35rem .5rem; background: var(--panel);
  border-radius: 7px; font-size: .82rem;
}
.def .poles b { color: var(--ink); font-variant-numeric: tabular-nums; }
.def .def-ex { margin-top: .45rem; font-size: .84rem; }
.def .def-ex em { color: var(--ink); }
.tag { font-size: .62rem; padding: .1rem .4rem; border-radius: 5px; font-weight: 800; letter-spacing: .05em; }
.tag.vad { background: var(--brand); color: var(--brand-ink); }

/* Progress */
.progress-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.summary { display: flex; gap: 1.5rem; margin: 1rem 0; flex-wrap: wrap; }
.summary .stat { font-size: 2rem; font-weight: 800; }
.summary .lab { color: var(--muted); font-size: .85rem; }
.minibar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; width: 120px; }
.minibar > div { height: 100%; background: var(--yes); }

/* Admin */
.export-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; }
.filters { display: flex; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.filters input, .filters select {
  padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); font: inherit;
}
#logs-table td { font-size: .84rem; vertical-align: top; }
#logs-table td.mono { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.act { padding: .1rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 700; }
.act.login { background: #e7eefc; color: #2547b0; }
.act.validate { background: #e4f2e4; color: #197a3b; }
.act.modify { background: #fdeee0; color: #b54708; }
.act.assign { background: #eceef2; color: #475467; }
.act.seed { background: #f0e7fc; color: #6b34c0; }
@media (prefers-color-scheme: dark) {
  .act.login{background:#1c2b52;color:#9db8ff}.act.validate{background:#173a24;color:#7fe0a2}
  .act.modify{background:#4a2e14;color:#f7b267}.act.assign{background:#2b313d;color:#aeb6c4}
  .act.seed{background:#2e1f4a;color:#c4a3ff}
}
.pager { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: .8rem; }
