/* TG Media Sync admin panel - Calm Admin (zero external assets) */
:root {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-low: #f2f4f6;
  --surface-mid: #eceef0;
  --text: #191c1e;
  --muted: #434655;
  --outline: #737686;
  --line: #e6e8ea;
  --primary: #2563eb;
  --primary-dark: #004ac6;
  --primary-soft: #dbe1ff;
  --green: #047857;
  --green-soft: #d1fae5;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #ba1a1a;
  --red-soft: #ffdad6;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --font: Inter, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  min-width: 1100px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--outline); }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: 220px;
  background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: space-between; z-index: 50;
}
.brand { height: 64px; padding: 12px 16px 0; }
.brand-row { display: flex; align-items: center; justify-content: space-between; }
.brand-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; }
.dot.green { background: #10b981; }
.dot.amber { background: #f59e0b; }
.dot.red { background: #ef4444; }
.ver { font-family: var(--mono); font-size: 10px; background: var(--surface-mid); color: var(--muted); padding: 1px 6px; border-radius: 4px; }
.engine-line { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.nav-caption { font-size: 10px; font-weight: 600; letter-spacing: .08em; color: var(--outline); padding: 14px 18px 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 13px; transition: background .12s;
}
.nav a:hover { background: var(--surface-mid); color: var(--text); }
.nav a.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav a .badge-count { margin-left: auto; background: var(--red-soft); color: var(--red); font-size: 10px; padding: 0 6px; border-radius: 999px; font-weight: 600; }
.nav a.active .badge-count { background: #fff; }
.sidebar-foot { margin: 8px; padding: 12px; background: var(--surface-low); border-radius: 8px; font-size: 11px; color: var(--muted); }
.sidebar-foot .row { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; margin-top: 2px; }
.sidebar-foot .row b { color: var(--text); }

.main { margin-left: 220px; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: 56px; padding: 0 24px;
  background: rgba(247, 249, 251, 0.92); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 8px;
  background: var(--surface); box-shadow: var(--shadow); font-size: 12px;
}
.content { padding: 24px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-sub { margin: 4px 0 0; color: var(--muted); }
.tag { font-family: var(--mono); font-size: 10px; letter-spacing: .06em; padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-dark); text-transform: uppercase; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 0; border-radius: 8px; background: var(--surface-mid); color: var(--text); cursor: pointer; font-size: 12px; font-weight: 500;
  white-space: nowrap; transition: filter .12s, background .12s;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 11px; border-radius: 6px; }
.btn.link { background: transparent; color: var(--primary-dark); padding: 0 6px; }
.btn.link:hover:not(:disabled) { text-decoration: underline; filter: none; }
.input, .select, .textarea {
  height: 34px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px; background: var(--surface-mid); outline: none; width: 100%;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 90px; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .label { font-size: 11px; font-weight: 600; color: var(--muted); }
.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch { position: relative; width: 34px; height: 18px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c3c6d7; border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }
.seg { display: inline-flex; background: var(--surface-mid); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--surface-mid); color: var(--muted); white-space: nowrap; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.blue { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Cards / tables ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .k-label { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.kpi .k-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .k-note { font-size: 11px; color: var(--outline); }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); padding: 10px 14px; background: var(--surface-low); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: #fafbfc; }
.tbl .right { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 32px; height: 32px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.name-cell .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.name-cell .s { font-size: 11px; color: var(--outline); font-family: var(--mono); }
.empty { padding: 36px; text-align: center; color: var(--outline); }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager button { min-width: 30px; height: 28px; border: 0; background: var(--surface-mid); border-radius: 6px; cursor: pointer; }
.pager button.active { background: var(--primary); color: #fff; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Account cards ---------- */
.acct { padding: 14px 16px; cursor: pointer; border-top: 3px solid transparent; transition: box-shadow .12s; }
.acct.selected { border-top-color: var(--primary); }
.acct.warn { border-top-color: #f59e0b; }
.acct.bad { border-top-color: #ef4444; }
.acct:hover { box-shadow: 0 2px 14px rgba(0, 0, 0, 0.09); }
.acct-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.acct-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 8px; }

/* ---------- Modal / drawer / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.38); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 12px; width: 520px; max-width: calc(100vw - 48px); max-height: calc(100vh - 64px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: 760px; }
.modal-head { padding: 16px 20px 8px; display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 8px 20px 16px; overflow: auto; }
.modal-foot { padding: 12px 20px; display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-low); border-radius: 0 0 12px 12px; }
.drawer-overlay { justify-content: flex-end; align-items: stretch; }
.drawer { background: #fff; width: 620px; max-width: 92vw; height: 100%; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0, 0, 0, .18); }
.drawer-body { padding: 8px 20px 16px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 20px; background: var(--surface-low); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 380px; font-size: 12px; }
.toast.error { background: #7f1d1d; }
.toast.ok { background: #065f46; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px; }
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 380px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }

/* ---------- Task builder ---------- */
.flow { display: grid; grid-template-columns: 1fr 120px 1fr; gap: 16px; align-items: stretch; }
.flow-arrow { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--primary-dark); background: var(--surface-low); border-radius: 10px; text-align: center; font-size: 11px; padding: 10px; }
.pane { background: var(--surface-low); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.pane h4 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.pick-list { max-height: 210px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.pick { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #fff; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.pick.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.pick.disabled { opacity: .55; cursor: not-allowed; background: var(--surface-mid); }
.pick.disabled .pick-title { text-decoration: line-through; }
.pick-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-meta { font-size: 11px; color: var(--outline); font-family: var(--mono); }
.pick .grow { flex: 1; min-width: 0; }
.opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }

/* ---------- Rules ---------- */
.rules-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.rules-layout > * { min-width: 0; }
.profile-item { padding: 12px; border-radius: 10px; cursor: pointer; background: var(--surface); box-shadow: var(--shadow); margin-bottom: 8px; border-left: 3px solid transparent; }
.profile-item.active { background: #eef2ff; border-left-color: var(--primary); }
.quick-add { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.quick-add .qa-pattern { grid-column: 1 / -1; }
.verdict { padding: 12px; border-radius: 8px; margin-top: 10px; }
.verdict.skip { background: var(--red-soft); color: var(--red); }
.verdict.allow { background: var(--green-soft); color: var(--green); }
.verdict.review { background: var(--amber-soft); color: var(--amber); }
.feature-card { background: var(--surface-low); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.feature-card .ft { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }

/* ---------- Review ---------- */
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.cluster { padding: 16px 18px; margin-bottom: 14px; border-left: 4px solid var(--red); }
.cluster.flag { border-left-color: var(--amber); }
.sample { background: var(--surface-low); border-radius: 8px; padding: 12px; margin: 10px 0; display: flex; gap: 12px; }
.sample img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; background: var(--surface-mid); flex: none; }
.sample .txt { overflow-wrap: anywhere; white-space: pre-wrap; max-height: 110px; overflow: auto; }
.cand { background: var(--surface-low); border-radius: 10px; padding: 12px; margin-bottom: 10px; }

/* ---------- Message picker ---------- */
.msg-row { display: flex; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--surface-low); margin-bottom: 8px; align-items: flex-start; }
.msg-row.sel { background: #eef2ff; }
.msg-row .body { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--surface-mid); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
