/* ==========================================================================
   MessageDesk admin interface
   ========================================================================== */

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f2f4f7;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;

  --brand: #0d7a63;
  --brand-hover: #0a6653;
  --brand-50: #e9f6f2;
  --brand-100: #cdebe2;
  --brand-ring: rgba(13, 122, 99, .22);

  --blue: #1d5fd1;   --blue-50: #eef4ff;  --blue-100: #d6e4ff;
  --green: #067647;  --green-50: #ecfdf3; --green-100: #d1fadf;
  --amber: #a15c07;  --amber-50: #fffaeb; --amber-100: #fef0c7;
  --red: #c01f28;    --red-50: #fef3f2;   --red-100: #fee4e2;
  --grey: #475467;   --grey-50: #f2f4f7;  --grey-100: #e4e7ec;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 8px 24px -6px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .05);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .22);

  --sidebar-w: 248px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
h1 { font-size: 22px; line-height: 1.3; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
[hidden] { display: none !important; }
.icon { flex-shrink: 0; vertical-align: middle; }
.icon-xs { width: 14px; height: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --- Shell ---------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 40;
  transition: width .18s ease;
}
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; transition: margin .18s ease; }
.content { padding: 28px 32px 48px; max-width: 1440px; width: 100%; margin: 0 auto; }

.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); display: block; font-weight: 500; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-section { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 16px 10px 6px; white-space: nowrap; }
.nav-section:first-child { padding-top: 4px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; margin: 1px 0;
  border-radius: var(--radius); color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.nav-link .icon { color: var(--muted); }
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active { background: var(--brand-50); color: var(--brand); }
.nav-link.active .icon { color: var(--brand); }
.nav-link.active::before { content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge { font-size: 11px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--grey-100); color: var(--grey); }
.nav-badge.blue { background: var(--blue-100); color: var(--blue); }
.nav-badge.red { background: var(--red-100); color: var(--red); }
.nav-badge.amber { background: var(--amber-100); color: var(--amber); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; }
.collapse-btn { width: 100%; justify-content: flex-start; }

body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-section, body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-badge, body.sidebar-collapsed .collapse-text { display: none; }
body.sidebar-collapsed .nav-link { justify-content: center; padding: 0; }
body.sidebar-collapsed .nav-section { height: 12px; }
body.sidebar-collapsed .sidebar-brand { padding: 0 18px; }
body.sidebar-collapsed .collapse-btn { justify-content: center; }
body.sidebar-collapsed .collapse-btn .icon { transform: scaleX(-1); }

/* --- Top bar -------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); background: rgba(255,255,255,.92);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
}
.btn.topbar-menu { display: none; }
.search-trigger {
  flex: 1; max-width: 460px; height: 38px; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted);
  cursor: pointer; font: inherit; text-align: left;
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--surface); }
.search-trigger span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger .kbd { flex: 0 0 auto; }
.kbd { font-family: var(--font); font-size: 11px; font-weight: 500; padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 17px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.status-pill:hover { border-color: var(--border-strong); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status-pill.sending .status-dot { background: #12b76a; box-shadow: 0 0 0 3px rgba(18,183,106,.18); animation: pulse 1.6s ease-in-out infinite; }
.status-pill.paused .status-dot { background: #f79009; }
.status-pill.offline .status-dot { background: #f04438; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(18,183,106,.08); } }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.user-btn { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 3px; border-radius: 20px; border: 1px solid transparent; background: none; cursor: pointer; font: inherit; color: var(--text-2); }
.user-btn:hover { background: var(--surface-3); }

/* --- Banners & flash ------------------------------------------------------- */
.banner { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; border: 1px solid; }
.banner .icon { flex-shrink: 0; }
.banner-actions { margin-left: auto; display: flex; gap: 8px; }
.banner-info { background: var(--blue-50); border-color: var(--blue-100); color: #1a4a9e; }
.banner-warning { background: var(--amber-50); border-color: var(--amber-100); color: #7a4507; }
.banner-danger { background: var(--red-50); border-color: var(--red-100); color: #a3161f; }
.banner-success { background: var(--green-50); border-color: var(--green-100); color: #05603a; }
.banner-neutral { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.banner strong { font-weight: 600; }

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 280px; max-width: 420px; background: #101828; color: #fff; border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-lg); display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; animation: toastIn .2s ease; }
.toast.success .icon { color: #32d583; } .toast.error .icon { color: #f97066; } .toast.warning .icon { color: #fdb022; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* --- Page header ----------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head-main { min-width: 0; }
.page-sub { color: var(--muted); margin-top: 4px; font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .icon { color: var(--faint); }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* --- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  font: inherit; font-weight: 550; font-size: 14px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-xs);
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s; text-decoration: none; line-height: 1;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #a3161f; border-color: #a3161f; color: #fff; }
.btn-danger-outline { color: var(--red); border-color: #fda29b; }
.btn-danger-outline:hover { background: var(--red-50); color: #a3161f; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; gap: 4px; border-radius: 6px; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; font-weight: 500; }
.link-btn:hover { color: var(--brand-hover); text-decoration: underline; }
.link-danger { color: var(--red); }

/* --- Cards ----------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card-head .card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.card-body { padding: 20px; }
.card-body.tight { padding: 12px 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-flush .table-wrap { border: 0; border-radius: 0; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.grid-side-main { grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: 20px; }
.stack-sm > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.mt-0 { margin-top: 0 !important; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; } .strong { font-weight: 600; }
.text-right { text-align: right; } .text-center { text-align: center; } .nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-red { color: var(--red); } .text-green { color: var(--green); } .text-amber { color: var(--amber); } .text-blue { color: var(--blue); }

/* --- Stats ----------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-xs); min-width: 0; }
a.stat:hover { border-color: var(--border-strong); }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; color: var(--text); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-foot { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.stat-icon.green { background: var(--green-50); color: var(--green); }
.stat-icon.red { background: var(--red-50); color: var(--red); }
.stat-icon.blue { background: var(--blue-50); color: var(--blue); }
.stat-icon.amber { background: var(--amber-50); color: var(--amber); }
.stat-icon.brand { background: var(--brand-50); color: var(--brand); }

.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }

.summary-list { list-style: none; margin: 0; padding: 0; }
.summary-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.summary-list li:last-child { border-bottom: 0; }
.summary-list .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.summary-list li.minus .num { color: var(--muted); }
.summary-list li.minus .num::before { content: "\2212\00a0"; }
.summary-list li.total { border-top: 1px solid var(--text); border-bottom: 0; margin-top: 4px; padding-top: 12px; font-weight: 650; font-size: 15px; }
.summary-list li.total .num { color: var(--brand); font-size: 18px; }
.summary-list .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; }

/* --- Badges & chips -------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 550; white-space: nowrap; border: 1px solid transparent; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--green-50); color: var(--green); border-color: var(--green-100); }
.badge-red { background: var(--red-50); color: var(--red); border-color: var(--red-100); }
.badge-amber { background: var(--amber-50); color: var(--amber); border-color: var(--amber-100); }
.badge-blue { background: var(--blue-50); color: var(--blue); border-color: var(--blue-100); }
.badge-grey { background: var(--grey-50); color: var(--grey); border-color: var(--grey-100); }
.badge-outline { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 6px 0 10px; border-radius: 14px; background: var(--brand-50); color: var(--brand); font-size: 12.5px; font-weight: 500; border: 1px solid var(--brand-100); }
.chip a { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: var(--brand); }
.chip a:hover { background: var(--brand-100); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* --- Forms ----------------------------------------------------------------- */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-weight: 550; font-size: 13.5px; color: var(--text-2); margin-bottom: 6px; }
.label .req { color: var(--red); margin-left: 2px; }
.label .opt { color: var(--faint); font-weight: 400; margin-left: 4px; }
.help { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.error-text { font-size: 12.5px; color: var(--red); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-xs); transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.select[multiple] { height: auto; min-height: 120px; padding: 6px; background-image: none; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: #fda29b; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--muted); }
.input-sm, .select-sm { height: 32px; font-size: 13px; }
.input-group { display: flex; }
.input-group .input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .btn { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; box-shadow: none; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.form-grid .span-2 { grid-column: span 2; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 14px; }
.check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--brand); flex-shrink: 0; }
.check .check-text { color: var(--text-2); }
.check .check-text small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { width: 36px; height: 20px; border-radius: 10px; background: var(--border-strong); position: relative; transition: background .15s; flex-shrink: 0; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--brand-ring); }

.option-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.option-card { position: relative; display: block; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 14px 14px 14px 40px; cursor: pointer; background: var(--surface); transition: border-color .12s, box-shadow .12s; }
.option-card:hover { border-color: var(--faint); }
.option-card input { position: absolute; left: 14px; top: 16px; margin: 0; }
.option-card strong { display: block; font-weight: 600; font-size: 14px; }
.option-card span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.option-card:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); background: #fbfefd; }

.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; }
.fieldset-title { font-weight: 600; margin-bottom: 12px; font-size: 14px; }

/* --- Tables ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { text-align: left; font-weight: 550; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfc; }
.table tr.row-link { cursor: pointer; }
.table tr.is-selected td { background: var(--brand-50) !important; }
.table .col-check { width: 44px; padding-right: 0; }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-title { font-weight: 550; color: var(--text); }
.table .cell-title:hover { color: var(--brand); }
.table .cell-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.table-compact td { padding: 8px 14px; }
.th-sort { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.th-sort:hover, .th-sort.active { color: var(--text); }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .avatar { width: 32px; height: 32px; font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .input-icon { flex: 1; min-width: 220px; max-width: 380px; }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.filters-bar { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); align-items: center; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a, .tabs button { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--muted); font-weight: 550; border: 0; background: none; font: inherit; font-weight: 550; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs a.active, .tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--muted); padding: 1px 7px; border-radius: 10px; }
.tabs a.active .count { background: var(--brand-50); color: var(--brand); }
.card > .tabs { margin: 0; padding: 0 12px; }

.bulk-bar { position: sticky; top: calc(var(--topbar-h) + 8px); z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #101828; color: #fff; border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow-md); flex-wrap: wrap; }
.bulk-bar .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; box-shadow: none; }
.bulk-bar .btn:hover { background: rgba(255,255,255,.16); }
.bulk-bar .btn-danger-outline { color: #fda29b; border-color: rgba(253,162,155,.4); }
.bulk-bar .link-btn { color: #a6f4c5; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager a, .pager span { min-width: 32px; height: 32px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: 6px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); font-weight: 500; }
.pager a:hover { background: var(--surface-2); }
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .gap { border: 0; background: none; }
.pager .disabled { opacity: .45; }

.empty { text-align: center; padding: 56px 24px; }
.empty-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--surface-3); color: var(--muted); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { font-size: 15px; margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 16px; }

/* --- Dropdowns & modals ---------------------------------------------------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 6px; z-index: 60; display: none;
}
.dropdown-menu.left { left: 0; right: auto; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text-2); font: inherit; font-size: 13.5px; background: none; border: 0; cursor: pointer; text-align: left; white-space: nowrap; }
.dropdown-item:hover { background: var(--surface-3); color: var(--text); }
.dropdown-item .icon { color: var(--muted); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item.danger .icon { color: var(--red); }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px -6px; }
.dropdown-head { padding: 8px 10px 6px; font-size: 12px; color: var(--muted); }
.dropdown form { margin: 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 80; display: grid; place-items: center; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: calc(100vh - 40px); overflow: auto; animation: pop .16s ease; }
.modal-lg { max-width: 680px; }
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 0; }
.modal-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: var(--brand-50); color: var(--brand); }
.modal-icon.danger { background: var(--red-50); color: var(--red); }
.modal-icon.warning { background: var(--amber-50); color: var(--amber); }
.modal-title { font-size: 16px; font-weight: 600; margin-top: 8px; }
.modal-body { padding: 12px 22px 20px; color: var(--text-2); }
.modal-body p:last-child { margin-bottom: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; background: var(--surface-2); border-top: 1px solid var(--border); }
.modal .confirm-type { margin-top: 12px; }
.modal-close { margin-left: auto; }

/* Command palette */
.cmdk-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 90; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk { width: 100%; max-width: 620px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--border); }
.cmdk-input-wrap { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.cmdk-input-wrap .icon { color: var(--muted); }
.cmdk-input { flex: 1; height: 52px; border: 0; font: inherit; font-size: 15px; outline: none; background: none; color: var(--text); }
.cmdk-list { max-height: 400px; overflow-y: auto; padding: 8px; }
.cmdk-group { font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--text-2); cursor: pointer; }
.cmdk-item .icon { color: var(--muted); }
.cmdk-item.active { background: var(--brand-50); color: var(--brand); }
.cmdk-item.active .icon { color: var(--brand); }
.cmdk-item .meta { margin-left: auto; font-size: 12px; color: var(--muted); }
.cmdk-empty { padding: 28px; text-align: center; color: var(--muted); }
.cmdk-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 12px; color: var(--muted); }

/* Sending panel */
.panel-pop { position: absolute; right: 0; top: calc(100% + 8px); width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); z-index: 60; display: none; }
.dropdown.open .panel-pop { display: block; }
.panel-pop-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.panel-pop-body { padding: 8px 16px; max-height: 320px; overflow-y: auto; }
.panel-pop-foot { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.run-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.run-item:last-child { border-bottom: 0; }

/* --- Progress & steppers --------------------------------------------------- */
.progress { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand); border-radius: 4px; transition: width .4s ease; }
.progress-sm { height: 5px; }
.progress-stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-3); }
.progress-stack span { display: block; height: 100%; }

.stepper { display: flex; gap: 0; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 6px; overflow-x: auto; }
.step { flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); color: var(--muted); font-weight: 550; font-size: 13.5px; min-width: 150px; white-space: nowrap; }
a.step:hover { background: var(--surface-2); color: var(--text); }
.step-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--border-strong); font-size: 12px; font-weight: 600; flex-shrink: 0; background: var(--surface); }
.step.done .step-num { background: var(--brand); border-color: var(--brand); color: #fff; }
.step.done { color: var(--text-2); }
.step.current { background: var(--brand-50); color: var(--brand); }
.step.current .step-num { border-color: var(--brand); color: var(--brand); }

/* --- Charts ---------------------------------------------------------------- */
.chart { width: 100%; height: 240px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip { position: absolute; pointer-events: none; background: #101828; color: #fff; font-size: 12px; padding: 8px 10px; border-radius: 6px; box-shadow: var(--shadow-md); white-space: nowrap; z-index: 5; transform: translate(-50%, -100%); margin-top: -8px; }
.chart-tip div { display: flex; gap: 8px; align-items: center; }
.chart-tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 8px 0; font-size: 13.5px; }
.bar-list .bar { grid-column: span 2; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar-list .bar span { display: block; height: 100%; background: var(--brand); border-radius: 3px; }

/* --- Message preview ------------------------------------------------------- */
.wa-preview { background: #efeae2; border-radius: var(--radius-lg); padding: 18px 16px; min-height: 160px; }
.wa-bubble { background: #fff; border-radius: 8px 8px 8px 2px; padding: 8px 10px 6px; max-width: 320px; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 14px; color: #111b21; white-space: pre-wrap; word-wrap: break-word; }
.wa-bubble .wa-header { font-weight: 600; margin-bottom: 4px; }
.wa-bubble .wa-footer { font-size: 12.5px; color: #667781; margin-top: 6px; }
.wa-bubble .wa-time { text-align: right; font-size: 11px; color: #667781; margin-top: 2px; }
.wa-buttons { max-width: 320px; margin-top: 4px; display: grid; gap: 4px; }
.wa-buttons span { background: #fff; border-radius: 8px; text-align: center; padding: 8px; color: #027eb5; font-size: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.var-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.var-pill { font-family: var(--mono); font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; }
.var-pill:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-50); }

/* --- Timeline / activity --------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .tl-dot { position: absolute; left: 0; top: 4px; width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); }
.timeline .tl-dot.green { border-color: #32d583; } .timeline .tl-dot.red { border-color: #f97066; } .timeline .tl-dot.blue { border-color: #528bff; } .timeline .tl-dot.amber { border-color: #fdb022; }
.timeline .tl-title { font-weight: 550; font-size: 13.5px; }
.timeline .tl-meta { font-size: 12.5px; color: var(--muted); }

.diff { font-family: var(--mono); font-size: 12px; }
.diff .old { color: var(--red); text-decoration: line-through; }
.diff .new { color: var(--green); }

/* --- Settings layout ------------------------------------------------------- */
.side-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + 20px); }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; }
.side-nav a .icon { color: var(--muted); }
.side-nav a:hover { background: var(--surface); }
.side-nav a.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-xs); border: 1px solid var(--border); }
.side-nav a.active .icon { color: var(--brand); }
.settings-section { padding: 22px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; }
.settings-section:first-child { padding-top: 0; }
.settings-section:last-of-type { border-bottom: 0; }
.settings-section h3 { font-size: 14px; margin-bottom: 4px; }
.settings-section .desc { color: var(--muted); font-size: 13px; }

.secret-set { display: inline-flex; align-items: center; gap: 6px; color: var(--green); font-size: 13px; font-weight: 500; }
.copy-field { display: flex; }
.copy-field .input { font-family: var(--mono); font-size: 12.5px; border-radius: var(--radius) 0 0 var(--radius); background: var(--surface-2); }
.copy-field .btn { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; box-shadow: none; }

/* --- Auth pages ------------------------------------------------------------ */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: #0b3d33; color: #d6efe8; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side h2 { color: #fff; font-size: 28px; line-height: 1.25; max-width: 440px; letter-spacing: -.02em; }
.auth-side p { color: #a8d5c8; max-width: 440px; font-size: 15px; margin-top: 14px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-points li { display: flex; gap: 10px; align-items: flex-start; color: #cfe9e1; }
.auth-points .icon { color: #5fd3b3; margin-top: 2px; }
.auth-side .brand-mark { background: rgba(255,255,255,.12); }
.auth-main { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { font-size: 24px; margin-bottom: 6px; }
.auth-single { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-single .auth-card { width: 100%; max-width: 640px; }

/* --- Misc ------------------------------------------------------------------ */
.divider-text { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 12px; margin: 16px 0; }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 32px; text-align: center; background: var(--surface-2); transition: border-color .12s, background .12s; cursor: pointer; display: block; }
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-50); }
.dropzone input { display: none; }
.dropzone .empty-icon { background: var(--surface); border: 1px solid var(--border); }
.dropzone-file { font-weight: 600; color: var(--text); margin-top: 8px; }
.notice-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.pre { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto; margin: 0; }
.dot-inline { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: 0; }
.list-row { display: flex; align-items: center; gap: 12px; }
.hint-list { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.hint-list li { margin-bottom: 4px; }
.sticky-foot { position: sticky; bottom: 0; background: rgba(245,246,248,.94); backdrop-filter: blur(6px); padding: 14px 0; margin-top: 20px; display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); z-index: 10; }
.danger-zone { border-color: #fda29b; }
.danger-zone .card-head { border-bottom-color: #fecdca; }
.color-dot-slate { background: #667085; } .color-dot-green { background: #12b76a; } .color-dot-blue { background: #2e90fa; }
.color-dot-amber { background: #f79009; } .color-dot-red { background: #f04438; } .color-dot-purple { background: #7a5af8; } .color-dot-teal { background: #15b79e; }
.tag-slate { } .tag-green { background: var(--green-50); color: var(--green); border-color: var(--green-100); }
.tag-blue { background: var(--blue-50); color: var(--blue); border-color: var(--blue-100); }
.tag-amber { background: var(--amber-50); color: var(--amber); border-color: var(--amber-100); }
.tag-red { background: var(--red-50); color: var(--red); border-color: var(--red-100); }
.tag-purple { background: #f4f3ff; color: #5925dc; border-color: #ebe9fe; }
.tag-teal { background: #f0fdf9; color: #107569; border-color: #ccfbef; }
.drag-handle { cursor: grab; color: var(--faint); }
tr.dragging td { background: var(--brand-50); }
.loading { opacity: .55; pointer-events: none; transition: opacity .15s; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-page { text-align: center; padding: 80px 20px; }
.error-code { font-size: 14px; font-weight: 600; color: var(--brand); margin-bottom: 8px; }

/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: var(--sidebar-w) !important; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 35; }
  .main { margin-left: 0 !important; }
  .btn.topbar-menu { display: inline-flex; }
  .collapse-btn { display: none; }
  body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-section, body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-badge { display: revert; }
  body.sidebar-collapsed .nav-link { justify-content: flex-start; padding: 0 10px; }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-side-main { grid-template-columns: minmax(0, 1fr); }
  .side-nav { position: static; flex-direction: row; overflow-x: auto; }
  .settings-section { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .auth-wrap { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
}
@media (max-width: 720px) {
  .content { padding: 20px 16px 40px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .search-trigger .kbd, .search-trigger span { display: none; }
  .search-trigger { flex: 0 0 38px; padding: 0; justify-content: center; }
  .status-pill .status-text { display: none; }
  .status-pill { padding: 0 11px; }
  .user-btn .user-name { display: none; }
  .grid-2, .grid-4, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .page-head { align-items: flex-start; }
  h1 { font-size: 20px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .table .hide-sm { display: none; }
  .panel-pop { width: calc(100vw - 24px); right: -60px; }
  .stepper .step { min-width: auto; }
  .stepper .step-label { display: none; }
  .stat-value { font-size: 22px; }
  .banner { flex-wrap: wrap; }
  .banner-actions { margin-left: 30px; }
}

@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .pagination { display: none !important; }
  .main { margin: 0 !important; }
  .card { box-shadow: none; }
}
