:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --border: #e2dfd6;
  --text: #1d2321;
  --muted: #66706c;
  --accent: #0f5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --danger: #a3322a;
  --danger-soft: #f8e3e0;
  --bubble-in: #ffffff;
  --bubble-out: #dcf0e4;
  --chat-bg: #efeae1;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1a1f1e;
    --surface-2: #222826;
    --border: #2e3633;
    --text: #e7ece9;
    --muted: #93a09b;
    --accent: #4fb89c;
    --accent-ink: #0b1513;
    --accent-soft: #1d3530;
    --warn: #e7b25c;
    --warn-soft: #3a2e19;
    --danger: #f08a80;
    --danger-soft: #3d2220;
    --bubble-in: #232a28;
    --bubble-out: #1f4237;
    --chat-bg: #161b1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ico { width: 16px; height: 16px; fill: currentColor; flex: none; }
.count { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 4px; }

/* buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px;
  padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* header */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 18px; font-family: Georgia, "Times New Roman", serif;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: .1px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-actions form { margin: 0; }
.sync-pill { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; }
.venue {
  max-width: 1280px; margin: 0 auto; padding: 8px 16px 10px; display: flex; gap: 8px; align-items: flex-start;
  font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
.venue span { flex: 1 1 280px; }
.venue a { font-weight: 600; white-space: nowrap; }

/* layout */
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.tile:hover { border-color: var(--accent); }
.tile.active { border-color: var(--accent); background: var(--accent-soft); }
.tile .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.key .n { color: var(--accent); }
.tile.alert .n { color: var(--warn); }
.tile.zero { opacity: .55; }

/* shortlist cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; gap: 12px; background: var(--surface);
  cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%;
}
.card:hover { border-color: var(--accent); }
.card .meta { min-width: 0; flex: 1; }
.card .nm { font-weight: 650; }
.card .ph { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.card .rl { font-size: 13px; margin-top: 4px; }
.card .top { color: var(--muted); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.empty { color: var(--muted); padding: 12px 0; }

.avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: none; overflow: hidden; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 72px; height: 72px; font-size: 24px; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.fit { font-variant-numeric: tabular-nums; letter-spacing: 1px; color: var(--accent); }

/* filters & table */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.filters input[type=search] { flex: 1 1 220px; }
.filters select { flex: 0 1 180px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; max-height: 70vh; overflow-y: auto; }
table.grid { border-collapse: collapse; width: 100%; min-width: 900px; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.grid th {
  position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 650; color: var(--muted);
  cursor: pointer; user-select: none; white-space: nowrap; z-index: 1;
}
.grid th:hover { color: var(--text); }
.grid th.asc::after { content: " ▲"; font-size: 9px; }
.grid th.desc::after { content: " ▼"; font-size: 9px; }
.grid .num { text-align: right; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--accent-soft); }
.grid td.name { font-weight: 600; }
.grid td.name .wrapn { display: flex; gap: 8px; align-items: center; }
.grid td.phone { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.grid td.last { max-width: 300px; }
.grid td.last .t { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.grid td.slot { font-size: 12px; max-width: 180px; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface); z-index: 21;
  border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0, 0, 0, .12); display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .18s ease; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.drawer-head .who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.drawer-head h2 { font-size: 18px; }
.drawer-body { overflow-y: auto; padding: 14px 16px 40px; display: grid; gap: 12px; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.d-grid label, label.block { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.d-grid select, .d-grid input { width: 100%; color: var(--text); font-weight: 400; font-size: 14px; }
label.block textarea { font-weight: 400; font-size: 14px; }
.save-state { font-weight: 400; margin-left: 6px; }
.section { border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; }
.section > summary { cursor: pointer; padding: 10px 0; font-weight: 650; }
.section[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.section[open] { padding-bottom: 10px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.chat { background: var(--chat-bg); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }
.bubble { max-width: 85%; padding: 6px 10px 4px; border-radius: 10px; background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0, 0, 0, .06); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.school { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 3px; }
.bubble.candidate { align-self: flex-start; border-top-left-radius: 3px; }
.bubble .at { display: block; text-align: right; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.bubble.pending { opacity: .7; border: 1px dashed var(--muted); }

.composer { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: grid; gap: 8px; background: var(--surface-2); }
.composer textarea { background: var(--surface); }
.tpl-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.invite-fields { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.invite-fields label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.composer-foot { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.note { margin: 0; font-size: 12px; color: var(--muted); flex: 1 1 240px; }
.outbox { display: grid; gap: 6px; }
.ob-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; gap: 4px; }
.ob-item .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.ob-item .txt { white-space: pre-wrap; font-size: 13px; overflow-wrap: anywhere; }
.ob-item .btn { padding: 3px 9px; font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(150%); background: var(--text); color: var(--bg);
  padding: 9px 14px; border-radius: 8px; font-size: 13px; z-index: 40; transition: transform .2s ease; max-width: calc(100vw - 32px);
}
.toast.show { transform: translateX(-50%); }
.toast.err { background: var(--danger); color: #fff; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 24px; width: min(380px, 100%); display: grid; gap: 16px; }
.login-card form { display: grid; gap: 8px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--muted); }
.login-card .btn { justify-content: center; margin-top: 4px; padding: 9px; }
.login-error { margin: 0; background: var(--danger-soft); color: var(--danger); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

@media (max-width: 640px) {
  .wrap { padding: 12px; gap: 12px; }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tile { padding: 8px 10px; }
  .tile .n { font-size: 20px; }
  .tile .l { font-size: 11px; }
  .cards { grid-template-columns: 1fr; }
  .d-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dt { margin-top: 6px; }
  .drawer { border-left: 0; }
  .filters select { flex: 1 1 45%; }
  .topbar-actions .btn { padding: 5px 9px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { .drawer, .toast { transition: none; } }
