/* ASBData Campaign Console
   Light by default, dark on request. Palette derives from the platform's
   own primary (#132563). Numbers are always monospaced: in an ops tool,
   magnitude must be readable at a glance and columns must align. */

@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&display=swap');

/* ---- light (default) ---- */
:root {
  --bg:       #F6F7FB;
  --surface:  #FFFFFF;
  --raised:   #F2F4F9;
  --line:     #E2E6EF;
  --line-soft:#EDF0F6;
  --brand:    #2E4EA8;
  --brand-ink:#FFFFFF;
  --text:     #131A2A;
  --dim:      #58627C;
  --faint:    #8892A8;
  --track:    #E7EAF2;

  --amber:    #A96A0C;
  --amber-bg: rgba(169,106,12,.08);
  --teal:     #0E7C66;
  --teal-bg:  rgba(14,124,102,.09);
  --rose:     #C0394A;
  --rose-bg:  rgba(192,57,74,.08);
  --violet:   #5B4BB8;

  --shadow:   0 1px 2px rgba(19,26,42,.05), 0 1px 1px rgba(19,26,42,.04);
  --r: 7px;
  color-scheme: light;
}

/* ---- dark ---- */
[data-theme="dark"] {
  --bg:       #0B1020;
  --surface:  #131B2E;
  --raised:   #1A2439;
  --line:     #26314C;
  --line-soft:#1E2740;
  --brand:    #4467C8;
  --brand-ink:#FFFFFF;
  --text:     #E7ECF6;
  --dim:      #93A0BC;
  --faint:    #66738F;
  --track:    #0E1526;

  --amber:    #E0A24A;
  --amber-bg: rgba(224,162,74,.10);
  --teal:     #3FC5A6;
  --teal-bg:  rgba(63,197,166,.12);
  --rose:     #E87180;
  --rose-bg:  rgba(232,113,128,.12);
  --violet:   #9585E0;

  --shadow:   0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: 'DM Sans', sans-serif; letter-spacing: -0.018em; margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }

.num, .mono {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- shell */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: 214px; flex: 0 0 214px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand { padding: 18px 18px 16px; border-bottom: 1px solid var(--line); }
.brand b {
  font-size: 15px; font-weight: 700; letter-spacing: -0.02em;
  display: block; color: var(--text);
}
.brand span {
  font-size: 10.5px; color: var(--faint);
  letter-spacing: .1em; text-transform: uppercase;
}

.nav { padding: 10px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--r);
  color: var(--dim); font-size: 13px; font-weight: 500;
}
.nav a:hover { background: var(--raised); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] {
  background: var(--raised); color: var(--text); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--brand);
}
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }

.rail-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }
.rail-foot b { color: var(--dim); font-weight: 600; display: block; }

.main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .sub { color: var(--dim); font-size: 12.5px; margin-top: 2px; }

.wrap { padding: 22px 26px 60px; max-width: 1120px; }

/* --------------------------------------------------- theme toggle */

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--dim); cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--raised); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun  { display: none; }
[data-theme="dark"] .theme-toggle .moon { display: block; }

/* ---------------------------------------------------------- panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  margin-bottom: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.panel > header {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.panel > header .hint { color: var(--faint); font-size: 12px; font-weight: 400; }
.panel .body { padding: 16px; }
.panel .body.tight { padding: 0; }

/* ------------------------------------------------------ stat strip */

.strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); }
.strip .cell { background: var(--surface); padding: 14px 16px; }
.strip .k { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
.strip .v {
  font-family: 'DM Mono', monospace; font-size: 24px; font-weight: 500;
  margin-top: 4px; font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------- meters */

.meter-row { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); }
.meter-row:last-child { border-bottom: 0; }
.meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.meter-head .lbl { font-size: 13px; font-weight: 600; }
.meter-head .cnt { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

.meter { height: 7px; border-radius: 4px; background: var(--track); display: flex; overflow: hidden; }
.meter i { display: block; height: 100%; }
.meter i.sent    { background: var(--teal); }
.meter i.sending { background: var(--violet); }
.meter i.failed  { background: var(--rose); }
.meter i.pending { background: var(--faint); opacity: .35; }

.legend { display: flex; gap: 14px; margin-top: 7px; font-size: 11.5px; color: var(--faint); flex-wrap: wrap; }
.legend b { font-family: 'DM Mono', monospace; font-weight: 500; color: var(--dim); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* --------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); font-weight: 600;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--raised);
}
td { padding: 11px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--raised); }
td.n, th.n { text-align: right; font-family: 'DM Mono', monospace; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- chips */

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.draft     { color: var(--faint); border-color: var(--line); background: var(--raised); }
.chip.queued    { color: var(--amber); border-color: var(--amber); background: var(--amber-bg); }
.chip.running   { color: var(--teal);  border-color: var(--teal);  background: var(--teal-bg); }
.chip.paused    { color: var(--violet);border-color: var(--violet);background: transparent; }
.chip.completed { color: var(--dim);   border-color: var(--line);  background: var(--raised); }
.chip.failed    { color: var(--rose);  border-color: var(--rose);  background: var(--rose-bg); }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-family: 'DM Mono', monospace; font-size: 11px;
  background: var(--raised); border: 1px solid var(--line); color: var(--dim);
}

/* --------------------------------------------------------- forms */

label { display: block; font-size: 12px; font-weight: 600; color: var(--dim); margin-bottom: 5px; }
label .opt { font-weight: 400; color: var(--faint); }

input[type=text], input[type=password], input[type=number],
input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  font-family: inherit; font-size: 13.5px;
}
textarea { min-height: 130px; resize: vertical; font-family: 'DM Mono', monospace; font-size: 12.5px; line-height: 1.6; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(46,78,168,.18);
}
.field { margin-bottom: 15px; }
.field .help { font-size: 11.5px; color: var(--faint); margin-top: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--raised); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--rose); border-color: var(--rose); }
.btn.danger:hover { background: var(--rose-bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btnrow { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.btnrow form { margin: 0; }

/* -------------------------------------------------------- notices */

.notice { padding: 11px 14px; border-radius: var(--r); margin-bottom: 16px; font-size: 13px; border: 1px solid; }
.notice.ok   { color: var(--teal);  border-color: var(--teal);  background: var(--teal-bg); }
.notice.warn { color: var(--amber); border-color: var(--amber); background: var(--amber-bg); }
.notice.err  { color: var(--rose);  border-color: var(--rose);  background: var(--rose-bg); }

.empty { padding: 44px 20px; text-align: center; color: var(--faint); }
.empty p { margin: 0 0 14px; }

/* ------------------------------------------------- the send gate
   The one loud element. Sending is irreversible and expensive, so the
   control that arms it states scale, duration and cost, and will not
   unlock until the operator types the recipient count. */

.gate {
  border: 1px solid var(--amber); border-radius: var(--r);
  background: var(--amber-bg); margin-bottom: 18px;
}
.gate > header {
  padding: 12px 16px; border-bottom: 1px solid var(--amber);
  display: flex; align-items: center; justify-content: space-between; gap: 9px;
}
.gate > header b { font-size: 13px; font-weight: 700; color: var(--amber); }
.gate .body { padding: 16px; }

.gate .facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; margin-bottom: 15px;
}
.gate .facts div { background: var(--surface); padding: 12px 14px; }
.gate .facts .k { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
.gate .facts .v { font-family: 'DM Mono', monospace; font-size: 19px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.gate .facts .v.warn { color: var(--amber); }

.gate .confirm { display: flex; gap: 9px; align-items: flex-start; flex-wrap: wrap; }
.gate .confirm input { max-width: 220px; font-family: 'DM Mono', monospace; }

/* -------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; position: relative; }
.login-page .theme-toggle { position: absolute; top: 20px; right: 20px; }
.login-card { width: 100%; max-width: 372px; }
.login-card .mark { margin-bottom: 22px; }
.login-card .mark b { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; display: block; }
.login-card .mark span { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.login-card .panel .body { padding: 20px; }
.login-foot { margin-top: 16px; font-size: 11.5px; color: var(--faint); line-height: 1.6; }

/* ------------------------------------------------------ utilities */

.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.muted { color: var(--dim); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.stack > * + * { margin-top: 14px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code {
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; white-space: pre-wrap; max-height: 220px; overflow: auto;
  font-family: 'DM Mono', monospace; font-size: 12px;
}

@media (max-width: 860px) {
  .rail { position: fixed; transform: translateX(-100%); z-index: 30; transition: transform .18s; }
  .rail.open { transform: none; }
  .strip { grid-template-columns: repeat(2, 1fr); }
  .grid2, .gate .facts { grid-template-columns: 1fr; }
  .wrap, .topbar { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------------------------------------------------ user picker */

.picker { position: relative; }

.picker-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: 0 8px 24px rgba(19,26,42,.14);
  max-height: 320px; overflow-y: auto;
}
[data-theme="dark"] .picker-results { box-shadow: 0 10px 30px rgba(0,0,0,.5); }

.picker-row {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line-soft);
  background: transparent; color: var(--text); cursor: pointer;
  font-family: inherit; font-size: 13px;
}
.picker-row:last-child { border-bottom: 0; }
.picker-row:hover { background: var(--raised); }
.picker-row.on { background: var(--teal-bg); box-shadow: inset 3px 0 0 var(--teal); }
.picker-row.on .pr-main::after { content: ' ✓'; color: var(--teal); font-weight: 700; }
.picker-row .pr-sub { font-size: 11.5px; color: var(--faint); }

.picker-empty { padding: 12px; font-size: 12.5px; color: var(--faint); }

.picked { display: flex; flex-wrap: wrap; gap: 6px; }
.picked-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 10px; border-radius: 20px;
  background: var(--teal-bg); border: 1px solid var(--teal);
  color: var(--teal); font-size: 12px; font-weight: 600;
}
.picked-chip button {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px; opacity: .7;
}
.picked-chip button:hover { opacity: 1; }

#filterBlock { transition: opacity .15s; }

/* ------------------------------------------------------- editor */

#editorToolbar.ql-toolbar {
  border: 1px solid var(--line) !important;
  border-bottom: 0 !important;
  border-radius: var(--r) var(--r) 0 0;
  background: var(--raised);
}
#editor .ql-container,
#editor.ql-container {
  border: 1px solid var(--line) !important;
  border-radius: 0 0 var(--r) var(--r);
  background: var(--surface);
  font-family: 'DM Sans', sans-serif;
  font-size: 14.5px;
  min-height: 220px;
}
#editor .ql-editor { min-height: 220px; color: var(--text); line-height: 1.65; }
#editor .ql-editor.ql-blank::before { color: var(--faint); font-style: normal; }
#editor .ql-editor h2 { font-size: 19px; font-weight: 600; margin: 0 0 10px; }
#editor .ql-editor h3 { font-size: 16px; font-weight: 600; margin: 14px 0 8px; }
#editor .ql-editor blockquote {
  border-left: 3px solid var(--brand); padding: 8px 14px;
  background: var(--raised); margin: 0 0 12px; color: var(--dim);
}

/* Quill draws its icons with currentColor-less strokes, so they need
   explicit values to survive the dark theme. */
.ql-toolbar .ql-stroke { stroke: var(--dim); }
.ql-toolbar .ql-fill   { fill: var(--dim); }
.ql-toolbar .ql-picker-label { color: var(--dim); }
.ql-toolbar button:hover .ql-stroke,
.ql-toolbar button.ql-active .ql-stroke { stroke: var(--brand); }
.ql-toolbar button:hover .ql-fill,
.ql-toolbar button.ql-active .ql-fill { fill: var(--brand); }
.ql-toolbar button.ql-active .ql-picker-label,
.ql-toolbar .ql-picker-label:hover { color: var(--brand); }
.ql-picker-options {
  background: var(--surface) !important;
  border-color: var(--line) !important;
  color: var(--text);
}
.ql-picker-item { color: var(--dim); }
.ql-picker-item:hover { color: var(--text); }
.ql-tooltip {
  background: var(--surface) !important;
  border-color: var(--line) !important;
  box-shadow: 0 6px 20px rgba(0,0,0,.18) !important;
  color: var(--text) !important;
}
.ql-tooltip input[type=text] {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}

/* ------------------------------------------- whatsapp variables */

.wa-var {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 7px;
}
.wa-var-n {
  flex: 0 0 auto; min-width: 46px;
  padding: 5px 8px; border-radius: 4px;
  background: var(--raised); border: 1px solid var(--line);
  color: var(--dim); font-size: 11.5px; text-align: center;
}
.wa-var input { flex: 1; }
.wa-var button { flex: 0 0 auto; }

/* ------------------------------------------------ button loading */

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
/* the spinner has to be visible against a filled button too */
.btn.is-loading::after { border-color: var(--dim); border-top-color: transparent; }
.btn.primary.is-loading::after { border-color: var(--brand-ink); border-top-color: transparent; }

.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.is-loading:disabled { opacity: 1; }

@keyframes btn-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .btn.is-loading::after { animation: none; border-top-color: currentColor; opacity: .5; }
}
