/* Wordish admin — brand-matched, calm, Notion-like restraint. */
:root {
  --ink: #191918;
  --paper: #FAFAF8;
  --raised: #F0F2F3;
  --line: #E1E5E8;
  --muted: #70706B;
  --faint: #A7A7A1;
  --primary: #0279FB;
  --primary-deep: #005FC8;
  --primary-soft: #EAF4FF;
  --orange: #F7B313;
  --error: #D94E3C;
  --error-soft: #FBEAE7;
  --green: #1F9E5A;
  --green-soft: #E7F5EC;
  --white: #FFFFFF;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(25, 25, 24, 0.04), 0 8px 24px rgba(25, 25, 24, 0.06);
  --font: -apple-system, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }

/* ---- Login gate ---- */
.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--primary-soft), transparent 70%),
    var(--paper);
}
.gate-card {
  width: 100%; max-width: 380px; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px 28px;
}
.gate-mark { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.gate-mark svg { width: 30px; height: 30px; }
.gate h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.gate p { color: var(--muted); font-size: 13px; margin: 4px 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--white); }
.gate-error { color: var(--error); font-size: 13px; margin: 0 0 12px; min-height: 18px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: 14px; transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-deep); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--raised); }
.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- App shell ---- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column;
  gap: 4px; position: sticky; top: 0; height: 100vh; background: var(--paper);
}
.brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 18px; }
.brand svg { width: 26px; height: 26px; }
.brand b { font-size: 16px; letter-spacing: -0.02em; }
.brand span { font-size: 11px; color: var(--faint); font-weight: 600; margin-left: 2px;
  background: var(--raised); padding: 2px 6px; border-radius: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600; font-size: 14px; border: none; background: transparent;
  width: 100%; text-align: left; transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; opacity: .8; }
.nav-item:hover { background: var(--raised); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-deep); }
.nav-item.active svg { opacity: 1; }
.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.sidebar-footer .who { font-size: 12px; color: var(--faint); padding: 4px 8px 10px; word-break: break-all; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 22px 32px 0; margin-bottom: 6px;
}
.topbar h2 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.view { padding: 22px 32px 60px; }

/* ---- Cards / stats ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.stat .value small { font-size: 14px; font-weight: 600; color: var(--faint); }

.panel {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden;
}
.panel-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-head .hint { font-size: 12px; color: var(--faint); }
.panel-body { padding: 16px 18px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* distribution bars */
.dist-row { display: grid; grid-template-columns: 140px 1fr 44px; align-items: center; gap: 12px; padding: 5px 0; font-size: 13px; }
.dist-row .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-track { height: 8px; background: var(--raised); border-radius: 6px; overflow: hidden; }
.dist-fill { height: 100%; background: var(--primary); border-radius: 6px; }
.dist-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* sparkline */
.spark { display: flex; align-items: flex-end; gap: 5px; height: 90px; padding-top: 8px; }
.spark .bar { flex: 1; background: var(--primary-soft); border-radius: 5px 5px 3px 3px; position: relative; min-height: 3px; }
.spark .bar > i { position: absolute; inset: auto 0 0; background: var(--primary); border-radius: 5px 5px 3px 3px; }
.spark-labels { display: flex; gap: 5px; margin-top: 6px; }
.spark-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--faint); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: none;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--paper);
  position: sticky; top: 0; cursor: default; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--ink); }
thead th .arrow { color: var(--primary); font-size: 11px; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--primary-soft); }
tbody tr:last-child td { border-bottom: none; }
.word-cell { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }

/* pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-domain { background: var(--raised); color: var(--muted); }
.pill-d1 { background: var(--green-soft); color: var(--green); }
.pill-d2 { background: var(--primary-soft); color: var(--primary-deep); }
.pill-d3 { background: #F3ECFB; color: #7A47C2; }
.pill-tier-full { background: var(--primary-soft); color: var(--primary-deep); }
.pill-tier-feed { background: var(--raised); color: var(--muted); }
.dot-audio { color: var(--green); font-weight: 700; }
.dot-no { color: var(--faint); }

/* ---- Toolbar / filters ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); }
.search-box input {
  width: 100%; padding: 10px 12px 10px 36px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--white); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
select.filter, input.filter {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--white); outline: none; color: var(--ink);
}
select.filter:focus { border-color: var(--primary); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px 0; color: var(--muted); font-size: 13px; }
.pagination .pages { display: flex; gap: 8px; align-items: center; }

.empty { text-align: center; padding: 50px 20px; color: var(--faint); }
.empty svg { width: 34px; height: 34px; opacity: .5; margin-bottom: 8px; }

/* ---- Drawer (word editor) ---- */
.scrim { position: fixed; inset: 0; background: rgba(25,25,24,.35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 560px; max-width: 94vw; background: var(--white);
  border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(25,25,24,.12); z-index: 50;
  transform: translateX(100%); transition: transform .24s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-head h3 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.drawer-head .id { font-size: 12px; color: var(--faint); font-family: ui-monospace, monospace; }
.drawer-close { border: none; background: var(--raised); width: 32px; height: 32px; border-radius: 8px; color: var(--muted); font-size: 18px; line-height: 1; }
.drawer-close:hover { background: var(--line); }
.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; background: var(--paper); }
.drawer-foot .spacer { flex: 1; }
.save-note { font-size: 13px; color: var(--green); opacity: 0; transition: opacity .2s; }
.save-note.show { opacity: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row { margin-bottom: 14px; }
.form-row.full { grid-column: 1 / -1; }
.form-row label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); outline: none; transition: border-color .15s, box-shadow .15s; resize: vertical;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--white);
}
.form-row .hint { font-size: 11px; color: var(--faint); margin-top: 4px; }
.section-label { font-size: 13px; font-weight: 700; margin: 22px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }

/* question editor cards */
.q-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; background: var(--paper); }
.q-card .q-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.q-type-pill { font-size: 11px; font-weight: 700; color: var(--primary-deep); background: var(--primary-soft); padding: 2px 8px; border-radius: 6px; }
.q-card textarea, .q-card input { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); margin-bottom: 7px; outline: none; }
.q-card textarea:focus, .q-card input:focus { border-color: var(--primary); }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.opt-row input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; }
.opt-row input[type=text] { margin-bottom: 0; }
.q-del { border: none; background: transparent; color: var(--error); font-size: 12px; font-weight: 600; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--error); }

.loading { padding: 40px; text-align: center; color: var(--faint); font-size: 14px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--primary); border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* set editor chips */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-soft); color: var(--primary-deep);
  padding: 5px 6px 5px 11px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.chip button { border: none; background: transparent; color: var(--primary-deep); font-size: 15px; line-height: 1; padding: 0 3px; }
.set-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; background: var(--white); box-shadow: var(--shadow); }
.set-card .date { font-weight: 700; font-size: 15px; }
.set-card .today { font-size: 11px; color: var(--primary-deep); background: var(--primary-soft); padding: 1px 7px; border-radius: 6px; margin-left: 8px; }
.autocomplete { position: relative; }
.ac-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); margin-top: 4px; max-height: 240px; overflow-y: auto; z-index: 5; }
.ac-item { padding: 9px 12px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; }
.ac-item:hover { background: var(--primary-soft); }
.ac-item .ac-def { color: var(--faint); font-size: 12px; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
