:root {
  --bg: #FBFAF9; --surface: #FFFFFF; --surface-2: #F5F2ED; --surface-3: #EFEBE3;
  --border: #E7E2DA; --border-strong: #D7D0C4;
  --text: #211C15; --muted: #6E665A; --faint: #98907F;
  --primary: #5B54D6; --primary-hover: #4a44c4; --on-primary: #ffffff; --primary-soft: #ECEBFB;
  --success: #2F9E5B; --success-soft: #E4F3E9; --success-text: #1c7a41;
  --warning: #B0781E; --warning-soft: #F6ECD8;
  --danger: #CB4B36; --danger-hover: #b6402d; --danger-soft: #FAE9E5;
  --ring: rgba(91, 84, 214, .30);
  --shadow-sm: 0 1px 2px rgba(30, 25, 18, .06);
  --shadow-md: 0 4px 14px -6px rgba(30, 25, 18, .14), 0 1px 2px rgba(30, 25, 18, .05);
  --shadow-lg: 0 24px 48px -20px rgba(30, 25, 18, .30), 0 6px 16px -10px rgba(30, 25, 18, .20);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 9px; --r-sm: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210; --surface: #1E1B16; --surface-2: #252017; --surface-3: #2C261C;
    --border: #332D25; --border-strong: #423B30;
    --text: #F2EEE6; --muted: #A79D8D; --faint: #7B7263;
    --primary: #8B84F2; --primary-hover: #9c96f5; --on-primary: #16130d; --primary-soft: #292640;
    --success: #5EBD7D; --success-soft: #1C3025; --success-text: #7fd39a;
    --warning: #D6A44A; --warning-soft: #33280f;
    --danger: #E56C57; --danger-hover: #ea7c69; --danger-soft: #3A231E;
    --ring: rgba(139, 132, 242, .38);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
    --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, .55), 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 30px 60px -22px rgba(0, 0, 0, .7), 0 8px 20px -12px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="light"] {
  --bg: #FBFAF9; --surface: #FFFFFF; --surface-2: #F5F2ED; --surface-3: #EFEBE3;
  --border: #E7E2DA; --border-strong: #D7D0C4;
  --text: #211C15; --muted: #6E665A; --faint: #98907F;
  --primary: #5B54D6; --primary-hover: #4a44c4; --on-primary: #ffffff; --primary-soft: #ECEBFB;
  --success: #2F9E5B; --success-soft: #E4F3E9; --success-text: #1c7a41;
  --warning: #B0781E; --warning-soft: #F6ECD8;
  --danger: #CB4B36; --danger-hover: #b6402d; --danger-soft: #FAE9E5;
  --ring: rgba(91, 84, 214, .30);
  --shadow-sm: 0 1px 2px rgba(30, 25, 18, .06);
  --shadow-md: 0 4px 14px -6px rgba(30, 25, 18, .14), 0 1px 2px rgba(30, 25, 18, .05);
  --shadow-lg: 0 24px 48px -20px rgba(30, 25, 18, .30), 0 6px 16px -10px rgba(30, 25, 18, .20);
}
:root[data-theme="dark"] {
  --bg: #141210; --surface: #1E1B16; --surface-2: #252017; --surface-3: #2C261C;
  --border: #332D25; --border-strong: #423B30;
  --text: #F2EEE6; --muted: #A79D8D; --faint: #7B7263;
  --primary: #8B84F2; --primary-hover: #9c96f5; --on-primary: #16130d; --primary-soft: #292640;
  --success: #5EBD7D; --success-soft: #1C3025; --success-text: #7fd39a;
  --warning: #D6A44A; --warning-soft: #33280f;
  --danger: #E56C57; --danger-hover: #ea7c69; --danger-soft: #3A231E;
  --ring: rgba(139, 132, 242, .38);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow-md: 0 6px 18px -8px rgba(0, 0, 0, .55), 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 30px 60px -22px rgba(0, 0, 0, .7), 0 8px 20px -12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
::selection { background: var(--primary-soft); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
svg { display: block; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-radius: var(--r-sm); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font-weight: 800; font-size: 14px; box-shadow: var(--shadow-sm);
}
.brand small { color: var(--muted); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; font-size: 11px; margin-left: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px;
  border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 550; font-size: 13px; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--success-text); background: var(--success-soft); }
.pill.off { color: var(--muted); background: var(--surface-3); }

.label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.field-help { color: var(--muted); font-size: 12px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], textarea, select {
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 13.5px; transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 78px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); }

.switch { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); transition: background .15s; flex: none; border: none; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .16s; }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login__aside {
  position: relative; overflow: hidden; padding: 44px;
  background: radial-gradient(120% 120% at 12% 8%, color-mix(in srgb, var(--primary) 22%, var(--bg)) 0%, transparent 55%), linear-gradient(180deg, var(--surface-2), var(--bg));
  border-right: 1px solid var(--border); display: flex; flex-direction: column; justify-content: space-between;
}
.login__aside .glyph { position: absolute; right: -60px; bottom: -70px; width: 360px; height: 360px; opacity: .5; color: color-mix(in srgb, var(--primary) 30%, transparent); }
.login__aside h2 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; max-width: 15ch; margin-top: 26px; }
.login__aside p { color: var(--muted); max-width: 34ch; margin: 14px 0 0; }
.login__aside ul { list-style: none; padding: 0; margin: 26px 0 0; display: flex; flex-direction: column; gap: 11px; }
.login__aside li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.login__aside li svg { width: 17px; height: 17px; color: var(--primary); flex: none; }
.login__note { color: var(--faint); font-size: 12px; }
.login__main { display: grid; place-items: center; padding: 32px; }
.login__card { width: 100%; max-width: 350px; }
.login__card h1 { font-size: 21px; letter-spacing: -.01em; }
.login__card > p { color: var(--muted); margin: 6px 0 26px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.pw-wrap { position: relative; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); height: 28px; width: 30px; display: grid; place-items: center; border: none; background: transparent; color: var(--muted); border-radius: var(--r-sm); }
.pw-wrap button:hover { color: var(--text); background: var(--surface-2); }
.login__err { color: var(--danger); font-size: 12.5px; margin: 2px 0 12px; }
.login__foot { margin-top: 20px; color: var(--faint); font-size: 12px; text-align: center; }

/* ---- app shell ---- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.crumbs { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.crumbs .sep { color: var(--faint); }
.crumbs .cur { color: var(--text); font-weight: 600; }
.topbar .spacer { flex: 1; }
.iconbtn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.iconbtn:hover { color: var(--text); background: var(--surface-2); }
.iconbtn svg { width: 17px; height: 17px; }
.user { display: flex; align-items: center; gap: 9px; padding: 3px 10px 3px 3px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.user:hover { background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--on-primary); background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 60%, #d06)); }
.user .who { line-height: 1.1; text-align: left; }
.user .who b { font-size: 12.5px; font-weight: 600; }
.user .who small { display: block; color: var(--muted); font-size: 11px; }

.shell { display: flex; flex: 1; min-height: 0; }
.side { width: 226px; flex: none; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; padding: 14px 10px; }
.side .group { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); font-weight: 700; padding: 8px 10px 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); color: var(--text); border: none; background: transparent; font-weight: 500; font-size: 13.5px; width: 100%; text-align: left; }
.nav button svg { width: 17px; height: 17px; color: var(--faint); flex: none; }
.nav button .count { margin-left: auto; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav button:hover { background: var(--surface-2); }
.nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav button.active svg, .nav button.active .count { color: var(--primary); }
.side .foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--border); color: var(--faint); font-size: 11.5px; display: flex; align-items: center; justify-content: space-between; }

.main { flex: 1; min-width: 0; overflow: auto; }
.page { max-width: 1120px; margin: 0 auto; padding: 24px 26px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; letter-spacing: -.02em; }
.page-head p { color: var(--muted); font-size: 13px; margin: 3px 0 0; }
.page-head .spacer { flex: 1; }

.board { display: grid; grid-template-columns: 1fr 224px; gap: 18px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-bottom: 1px solid var(--border); }
.toolbar .count { color: var(--muted); font-size: 12.5px; }
.toolbar .count b { color: var(--text); font-variant-numeric: tabular-nums; }
.listsearch { display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); width: 210px; }
.listsearch svg { width: 14px; height: 14px; color: var(--muted); flex: none; }
.listsearch input { border: none; background: transparent; padding: 0; height: 100%; font-size: 13px; }
.listsearch input:focus { box-shadow: none; }

.bulkbar { display: flex; align-items: center; gap: 12px; padding: 9px 13px; background: var(--primary-soft); border-bottom: 1px solid var(--border); color: var(--primary); font-size: 13px; font-weight: 550; }

table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 9px 13px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; }
thead th.chk, tbody td.chk { width: 38px; padding-right: 0; }
tbody td { padding: 11px 13px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.sel { background: color-mix(in srgb, var(--primary-soft) 60%, var(--surface)); }
td .cell-title { font-weight: 600; }
td .id { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { visibility: hidden; }
tbody tr:hover td.actions .btn { visibility: visible; }
.cellmuted { color: var(--muted); }
.who-cell { display: flex; align-items: center; gap: 8px; }
.who-cell .av { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: var(--on-primary); background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 55%, #c60)); flex: none; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 30px; height: 30px; color: var(--faint); margin: 0 auto 10px; }

.tablefoot { display: flex; align-items: center; gap: 12px; padding: 10px 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }
.tablefoot .spacer { flex: 1; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager button { min-width: 30px; height: 30px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); font-size: 12.5px; display: grid; place-items: center; }
.pager button:hover:not(:disabled) { background: var(--surface-2); }
.pager button[aria-current="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager svg { width: 15px; height: 15px; }

.filters h3 { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 12px 14px 8px; }
.filters .fgroup { padding: 2px 8px 10px; }
.filters .fgroup .cap { font-size: 12px; font-weight: 600; padding: 4px 6px; }
.filters button.opt { display: flex; width: 100%; align-items: center; gap: 8px; padding: 6px 8px; border: none; background: transparent; border-radius: var(--r-sm); font-size: 13px; color: var(--muted); text-align: left; }
.filters button.opt:hover { background: var(--surface-2); color: var(--text); }
.filters button.opt.on { color: var(--primary); font-weight: 600; }
.filters button.opt .tick { width: 15px; height: 15px; opacity: 0; color: var(--primary); flex: none; }
.filters button.opt.on .tick { opacity: 1; }
.filters .clear { margin: 4px 10px; }

/* ---- drawer ---- */
.scrim { position: fixed; inset: 0; background: rgba(20, 16, 10, .42); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.show { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 94vw; z-index: 50; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform .24s cubic-bezier(.4, 0, .2, 1); display: flex; flex-direction: column; }
.drawer.show { transform: translateX(0); }
.drawer__head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer__head h2 { font-size: 16px; letter-spacing: -.01em; }
.drawer__head .sub { color: var(--muted); font-size: 12px; }
.drawer__head .spacer { flex: 1; }
.drawer__body { padding: 18px; overflow: auto; flex: 1; }
.fieldset { border: 1px solid var(--border); border-radius: var(--r); padding: 15px; margin: 0 0 16px; }
.fieldset legend { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 0 6px; }
.frow { margin-bottom: 14px; }
.frow:last-child { margin-bottom: 0; }
.frow > label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 5px; }
.frow .req { color: var(--danger); }
.frow .togglerow { display: flex; align-items: center; gap: 10px; }
.frow.err input, .frow.err textarea, .frow.err select { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.frow .msg { color: var(--danger); font-size: 12px; margin-top: 5px; }
.selectwrap { position: relative; }
.selectwrap svg { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
select { appearance: none; padding-right: 30px; }
.drawer__foot { display: flex; align-items: center; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer__foot .spacer { flex: 1; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 550; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast svg { width: 16px; height: 16px; }
.toast svg.ok { color: var(--success); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login__aside { display: none; }
  .board { grid-template-columns: 1fr; }
  .filters { order: -1; }
  .side { display: none; }
}
