:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --text: #1c2033;
  --muted: #6b7185;
  --line: #e6e8ef;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --ok: #12a150;
  --ok-soft: #e7f7ee;
  --warn: #c27a00;
  --warn-soft: #fff4dc;
  --bad: #d93a3a;
  --bad-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --side: #151a2e;
  --side-text: #aab0c6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
p { margin: 0 0 10px; }

.boot { height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(99,102,241,.22); color: #fff; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6c7392; padding: 14px 10px 6px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: 20px; padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side-foot .email { color: #fff; word-break: break-all; }

.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn.menu-btn { display: none; padding: 4px 8px; }
.btn.menu-btn svg { width: 18px; height: 18px; }

.banner { background: var(--warn-soft); color: #6b4500; border: 1px solid #f3dca6; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-family: 'Inter', sans-serif; }
.kpi .sub { color: var(--muted); font-size: 12px; }

/* forms */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: #3b4157; }
.field .hint { font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid #d5d9e3; border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.filters input, .filters select { width: auto; min-width: 140px; }
textarea { min-height: 80px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; min-height: 0; }

.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d5d9e3; background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 38px; white-space: nowrap; }
.btn:hover { background: #f7f8fb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: 'Inter', sans-serif; }
tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; background: #fafbfc; border-top: 1px solid var(--line); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eef0f4; color: #4a5068; white-space: nowrap; }
.badge.ok, .badge.approve, .badge.sent, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.hold, .badge.pending, .badge.unknown { background: var(--warn-soft); color: var(--warn); }
.badge.reject, .badge.trash, .badge.failed, .badge.error, .badge.token_error { background: var(--bad-soft); color: var(--bad); }
.badge.skipped, .badge.other, .badge.paused { background: #eef0f4; color: #4a5068; }
.badge.info { background: var(--info-soft); color: var(--info); }

.copy { display: flex; gap: 6px; align-items: stretch; }
.copy input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: #fafbfc; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err-text { color: var(--bad); font-size: 12.5px; word-break: break-word; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pager { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 14px; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 0 0 18px 44px; }
.steps li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; display: grid; place-items: center; font-family: 'Inter', sans-serif; }
.note { background: var(--info-soft); color: #1e40af; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); color: #6b4500; }
pre.json { background: #0f1424; color: #d4d8e8; padding: 10px; border-radius: 8px; font-size: 12px; max-width: 520px; overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-all; }
details summary { cursor: pointer; color: var(--brand); font-size: 12.5px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 36, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px 6px; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1c2033; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; font-size: 13.5px; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate .card { max-width: 440px; text-align: center; padding: 32px 28px; }
.gate .brand-logo { margin: 0 auto 14px; width: 46px; height: 46px; border-radius: 12px; }

.chart-box { position: relative; height: 260px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .grid-2, .row { grid-template-columns: 1fr; }
  .filters .field { flex: 1 1 140px; }
  .filters input, .filters select { min-width: 0; width: 100%; }
}
