: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; }
/* The hidden attribute must always win over a component's own display rule. */
[hidden] { display: none !important; }
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; }
}

/* --- Pending queue --------------------------------------------------------- */
.backlog-card {
  margin-top: 18px;
  border-left: 3px solid var(--accent);
}

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

.backlog-card .stat-value { font-variant-numeric: tabular-nums; }


/* --- 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; }
}

/* ---------- phones ------------------------------------------------------- */
/* The back button only exists for the phone layout, where the chat list and
   an open chat are separate screens (body.thread-open switches between them). */
.back-btn { display: none; }
.thread-title { min-width: 0; }

@media (max-width: 760px) {
  /* one compact row instead of three wrapped ones */
  .topbar {
    flex-wrap: wrap;            /* extra buttons drop to a second row only when they don't fit */
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  .brand-row { width: auto; flex: 1 1 250px; min-width: 0; flex-wrap: nowrap; gap: 8px; }
  .topbar .endpoint { display: none; }
  .brand-row strong,
  .brand-row .brand-dot,
  .topbar .badge { display: none; }
  .nav {
    margin-left: 0;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 7px 11px; }
  .topbar-actions { width: auto; flex: 0 0 auto; margin-left: auto; flex-wrap: nowrap; gap: 6px; justify-content: flex-end; }
  .topbar .btn.ghost { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .topbar .theme-toggle { display: none; }   /* phones follow the system light/dark setting */

  /* inputs under 16px make iPhone zoom the whole page on tap */
  .search,
  .message-composer textarea,
  input[type="text"], input[type="password"], input[type="search"], input[type="number"] { font-size: 16px; }

  /* chats: list screen and thread screen */
  .chat-body { height: 100vh; height: 100dvh; }
  .chat-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); border-top: 0; }
  .thread-pane, .chat-list { min-width: 0; }
  .chat-list { border-right: 0; border-bottom: 0; }
  .thread-pane { display: none; }
  body.thread-open .chat-list { display: none; }
  body.thread-open .thread-pane { display: flex; }

  .chat-list-head { padding: 10px; }
  .contact { padding: 12px; gap: 11px; min-height: 68px; }
  .contact .pill { display: none; }

  .thread-head { padding: 8px 10px; gap: 10px; }
  .thread-head .back-btn {
    display: grid;
    place-items: center;
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    margin-left: -4px;
    padding: 0;
    font-size: 30px;
    line-height: 1;
    border-color: transparent;
    background: transparent;
  }
  .thread-head a.small-btn { display: none; }          /* raw events: desktop only */
  .thread-head [data-details] { padding: 6px 9px; }
  .thread-head [data-details] .btn-label { display: none; }
  .thread-head .avatar.big { width: 38px; height: 38px; font-size: 15px; }
  .thread-title { flex: 1; }
  .thread-name, .thread-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .thread { padding: 12px 10px; gap: 6px; }
  .bubble { max-width: 86%; }
  .attach-image, .attach-video { max-width: 100%; height: auto; }
  .attach-audio { width: 100%; max-width: 260px; }
  .attachment { min-width: 0; }

  .composer-wrap {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .window-status { min-height: 0; margin-bottom: 6px; font-size: 12px; }
  .window-status.expired { padding: 8px 10px; }
  .message-composer { gap: 6px; }
  .message-composer textarea { min-width: 0; min-height: 44px; padding: 10px 14px; resize: none; border-radius: 22px; }
  .message-composer .btn { min-height: 44px; }
  .message-composer .btn.primary { min-width: 64px; padding-inline: 14px; border-radius: 22px; }
  .message-composer .icon-btn { width: 44px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
  .lightbox { padding: 12px; }

  /* events and installments pages */
  .controls { margin: 8px 10px 12px; }
  .controls, .layout { padding-left: 10px; padding-right: 10px; }
  .stats { padding: 12px 10px 6px; gap: 8px; }
  .installments-page { padding: 12px 10px; }
}

/* ---------- brand -------------------------------------------------------- */
.brand-logo { width: 30px; height: 30px; flex: none; border-radius: 8px; display: block; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto; box-shadow: 0 10px 24px rgba(174, 16, 27, .22); }

/* ---------- stop button -------------------------------------------------- */
.btn.danger { color: #fff; background: var(--red); border-color: var(--red); }
.btn.danger:hover { filter: brightness(.94); }
.btn.danger:disabled { opacity: .7; cursor: progress; }

/* ---------- settings ----------------------------------------------------- */
.settings-page { display: grid; gap: 16px; padding: 22px; max-width: 720px; margin: 0 auto; }
.settings-card h2 { margin: 0 0 6px; font-size: 18px; }
.settings-form { display: grid; gap: 6px; max-width: 360px; margin-top: 12px; }
.settings-form .label { margin: 8px 0 0; }
.settings-form .btn { margin-top: 12px; justify-self: start; }
.settings-form .alert, .settings-form .success-note { margin: 8px 0 0; }
.install-steps { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 14px 0 0; font-size: 14px; }
.install-steps dt { font-weight: 760; }
.install-steps dd { margin: 0; color: var(--muted); }
#install-btn { margin-top: 10px; }

/* ---------- unread ------------------------------------------------------- */
.chat-filters { display: flex; gap: 6px; margin-top: 10px; align-items: center; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer;
}
.filter-chip.active { color: var(--accent-strong); background: var(--accent-dim); border-color: rgba(15, 159, 110, .3); }
.chip-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; line-height: 20px; text-align: center; }
.unread-badge {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 760; line-height: 22px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.contact.has-unread .contact-name { font-weight: 820; }
.contact.has-unread .contact-time { color: var(--accent-strong); font-weight: 700; }
.contact.has-unread .contact-preview { color: var(--text); }
.contact-preview.is-status { font-style: italic; opacity: .8; }

/* ---------- notifications ------------------------------------------------ */
.notify-status { margin: 12px 0; font-weight: 650; }
.notify-status[data-tone="ok"] { color: var(--accent-strong); }
.notify-status[data-tone="warn"] { color: var(--amber); }

/* ---------- accounts ----------------------------------------------------- */
.text-input { width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 159, 110, .14); outline: none; }
.login-card .label { margin-top: 14px; }
.login-card .text-input { font-size: 16px; padding: 12px 14px; }
.login-help { margin: 12px 0 16px; }
.user-chip { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; }
.users-list { display: grid; gap: 8px; margin-top: 12px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); flex-wrap: wrap; }
.user-row.off { opacity: .6; }
.user-main { flex: 1 1 220px; min-width: 0; }
.user-name { font-weight: 760; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.users-add-title { margin: 18px 0 8px; font-size: 15px; }
.user-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.user-form .btn { justify-self: start; }
.bubble .sender { font-weight: 700; color: var(--accent-strong); }

/* ---------- sending limit ------------------------------------------------ */
.limits-card { margin-bottom: 14px; }
.limits-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 10px; }
.limits-form label { display: grid; gap: 4px; }
.limits-form .text-input { width: 180px; }

/* ---------- polish ------------------------------------------------------- */
/* each contact gets a steady colour (set with --hue on the element) */
.avatar {
  background: linear-gradient(145deg, hsl(var(--hue, 160) 58% 44%), hsl(calc(var(--hue, 160) + 28) 62% 56%));
  box-shadow: 0 4px 14px hsl(var(--hue, 160) 60% 40% / .25), 0 0 0 1px var(--line);
}
html[data-theme="dark"] .avatar { border-color: var(--panel); }
/* chat canvas: a faint dot pattern like a messaging app */
.thread {
  background-color: var(--panel-2);
  background-image: radial-gradient(rgba(15, 159, 110, .10) 1px, transparent 1.4px), radial-gradient(rgba(15, 159, 110, .06) 1px, transparent 1.4px);
  background-size: 26px 26px, 26px 26px;
  background-position: 0 0, 13px 13px;
}
html[data-theme="dark"] .thread {
  background-image: radial-gradient(rgba(255, 255, 255, .05) 1px, transparent 1.4px), radial-gradient(rgba(255, 255, 255, .03) 1px, transparent 1.4px);
}
.row.inbound .bubble { border-bottom-left-radius: 6px; }
.row.outbound .bubble { border-bottom-right-radius: 6px; }
.message-composer textarea { max-height: 160px; line-height: 1.4; }
.thread-pane { position: relative; }
.jump-latest {
  position: absolute; right: 18px; bottom: 110px; z-index: 3; padding: 8px 14px; border-radius: 999px;
  background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 8px 20px rgba(15, 159, 110, .3); font-weight: 700;
}
.quick-replies { margin: 0 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 12px 30px rgba(0, 0, 0, .12); max-height: 260px; overflow-y: auto; }
.quick-item {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 12px; width: 100%; padding: 10px 12px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; cursor: pointer; font: inherit;
}
.quick-item:last-child { border-bottom: 0; }
.quick-item.active, .quick-item:hover { background: var(--accent-dim); }
.quick-key { font-weight: 760; color: var(--accent-strong); white-space: nowrap; }
.quick-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-empty { padding: 12px; }
.login-body {
  background: radial-gradient(circle at 15% 10%, rgba(200, 22, 29, .14), transparent 36%), radial-gradient(circle at 85% 90%, rgba(15, 159, 110, .18), transparent 40%), linear-gradient(180deg, #f9fbfa, #eef2f0);
}
html[data-theme="dark"] .login-body {
  background: radial-gradient(circle at 15% 10%, rgba(200, 22, 29, .22), transparent 36%), radial-gradient(circle at 85% 90%, rgba(15, 159, 110, .2), transparent 40%), linear-gradient(180deg, #14171d, #0f1115);
}
.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--accent-dim); color: var(--accent-strong); font-size: 14px; font-weight: 650; }
.auto-block { margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.auto-block textarea { margin-top: 8px; }
.toggle-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; cursor: pointer; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.hours-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-top: 10px; }
.hours-row label { display: grid; gap: 4px; }
.hours-row .text-input { width: auto; min-width: 120px; }
.days-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.days-row label { display: inline-flex; gap: 4px; align-items: center; font-size: 14px; }
.days-row input { accent-color: var(--accent); }
.rules-list { display: grid; gap: 10px; margin: 10px 0; }
.rule-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) max-content; gap: 8px; align-items: start; }
.rule-row .qr-key { font-weight: 700; }
#ar-save, #qr-save, #lb-save { margin-top: 10px; }

/* ---------- team inbox --------------------------------------------------- */
.filter-select { margin-left: auto; padding: 5px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; max-width: 120px; }
.label-dots { display: inline-flex; gap: 3px; flex: none; }
.label-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }
.contact-panel { padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); display: grid; gap: 10px; }
.contact-panel-row { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 14px; }
.contact-panel .text-input { width: 100%; }
.label-picks { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 6px; }
.label-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.label-pick input { accent-color: var(--accent); }
.contact-panel-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.qr-image { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.qr-image img { height: 56px; border-radius: 8px; border: 1px solid var(--line); }
.label-row { grid-template-columns: minmax(0, 1fr) 48px max-content; }
.color-input { width: 48px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.report-preview, .report-template pre { margin: 12px 0; padding: 12px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--line); white-space: pre-wrap; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.report-template { margin-top: 12px; }
.bc-step { margin: 16px 0; display: grid; gap: 8px; }
.bc-step .days-row label { font-size: 15px; }
.progress { position: relative; height: 26px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; }

@media (max-width: 760px) {
  .brand-row .brand-logo { display: none; }
  .nav-label { display: none; }
  .settings-page { padding: 12px 10px; }
  .install-steps { grid-template-columns: 1fr; gap: 2px; }
  .install-steps dd { margin-bottom: 8px; }
  .user-chip { display: none; }
  .user-form { grid-template-columns: 1fr; }
  .limits-form .text-input { width: 100%; }
  .limits-form label { flex: 1 1 140px; }
  .rule-row { grid-template-columns: 1fr; }
  .jump-latest { bottom: 120px; right: 12px; }
  .chat-filters { flex-wrap: wrap; }
  .filter-select { margin-left: 0; }
  .contact-panel-row { grid-template-columns: 1fr; }
  .contact-panel { padding: 10px; }
}

/* ---------- internal notes ------------------------------------------------ */
.row.note { justify-content: center; }
.note-bubble {
  width: min(560px, 92%);
  padding: 10px 14px 8px;
  border-radius: 12px;
  background: #fff6d6;
  border: 1px dashed #e0b84a;
  color: #4a3a0a;
  box-shadow: 0 4px 14px rgba(160, 120, 20, .10);
}
.row.note.for-me .note-bubble { border-style: solid; border-width: 2px; }
.note-head { display: flex; gap: 6px; align-items: baseline; font-size: 12px; margin-bottom: 4px; }
.note-head .muted { margin-left: auto; }
.note-foot { margin-top: 4px; font-size: 11px; }
.mention-tag { font-weight: 760; color: #9a5b00; background: rgba(240, 180, 40, .22); padding: 0 3px; border-radius: 4px; }
html[data-theme="dark"] .note-bubble { background: #3a3012; border-color: #8a6d1e; color: #f3e3b3; }
html[data-theme="dark"] .mention-tag { color: #ffd479; background: rgba(255, 212, 121, .14); }

.composer-modes { display: flex; gap: 6px; margin: 0 0 8px; }
.mode-tab {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer;
}
.mode-tab.active { color: var(--accent-strong); background: var(--accent-dim); border-color: rgba(15, 159, 110, .3); }
.mode-tab:disabled { opacity: .5; cursor: not-allowed; }
#mode-note.active { color: #8a5a00; background: #fff1c2; border-color: #e0b84a; }
.composer-wrap.note-mode .message-composer textarea { background: #fff8e1; border-color: #e0b84a; }
.composer-wrap.note-mode .btn.primary { background: #c98a00; border-color: #c98a00; }
html[data-theme="dark"] .composer-wrap.note-mode .message-composer textarea { background: #2e2710; }
html[data-theme="dark"] #mode-note.active { color: #ffd479; background: #3a3012; }

.mention-badge {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: #e0a000; color: #fff; font-size: 12px; font-weight: 800;
}
.chip-count.mention { background: #e0a000; }

.filter-chip { white-space: nowrap; }
.composer-wrap.note-mode #attach-button,
.composer-wrap.note-mode #quick-button { display: none; }

/* --- quick unlock (v2.1.2) --- */
.unlock-body { min-height: 100vh; min-height: 100dvh; }
.unlock-card { text-align: center; user-select: none; -webkit-user-select: none; }
.unlock-card .login-logo { width: 64px; height: 64px; }
.unlock-card h1 { font-size: 1.3rem; margin: 10px 0 2px; }
.unlock-card .brand p { margin: 0; }
.pin-dots { display: flex; justify-content: center; gap: 18px; margin: 26px 0 8px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); transition: background .12s, transform .12s; }
.pin-dots span.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.pin-hidden-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.unlock-msg { min-height: 22px; margin: 4px 0 0; font-size: 14px; font-weight: 600; color: #d93a3a; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; margin: 18px 0 8px; }
.pin-pad button {
  -webkit-appearance: none; appearance: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  width: 76px; height: 76px; border-radius: 50%; border: 0; padding: 0;
  background: var(--panel-2); color: var(--text); font-family: inherit; font-size: 30px; font-weight: 500; line-height: 1;
  cursor: pointer; transition: background .1s, transform .1s;
}
.pin-pad button:active { background: var(--accent); color: #fff; transform: scale(.94); }
.pin-pad button[data-back] { background: transparent; font-size: 26px; color: var(--muted); }
.pin-pad button[data-back]:active { background: var(--panel-2); color: var(--text); }
.unlock-switch { margin-top: 10px; }
.link-button { -webkit-appearance: none; appearance: none; background: none; border: 0; padding: 10px; color: var(--accent-strong); cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; }
html[data-theme="dark"] .link-button { color: var(--accent); }
.shake { animation: pin-shake .35s; }
@keyframes pin-shake { 25% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 75% { transform: translateX(-5px); } }
@media (max-width: 600px) {
  .unlock-body { display: flex; align-items: stretch; justify-content: center; padding: 0; }
  .unlock-body .unlock-card {
    width: 100%; max-width: none; min-height: 100vh; min-height: 100dvh; margin: 0; border: 0; border-radius: 0;
    box-shadow: none; background: transparent; display: flex; flex-direction: column; justify-content: center;
    padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 16px);
  }
  .pin-pad { grid-template-columns: repeat(3, min(22vw, 80px)); gap: min(4vw, 18px) min(7vw, 28px); }
  .pin-pad button { width: min(22vw, 80px); height: min(22vw, 80px); }
}
@media (max-height: 700px) {
  .unlock-card .login-logo { width: 48px; height: 48px; }
  .unlock-body .unlock-card { padding-top: calc(env(safe-area-inset-top) + 12px); padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
  .pin-dots { margin-top: 16px; }
  .pin-pad { gap: 10px 24px; margin-top: 8px; }
  .pin-pad button { width: 70px; height: 70px; }
  .pin-pad { grid-template-columns: repeat(3, 70px); }
}
.signout-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.pin-input { max-width: 140px; letter-spacing: .3em; }

/* v2.1.1: filter row always fits the chat list (wraps instead of spilling out) */
.chat-filters { flex-wrap: wrap; gap: 6px; min-width: 0; }
.filter-chip { padding: 5px 11px; font-size: 12.5px; white-space: nowrap; }
.filter-select { margin-left: 0; flex: 0 1 auto; min-width: 0; max-width: 130px; font-size: 12.5px; }

/* v2.2: saved contact name */
.cp-name-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; }
.cp-name-row label { flex: 1; min-width: 0; }
.cp-name-row .btn { flex: none; }
.phonebook-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px 0 4px; max-width: 420px; }
.phonebook-stats div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.phonebook-stats span { display: block; line-height: 1.2; }
#phonebook-card details { margin-top: 10px; }
.phonebook-stats strong { display: block; font-size: 20px; }
.phonebook-help { margin: 10px 0 0; padding-left: 18px; }
.phonebook-help li { margin: 3px 0; }
.check-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 14px; }
