:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --panel: #ffffff;
  --panel-2: #eef3f1;
  --line: #dce3e1;
  --line-strong: #c8d3d0;
  --text: #16201d;
  --muted: #66746f;
  --accent: #0f9f6e;
  --accent-strong: #08784f;
  --accent-dim: #e6f6ef;
  --blue: #266dd3;
  --amber: #b7791f;
  --red: #c9362c;
  --red-soft: #fff0ee;
  --shadow: 0 20px 48px rgba(20, 32, 29, .12);
  --shadow-soft: 0 10px 28px rgba(20, 32, 29, .08);
  --shadow-tiny: 0 3px 10px rgba(20, 32, 29, .06);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #111318;
  --surface: #181b22;
  --panel: #181b22;
  --panel-2: #222631;
  --line: #2e3440;
  --line-strong: #424a59;
  --text: #e8efec;
  --muted: #9aaaa4;
  --accent: #21c88a;
  --accent-strong: #7de0b8;
  --accent-dim: #12332a;
  --blue: #7eb2ff;
  --amber: #f0bd58;
  --red: #ff8178;
  --red-soft: #3a1918;
  --shadow: 0 18px 44px rgba(0, 0, 0, .34);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, .24);
  --shadow-tiny: 0 3px 10px rgba(0, 0, 0, .20);
}

* { box-sizing: border-box; }
html { min-width: 320px; }

body {
  margin: 0;
  background: linear-gradient(180deg, #fbfcfc 0, var(--bg) 360px);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

html[data-theme="dark"] body {
  background: linear-gradient(180deg, #171a21 0, var(--bg) 360px);
}

button, input, textarea { font: inherit; }
button, a, input, textarea { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  box-shadow: 0 0 0 3px rgba(15, 159, 110, .18);
  border-color: var(--accent);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(15, 159, 110, .16), transparent 34%),
    linear-gradient(180deg, #f9fbfa, #edf2f0);
}

html[data-theme="dark"] .login-body {
  background:
    radial-gradient(circle at 50% 0%, rgba(126, 178, 255, .14), transparent 34%),
    linear-gradient(180deg, #171a21, #111318);
}

.login-card {
  position: relative;
  width: min(400px, 100%);
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(220, 227, 225, .92);
  border-radius: 8px;
  padding: 42px 32px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

html[data-theme="dark"] .login-card {
  background: rgba(23, 32, 29, .94);
  border-color: var(--line);
}

.brand { text-align: center; margin-bottom: 26px; }
.brand h1 { font-size: 24px; line-height: 1.2; margin: 13px 0 5px; letter-spacing: 0; }
.brand p { margin: 0; font-size: 13px; }
.brand-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px var(--accent-dim);
}

.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}

.pin-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 24px;
  letter-spacing: 10px;
  text-align: center;
  background: #fbfcfc;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .78);
}

html[data-theme="dark"] .pin-input,
html[data-theme="dark"] .search,
html[data-theme="dark"] .message-composer textarea,
html[data-theme="dark"] .attachment-preview {
  background: #12151b;
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.key {
  min-height: 48px;
  padding: 12px 0;
  font-size: 18px;
  cursor: pointer;
  background: #f8faf9;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-tiny);
  transition: transform .12s ease, border-color .12s ease, background .12s ease, box-shadow .12s ease;
}
html[data-theme="dark"] .key { background: #222631; }
.key:hover { background: #eff5f2; border-color: var(--line-strong); }
html[data-theme="dark"] .key:hover { background: #2a303b; }
.key:active { transform: translateY(1px); }

.btn {
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 650;
  min-height: 38px;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.btn:hover { background: #f4f8f6; border-color: var(--line-strong); box-shadow: var(--shadow-tiny); }
html[data-theme="dark"] .btn:hover { background: #222631; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(15, 159, 110, .22);
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.block { width: 100%; min-height: 46px; font-size: 15px; }
.btn.ghost { background: transparent; }

.theme-toggle {
  min-width: 64px;
}

.login-theme {
  position: absolute;
  top: 14px;
  right: 14px;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

.alert {
  background: var(--red-soft);
  border: 1px solid rgba(201, 54, 44, .25);
  color: var(--red);
  padding: 11px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  margin: 0 0 16px;
}

/* ---------- shell ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .65);
}

html[data-theme="dark"] .topbar,
html[data-theme="dark"] .thread-head,
html[data-theme="dark"] .composer-wrap {
  background: rgba(23, 32, 29, .92);
}
.brand-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-row strong { white-space: nowrap; letter-spacing: 0; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-actions form { margin: 0; }

.endpoint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: #f7faf9;
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: var(--radius);
  max-width: min(46ch, 42vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
}

html[data-theme="dark"] .endpoint,
html[data-theme="dark"] .badge,
html[data-theme="dark"] .toggle,
html[data-theme="dark"] .pill {
  background: #12151b;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f8faf9;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65);
}
.badge.online { color: var(--accent-strong); border-color: rgba(15, 159, 110, .32); background: var(--accent-dim); }
.badge.offline { color: var(--amber); border-color: rgba(183, 121, 31, .28); background: #fff7e8; }
html[data-theme="dark"] .badge.offline { background: #302413; }
.badge.prod { color: var(--red); border-color: rgba(201, 54, 44, .25); background: var(--red-soft); }
.badge.warn { color: var(--amber); border-color: rgba(183, 121, 31, .28); background: #fff7e8; text-transform: none; letter-spacing: 0; }
html[data-theme="dark"] .badge.warn { background: #302413; }

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  padding: 3px;
  background: #edf3f1;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
}

html[data-theme="dark"] .nav {
  background: #12151b;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: rgba(255, 255, 255, .7); }
html[data-theme="dark"] .nav-link:hover { background: rgba(255, 255, 255, .06); }
.nav-link.active { color: var(--accent-strong); background: var(--surface); border-color: rgba(15, 159, 110, .18); box-shadow: var(--shadow-soft); }

/* ---------- dashboard ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  padding: 20px 22px 10px;
}
.stat {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 15px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), rgba(38, 109, 211, .78));
}
.stat-value {
  display: block;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}
.stat-value.small { font-size: 14px; font-weight: 750; color: var(--blue); overflow-wrap: anywhere; }
.stat-label {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 10px 22px 16px;
  padding: 10px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, .72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}
html[data-theme="dark"] .controls { background: rgba(23, 32, 29, .72); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .12s ease;
}
.chip:hover { color: var(--text); background: #f4f8f6; }
html[data-theme="dark"] .chip:hover { background: #222631; }
.chip.active { background: var(--accent-dim); color: var(--accent-strong); border-color: rgba(15, 159, 110, .28); box-shadow: inset 0 0 0 1px rgba(15, 159, 110, .08); }

.search {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  min-height: 40px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 159, 110, .12); }
.search::placeholder { color: #87938f; }
html[data-theme="dark"] .search::placeholder { color: #7f918a; }

.chat-list-head .search {
  width: 100%;
  min-width: 0;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
}
.toggle input { accent-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, .92fr);
  gap: 16px;
  padding: 0 22px 24px;
  align-items: start;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(100vh - 256px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.event {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s ease, box-shadow .12s ease;
}
.event:last-child { border-bottom: none; }
.event:hover { background: #f7faf9; }
html[data-theme="dark"] .event:hover { background: #1f2430; }
.event.selected { background: var(--accent-dim); box-shadow: inset 3px 0 0 var(--accent); }
.event.new { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: rgba(15, 159, 110, .18); } to { background: transparent; } }

.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; background: var(--muted); }
.dot.message { background: var(--accent); }
.dot.status { background: var(--blue); }
.dot.error { background: var(--red); }
.dot.account { background: var(--amber); }

.event-main { min-width: 0; }
.event-title { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.event-who { font-weight: 780; }
.event-kind { font-size: 11px; color: var(--muted); font-family: var(--mono); text-transform: uppercase; }
.event-summary { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; margin-top: 2px; }
.event-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.detail {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 20px;
  max-height: calc(100vh - 256px);
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.detail-placeholder { color: var(--muted); text-align: center; padding: 42px 10px; }
.detail h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.25; letter-spacing: 0; }
.detail dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 16px; margin: 16px 0; font-size: 13px; }
.detail dt { color: var(--muted); font-weight: 700; }
.detail dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.detail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 0 8px; }

pre.json {
  background: #101513;
  border: 1px solid #26302d;
  border-radius: var(--radius);
  padding: 13px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  margin: 0;
  color: #e8f0ed;
}

html[data-theme="dark"] pre.json {
  background: #0b1110;
}
.tok-key { color: #8fd7ff; }
.tok-str { color: #82e6b8; }
.tok-num { color: #f2c879; }
.tok-bool { color: #ffb4a9; }

/* ---------- installments ---------- */
.installments-page {
  padding: 22px;
}

.installment-panel,
.installment-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.installment-panel {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.installment-panel h1,
.installment-card h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.installment-panel h1 { font-size: 22px; }
.installment-card h2 { font-size: 16px; }
.installment-card h3 {
  margin: 20px 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.installment-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.file-drop {
  cursor: pointer;
  min-width: min(360px, 82vw);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #f8faf9;
}

html[data-theme="dark"] .file-drop {
  background: #12151b;
}

.file-drop:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.file-title {
  font-weight: 760;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.installment-actions {
  display: flex;
  gap: 8px;
}

.installment-stats {
  padding: 0;
  margin: 0 0 14px;
}

.installments-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 14px;
}

.installment-card {
  padding: 16px;
  min-width: 0;
}

.summary-line {
  margin: 10px 0 12px;
  color: var(--muted);
  font-weight: 650;
}

.queue-list,
.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 430px;
  overflow-y: auto;
}

.queue-row,
.log-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfc;
}

html[data-theme="dark"] .queue-row,
html[data-theme="dark"] .log-row {
  background: #12151b;
}

.queue-phone {
  font-family: var(--mono);
  font-weight: 780;
  margin-bottom: 7px;
}

.queue-accounts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.queue-pill {
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
}

.queue-pill.tier-3 { color: var(--red); border-color: rgba(201, 54, 44, .28); background: var(--red-soft); }
.queue-pill.tier-2 { color: var(--amber); border-color: rgba(183, 121, 31, .28); background: #fff7e8; }
.queue-pill.tier-1 { color: var(--accent-strong); border-color: rgba(15, 159, 110, .24); background: var(--accent-dim); }
html[data-theme="dark"] .queue-pill.tier-2 { background: #302413; }

.report-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  margin: 12px 0 0;
}

.report-list dt {
  color: var(--muted);
  font-weight: 700;
}

.report-list dd {
  margin: 0;
  font-family: var(--mono);
  font-weight: 760;
}

.log-row {
  display: grid;
  grid-template-columns: minmax(88px, .8fr) minmax(104px, 1fr);
  gap: 4px 10px;
  font-size: 12px;
}

.log-row span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.success-note {
  width: 100%;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid rgba(15, 159, 110, .28);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-weight: 650;
}

/* ---------- conversations ---------- */
.chat-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; background: #eef2f0; }
html[data-theme="dark"] .chat-body { background: #111318; }
.chat-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--line);
}

.chat-list {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fbfcfc;
}
html[data-theme="dark"] .chat-list { background: #12151b; }
.chat-list-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .62);
  z-index: 1;
}
.chat-list ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }

.contact {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #edf1ef;
  cursor: pointer;
  min-height: 72px;
  transition: background .12s ease, box-shadow .12s ease;
}
.contact:hover { background: #f4f8f6; }
html[data-theme="dark"] .contact { border-bottom-color: #222631; }
html[data-theme="dark"] .contact:hover { background: #1f2430; }
.contact.active { background: var(--accent-dim); box-shadow: inset 3px 0 0 var(--accent); }
.contact-main { min-width: 0; flex: 1; }
.contact-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.contact-name { font-weight: 760; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.contact-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 760;
  background: linear-gradient(145deg, var(--accent), #47bf90);
  color: #fff;
  border: 2px solid var(--surface);
  box-shadow: 0 4px 14px rgba(15, 159, 110, .22), 0 0 0 1px var(--line);
}
.avatar.big { width: 48px; height: 48px; font-size: 18px; }
.pill {
  font-size: 11px;
  color: var(--muted);
  background: #f5f8f7;
  border: 1px solid var(--line);
  padding: 3px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.thread-pane { display: flex; flex-direction: column; min-height: 0; background: #f6f8f7; }
html[data-theme="dark"] .thread-pane { background: #111318; }
.thread-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
}
.thread-head .btn { margin-left: auto; }
.small-btn { font-size: 12px; padding: 6px 10px; text-decoration: none; min-height: 32px; }
.thread-name { font-weight: 780; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 26px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background:
    linear-gradient(180deg, rgba(15, 159, 110, .06), transparent 260px),
    #f6f8f7;
}

html[data-theme="dark"] .thread {
  background:
    linear-gradient(180deg, rgba(126, 178, 255, .07), transparent 260px),
    #111318;
}

.row { display: flex; }
.row.inbound { justify-content: flex-start; }
.row.outbound { justify-content: flex-end; }
.row.system { justify-content: center; }
.bubble {
  max-width: min(600px, 78%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px 16px 16px 16px;
  padding: 10px 12px 8px;
  box-shadow: 0 6px 18px rgba(20, 32, 29, .07);
}
.row.outbound .bubble {
  background: var(--accent-dim);
  border-color: rgba(15, 159, 110, .2);
  border-radius: 16px 6px 16px 16px;
}
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.caption { margin-top: 7px; font-size: 14px; overflow-wrap: anywhere; }
.bubble .meta {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}
.bubble .kind { font-family: var(--mono); text-transform: uppercase; opacity: .72; margin-right: auto; }

.system-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  max-width: 90%;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
}
html[data-theme="dark"] .system-chip,
html[data-theme="dark"] .day-sep {
  background: rgba(23, 32, 29, .86);
}
.tick.read { color: var(--blue); }
.tick.delivered, .tick.sent { color: var(--muted); }
.row.system.error .system-chip, .tick.failed { color: var(--red); border-color: rgba(201, 54, 44, .25); }
.thread-loader {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
  padding: 8px 0;
}
.day-sep {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: 999px;
  margin: 10px 0 2px;
}

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  padding: 12px 16px 16px;
  box-shadow: 0 -10px 24px rgba(20, 32, 29, .05);
}
.window-status { min-height: 22px; margin: 0 0 8px; font-size: 13px; font-weight: 650; color: var(--muted); }
.window-status.active { color: var(--accent-strong); }
.window-status.expired {
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid rgba(201, 54, 44, .25);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.message-composer { display: flex; gap: 10px; align-items: flex-end; }
.message-composer[hidden] { display: none; }
.message-composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 128px;
  resize: vertical;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fbfcfc;
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.message-composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 159, 110, .12); }
.message-composer .btn { min-height: 46px; min-width: 80px; }
.message-composer .btn:disabled { cursor: not-allowed; filter: grayscale(.4); opacity: .6; }
.icon-btn {
  width: 46px;
  min-width: 46px;
  min-height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  padding: 10px;
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-tiny);
}
.attachment-preview[hidden] { display: none; }
.attachment-preview.error { color: var(--red); background: var(--red-soft); border-color: rgba(201, 54, 44, .25); }
.preview-thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: #eef3f1; }
html[data-theme="dark"] .preview-thumb,
html[data-theme="dark"] .preview-icon,
html[data-theme="dark"] .attach-image {
  background: #222631;
}
.preview-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 6px;
  background: #eef3f1;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.preview-main { min-width: 0; flex: 1; }
.preview-name { font-weight: 760; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.attach-image { display: block; max-width: 320px; max-height: 320px; border-radius: 8px; cursor: zoom-in; background: #eef3f1; }
.attach-video { max-width: 340px; border-radius: 8px; display: block; }
.attach-audio { width: 280px; display: block; }
.attachment {
  display: flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 220px;
}
html[data-theme="dark"] .attachment { background: #12151b; }
.attachment:hover { border-color: var(--accent); }
.attachment.fallback { border-style: dashed; opacity: .9; }
.attach-icon { font-size: 22px; }
.attach-name { font-weight: 760; font-size: 14px; overflow-wrap: anywhere; }
.media-note { font-size: 11px; color: var(--amber); margin-top: 5px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 10, .86);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 40px;
}
.lightbox[hidden] { display: none; }
.lightbox-inner img { max-width: 92vw; max-height: 88vh; border-radius: 8px; box-shadow: var(--shadow); }
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  font-size: 22px;
  cursor: pointer;
  background: transparent;
  border: none;
  color: #fff;
}

@media (max-width: 1120px) {
  .stats { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
  .layout { grid-template-columns: 1fr; }
  .installments-grid { grid-template-columns: 1fr; }
  .feed, .detail { max-height: none; }
}

@media (max-width: 860px) {
  .topbar { align-items: stretch; }
  .brand-row, .topbar-actions { width: 100%; flex-wrap: wrap; }
  .topbar-actions { justify-content: space-between; flex-wrap: wrap; }
  .nav { margin-left: 0; }
  .endpoint { max-width: 100%; flex: 1; }
  .chat-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 34vh) minmax(0, 1fr);
  }
  .chat-list {
    display: flex;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 14px 14px 8px; }
  .controls, .layout { padding-left: 14px; padding-right: 14px; }
  .filters { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .search { min-width: 100%; }
  .thread { padding: 16px 12px; }
  .bubble { max-width: 88%; }
  .message-composer { gap: 8px; }
  .message-composer .btn { min-width: 70px; padding-inline: 10px; }
  .login-card { padding: 28px 22px; }
}

/* --- Job history ---------------------------------------------------------- */
.runs-card { margin-top: 18px; }

.runs-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.runs-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.runs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.run-row {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfc;
  overflow: hidden;
}

html[data-theme="dark"] .run-row { background: #12151b; }

.run-row.sent      { border-left-color: var(--accent); }
.run-row.failed    { border-left-color: var(--red); }
.run-row.dry       { border-left-color: var(--blue); }
.run-row.empty     { border-left-color: var(--amber); }
.run-row.running   { border-left-color: var(--amber); }
.run-row.open      { box-shadow: var(--shadow-tiny); }

.run-head {
  width: 100%;
  display: grid;
  grid-template-columns: 84px 132px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.run-head:hover { background: var(--panel-2); }

.run-kind {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.run-when {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.run-summary { font-weight: 620; }
.run-row.failed .run-summary { color: var(--red); }
.run-row.empty  .run-summary { color: var(--amber); }

.run-meta {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

.run-detail {
  border-top: 1px solid var(--line);
  padding: 13px;
}

.run-messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  max-height: 340px;
  overflow-y: auto;
}

.run-error {
  color: var(--red);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert.small { font-size: 13px; padding: 8px 10px; margin-bottom: 10px; }

@media (max-width: 720px) {
  .run-head {
    grid-template-columns: 1fr auto;
    row-gap: 4px;
  }
  .run-summary { grid-column: 1 / -1; }
}

/* --- Numbers to fix ------------------------------------------------------- */
.numbers-card { margin-top: 18px; }

.numbers-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 6px;
}

.numbers-stats .stat {
  flex: 1 1 130px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel-2);
}

.numbers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.numbers-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.number-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 4px 10px;
  align-items: baseline;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #fbfcfc;
  font-size: 13px;
}

html[data-theme="dark"] .number-row { background: #12151b; }

.number-row.unreachable { border-left-color: var(--red); }

.number-msisdn {
  font-family: var(--mono);
  font-weight: 720;
}

.number-reason { color: var(--text); }
.number-row.unreachable .number-reason { color: var(--red); }

.number-meta {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .numbers-grid { grid-template-columns: 1fr; }
  .number-row { grid-template-columns: 1fr auto; }
  .number-reason { grid-column: 1 / -1; }
}
