/* Quickmart Engage — admin (Perfex-grade shell, light mode) */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  /* chrome */
  --qm-red: #E4002B;
  --sidebar-bg: #1B2431;
  --sidebar-ink: #aeb9c4;
  --sidebar-active: #ffffff;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11,11,11,.10);
  /* viz (validated reference palette, light mode) */
  --series-1: #2a78d6;
  --seq-250: #86b6ef; --seq-350: #5598e7; --seq-450: #2a78d6; --seq-550: #1c5cab; --seq-650: #104281;
  --status-good: #0ca30c; --status-warn: #fab219; --status-serious: #ec835a; --status-critical: #d03b3b;
  --success-text: #006300;
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--ink); font-size: 14px; min-height: 100vh;
}
a { color: #1c5cab; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background:
  radial-gradient(900px 500px at 80% -10%, #ffe2e8 0%, var(--page) 55%); }
.login-card { width: 400px; max-width: 92vw; background: var(--surface); border: 1px solid var(--ring);
  border-radius: 14px; padding: 34px; box-shadow: 0 18px 50px rgba(27,36,49,.10); }
.login-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-card .logo { width: 44px; height: 44px; border-radius: 12px; background: var(--qm-red); color: #fff;
  font-weight: 800; font-size: 24px; display: flex; align-items: center; justify-content: center; }
.login-card h1 { font-size: 18px; }
.login-card h1 small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.login-card label { display: block; font-size: 12px; color: var(--ink-2); margin: 14px 0 5px; font-weight: 600; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--baseline); border-radius: 8px;
  font-size: 14px; font-family: inherit; outline: none; background: #fff; }
.login-card input:focus { border-color: var(--series-1); box-shadow: 0 0 0 3px rgba(42,120,214,.15); }
.login-card button { margin-top: 20px; width: 100%; padding: 11px; background: var(--qm-red); border: none;
  color: #fff; font-size: 14.5px; font-weight: 600; border-radius: 8px; cursor: pointer; font-family: inherit; }
.login-card button:hover { background: #c40025; }
.login-card .demo-creds { margin-top: 16px; font-size: 12.5px; color: var(--muted); background: var(--page);
  border: 1px dashed var(--baseline); padding: 10px 12px; border-radius: 8px; line-height: 1.6; }
.login-err { background: #fdeaea; color: #a12626; border: 1px solid #f2c4c4; padding: 9px 12px;
  border-radius: 8px; font-size: 13px; margin-bottom: 6px; }

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--sidebar-bg); color: var(--sidebar-ink); flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo-row { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; }
.sidebar .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--qm-red); color: #fff;
  font-weight: 800; font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar .logo-row .t { font-size: 14.5px; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar .logo-row .t small { display: block; font-size: 10.5px; color: var(--sidebar-ink); font-weight: 400; }
.sidebar .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: #5d6b7a;
  padding: 16px 18px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: 11px; padding: 9px 18px; color: var(--sidebar-ink);
  font-size: 13.5px; text-decoration: none; border-left: 3px solid transparent; transition: .12s; }
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .8; }
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(228,0,43,.14); color: var(--sidebar-active); border-left-color: var(--qm-red); }
.sidebar nav a .badge { margin-left: auto; background: var(--qm-red); color: #fff; font-size: 10.5px;
  border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.sidebar .foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #5d6b7a; line-height: 1.5; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--ring); padding: 0 26px; height: 56px;
  display: flex; align-items: center; gap: 18px; position: sticky; top: 0; z-index: 30; }
.topbar form.search { flex: 1; max-width: 430px; }
.topbar input[type=search] { width: 100%; padding: 8px 13px; border: 1px solid var(--grid); background: var(--page);
  border-radius: 8px; font-size: 13.5px; font-family: inherit; outline: none; }
.topbar input[type=search]:focus { border-color: var(--series-1); background: #fff; }
.topbar .spacer { flex: 1; }
.topbar .today { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.topbar .quick-links { display: flex; gap: 8px; }
.topbar .quick-links a { font-size: 12.5px; border: 1px solid var(--grid); padding: 6px 11px; border-radius: 8px;
  color: var(--ink-2); white-space: nowrap; }
.topbar .quick-links a:hover { border-color: var(--series-1); color: var(--series-1); text-decoration: none; }
.topbar .user { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.topbar .user .av { width: 32px; height: 32px; border-radius: 50%; background: var(--sidebar-bg); color: #fff;
  font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.topbar .user .nm { font-size: 13px; font-weight: 600; }
.topbar .user .rl { font-size: 11px; color: var(--muted); display: block; }

.content { padding: 24px 26px 40px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 700; }
.page-head .actions { display: flex; gap: 9px; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; }
.card .card-h { padding: 14px 18px; border-bottom: 1px solid var(--grid); display: flex; align-items: center;
  justify-content: space-between; gap: 10px; }
.card .card-h h2 { font-size: 14px; font-weight: 700; }
.card .card-h .sub { font-size: 12px; color: var(--muted); }
.card .card-b { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.g-6 { grid-template-columns: repeat(6, 1fr); }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-1-1 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1200px) { .g-6 { grid-template-columns: repeat(3, 1fr); } .g-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) { .g-3, .g-2, .g-2-1, .g-1-1-1 { grid-template-columns: 1fr; } .g-6 { grid-template-columns: repeat(2, 1fr); } }

.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 15px 17px; }
.tile .k { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.1; }
.tile .d { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.tile .d .up { color: var(--success-text); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr:hover { background: #f4f6f2; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list a.rowlink { font-weight: 600; color: var(--ink); }
table.list a.rowlink:hover { color: #1c5cab; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.pill-gray { background: #f0efec; color: var(--ink-2); }
.pill-blue { background: #e3edfa; color: #1c5cab; }
.pill-green { background: #e2f4e2; color: var(--success-text); }
.pill-amber { background: #fdf1d7; color: #8a5f00; }
.pill-orange { background: #fde9e0; color: #9c3f1c; }
.pill-red { background: #fbe3e3; color: #9c2020; }
.pill-magenta { background: #fae5ee; color: #a03a68; }

.btn { display: inline-flex; align-items: center; gap: 7px; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid transparent; font-family: inherit;
  text-decoration: none !important; transition: .12s; }
.btn-primary { background: var(--qm-red); color: #fff; }
.btn-primary:hover { background: #c40025; }
.btn-outline { background: var(--surface); color: var(--ink-2); border-color: var(--baseline); }
.btn-outline:hover { border-color: var(--series-1); color: var(--series-1); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-green { background: var(--status-good); color: #fff; }
.btn-green:hover { filter: brightness(.92); }

.filters { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters select, .filters input[type=text], .filters input[type=search] {
  padding: 7px 11px; border: 1px solid var(--grid); border-radius: 8px; background: var(--surface);
  font-size: 13px; font-family: inherit; outline: none; }
.filters .count { font-size: 12.5px; color: var(--muted); margin-left: auto; }

.empty { padding: 34px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* engagement mini-meter */
.meter { width: 90px; height: 6px; background: var(--grid); border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--seq-450); border-radius: 4px; }
.meter-val { font-size: 12px; color: var(--ink-2); margin-left: 7px; font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.viz-root { color-scheme: light; }
.chart-note { font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.hbar-row { display: grid; grid-template-columns: 130px 1fr 58px; align-items: center; gap: 10px; margin: 9px 0; }
.hbar-row .lbl { font-size: 12.5px; color: var(--ink-2); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-row .track { height: 22px; display: flex; align-items: center; }
.hbar-row .bar { height: 16px; border-radius: 0 4px 4px 0; background: var(--seq-450); min-width: 2px; transition: .15s; }
.hbar-row:hover .bar { filter: brightness(1.08); }
.hbar-row .val { font-size: 12.5px; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
svg.linechart { width: 100%; height: auto; display: block; }
svg.linechart text { font-family: inherit; }
#viztip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px;
  padding: 6px 9px; border-radius: 7px; z-index: 99; opacity: 0; transition: opacity .1s; max-width: 260px; line-height: 1.45; }

/* WhatsApp transcript viewer inside admin */
.wa-view { background: #EFEAE2; border-radius: 10px; padding: 16px; max-height: 640px; overflow-y: auto; }
.wa-view .m { display: flex; margin-bottom: 6px; }
.wa-view .m.out { justify-content: flex-end; }
.wa-view .b { max-width: 72%; background: #fff; padding: 7px 10px 8px; border-radius: 8px; font-size: 13px;
  line-height: 1.45; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; color: #111B21; }
.wa-view .m.out .b { background: #D9FDD3; }
.wa-view .b .who { font-size: 11px; font-weight: 700; color: #008069; margin-bottom: 2px; }
.wa-view .b .who.camp { color: #d33f92; }
.wa-view .b .tm { display: block; text-align: right; font-size: 10.5px; color: #667781; margin-top: 3px; }
.wa-view .b .itag { display: inline-block; margin-top: 5px; font-size: 10.5px; background: rgba(0,0,0,.06);
  border-radius: 5px; padding: 1px 7px; color: #54656f; }
.wa-view .btns-note { font-size: 11px; color: #54656f; margin: 2px 0 8px; padding-left: 8px; }

/* campaign template preview bubble */
.tpl-preview { background: #EFEAE2; border-radius: 10px; padding: 18px; }
.tpl-preview .b { background: #fff; border-radius: 9px; max-width: 330px; padding: 9px 11px; font-size: 13.5px;
  line-height: 1.5; box-shadow: 0 1px 1px rgba(0,0,0,.1); white-space: pre-wrap; color: #111B21; }
.tpl-preview .btnrow { max-width: 330px; margin-top: 6px; display: flex; flex-direction: column; gap: 5px; }
.tpl-preview .btnrow span { background: #fff; border-radius: 8px; text-align: center; color: #00A5F4;
  font-size: 13.5px; font-weight: 500; padding: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.1); }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.fld label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.fld input, .fld select, .fld textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--baseline);
  border-radius: 8px; font-size: 13.5px; font-family: inherit; outline: none; background: #fff; }
.fld textarea { min-height: 90px; resize: vertical; }
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--series-1); box-shadow: 0 0 0 3px rgba(42,120,214,.13); }
.fld .help { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.flash { background: #e2f4e2; border: 1px solid #b5e2b5; color: var(--success-text); padding: 10px 14px;
  border-radius: 9px; font-size: 13px; margin-bottom: 16px; }

.timeline { list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--grid); margin-left: 8px; }
.timeline li:last-child { padding-bottom: 2px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--seq-450); border: 2px solid var(--surface); }
.timeline li .tl-t { font-size: 11px; color: var(--muted); }
.timeline li .tl-b { font-size: 13px; margin-top: 1px; }
.timeline li.ev-handover::before { background: var(--status-serious); }
.timeline li.ev-order::before { background: var(--status-good); }
.timeline li.ev-campaign::before { background: #d33f92; }
