:root {
  --ink-900: #151c2e;
  --ink-800: #1d273e;
  --ink-700: #212c47;
  --ink-500: #3a4763;
  --ink-300: #6b7690;
  --ink-200: #98a1b5;
  --line: #dce1ea;
  --line-soft: #e8ebf1;
  --canvas: #edeff4;
  --surface: #ffffff;
  --surface-sunk: #f6f7fa;
  --marigold: #d99612;
  --marigold-deep: #a96f06;
  --marigold-soft: #fdf3dd;
  --green: #2f8f6b;
  --blue: #3e7cb1;
  --red: #c0392b;
  --red-soft: #fbeceb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-panel: 0 1px 2px rgba(21, 28, 46, .06);
  --shadow-pop: 0 12px 32px rgba(21, 28, 46, .18);
  --rail: 72px;
  --list: 330px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Gujarati", Ubuntu, Cantarell, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-800);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 1em; }
a { color: var(--ink-700); }
small, .small { font-size: 13px; }
.muted { color: var(--ink-300); }
.tabular { font-variant-numeric: tabular-nums; }

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

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

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--ink-900);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--marigold);
  color: var(--ink-900);
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px;
  margin-bottom: 14px;
}

.rail a, .rail button {
  width: 48px; height: 48px;
  border: 0; background: none; cursor: pointer;
  border-radius: 10px;
  display: grid; place-items: center;
  color: #93a0bd;
  text-decoration: none;
  position: relative;
}
.rail a:hover, .rail button:hover { background: rgba(255,255,255,.08); color: #fff; }
.rail a.is-active { background: rgba(217,150,18,.18); color: var(--marigold); }
.rail .spacer { flex: 1; }
.rail svg { width: 21px; height: 21px; }

.rail-badge {
  position: absolute; top: 6px; right: 6px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px;
  background: var(--marigold); color: var(--ink-900);
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

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

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; }
.topbar .grow { flex: 1; }

.page { padding: 22px; max-width: 1180px; width: 100%; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
}
.panel + .panel { margin-top: 18px; }
.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.panel-body { padding: 18px; }
.panel-body > :last-child { margin-bottom: 0; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--ink-300); margin-bottom: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=search], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-800);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--ink-500);
  outline: none;
  box-shadow: 0 0 0 3px rgba(58,71,99,.12);
}
textarea { resize: vertical; min-height: 84px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 190px; }
.hint { font-size: 12px; color: var(--ink-300); margin-top: 5px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-800); }
.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  font: inherit; font-size: 14px; font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-800);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-sunk); }
.btn-primary { background: var(--ink-700); border-color: var(--ink-700); color: #fff; }
.btn-primary:hover { background: var(--ink-800); }
.btn-accent { background: var(--marigold); border-color: var(--marigold); color: #2a2100; }
.btn-accent:hover { background: #c9880d; }
.btn-danger { color: var(--red); border-color: #efc9c5; background: var(--red-soft); }
.btn-danger:hover { background: #f7dedb; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.inline-form { display: inline; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- feedback ---------- */
.flash-stack { position: fixed; top: 16px; right: 16px; z-index: 60; display: grid; gap: 8px; max-width: 380px; }
.flash {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink-800); color: #fff;
  box-shadow: var(--shadow-pop);
  font-size: 14px;
}
.flash.error { background: var(--red); }
.flash.success { background: var(--green); }

.notice {
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--marigold-soft); border: 1px solid #f0dcae;
  font-size: 14px; margin-bottom: 16px;
}
.notice.error { background: var(--red-soft); border-color: #efc9c5; }

.empty { padding: 44px 24px; text-align: center; color: var(--ink-300); }
.empty h3 { color: var(--ink-800); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 600; font-size: 13px; color: var(--ink-300);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-sunk); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  /* A short label broken across lines is never what you want; let the table scroll instead. */
  white-space: nowrap;
  background: var(--surface-sunk); color: var(--ink-500);
  border: 1px solid var(--line);
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: #e8f4ef; border-color: #bfe0d3; color: #1f6b4f; }
.badge.warn { background: var(--marigold-soft); border-color: #f0dcae; color: var(--marigold-deep); }
.badge.bad { background: var(--red-soft); border-color: #efc9c5; color: var(--red); }
.badge.info { background: #e9f1f8; border-color: #c6dcee; color: #2c5f8a; }

.avatar {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 50%;
  background: var(--ink-700); color: #fff;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600;
}
.avatar.sm { width: 30px; height: 30px; flex-basis: 30px; font-size: 12px; }

/* ---------- inbox ---------- */
.inbox { display: flex; height: 100vh; overflow: hidden; }

.thread-list {
  width: var(--list); flex: 0 0 var(--list);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.thread-list-head { padding: 14px; border-bottom: 1px solid var(--line-soft); display: grid; gap: 10px; }
.thread-list-head .row { display: flex; gap: 8px; align-items: center; }
.thread-filters { display: flex; gap: 6px; }
.chip {
  padding: 4px 11px; border-radius: 20px; font-size: 13px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-300); text-decoration: none;
}
.chip.is-active { background: var(--ink-700); border-color: var(--ink-700); color: #fff; }

.threads { flex: 1; overflow-y: auto; }
.thread {
  display: flex; gap: 11px; padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none; color: inherit;
}
.thread:hover { background: var(--surface-sunk); }
.thread.is-active { background: #eef1f7; box-shadow: inset 3px 0 0 var(--marigold); }
.thread-main { min-width: 0; flex: 1; }
.thread-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.thread-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-time { font-size: 12px; color: var(--ink-300); white-space: nowrap; }
.thread-preview {
  font-size: 13px; color: var(--ink-300);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unread-pill {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--marigold); color: #2a2100;
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}

.thread-view { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }
.thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.thread-head .grow { flex: 1; min-width: 0; }
.thread-head .name { font-weight: 600; }

.messages { flex: 1; overflow-y: auto; padding: 18px 20px 22px; display: flex; flex-direction: column; }
.day-divider { align-self: center; margin: 14px 0 10px; }
.day-divider span {
  background: #dfe3ec; color: var(--ink-500);
  padding: 3px 12px; border-radius: 20px; font-size: 12px;
}

/* One row per message; the row handles the side, the bubble handles the width. */
.msg { display: flex; margin-top: 2px; }
.msg.out { justify-content: flex-end; }
.msg.start { margin-top: 10px; }

.bubble {
  position: relative;
  max-width: min(640px, 74%);
  min-width: 96px;
  padding: 6px 11px 7px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.42;
}
.bubble.in {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.bubble.out {
  background: var(--ink-700);
  color: #eef1f7;
  border-top-right-radius: 4px;
}
.bubble.out a { color: #ffd98a; }
.bubble.failed { background: var(--red-soft); color: var(--red); border: 1px solid #efc9c5; }

/* Only the text preserves line breaks — never the whole bubble, or the markup's own
   newlines and indentation get rendered as blank lines. */
.bubble-text {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}
/* Reserves room on the last line so the clock never sits under the text. */
.bubble-text::after { content: ''; display: inline-block; width: 54px; height: 1px; }
.bubble.out .bubble-text::after { width: 72px; }

.bubble-meta {
  position: absolute; right: 10px; bottom: 6px;
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; line-height: 1;
  color: var(--ink-300);
  white-space: nowrap;
}
.bubble.out .bubble-meta { color: #9aa7c4; }
.tick.read { color: #7fb7e8; }
.tick svg { width: 15px; height: 15px; display: block; }
.bubble-error { font-size: 12px; margin-top: 4px; }

/* Media bubbles size to the media, so the clock goes back into normal flow. */
.bubble.has-media { min-width: 0; padding: 5px 5px 6px; }
.bubble.has-media .bubble-text { padding: 2px 6px 0; }
.bubble.has-media .bubble-text::after { content: none; }
.bubble.has-media .bubble-meta { position: static; justify-content: flex-end; margin: 3px 6px 0 0; }

.bubble img, .bubble video {
  display: block;
  width: auto; max-width: 100%;
  max-height: 380px;
  border-radius: 9px;
}
.bubble.has-media img, .bubble.has-media video { min-width: 180px; }
.bubble audio { width: 270px; max-width: 100%; margin: 2px 0; }
.bubble .media-note { display: block; padding: 6px 8px; font-size: 13px; }

.file-card {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  background: rgba(0,0,0,.05);
  text-decoration: none; color: inherit;
  min-width: 230px; max-width: 320px;
}
.bubble.out .file-card { background: rgba(255,255,255,.1); }
.file-card .ico {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 8px;
  background: var(--marigold); color: #2a2100;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
}
.file-card .txt { min-width: 0; }
/* Ellipsis needs a block box — it does nothing on a plain inline span. */
.file-card .nm {
  display: block; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-card .sz { display: block; font-size: 12px; opacity: .7; margin-top: 1px; }

.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 12px 18px; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  min-height: 42px; max-height: 160px; border-radius: 20px; padding: 10px 16px; resize: none;
}
.icon-btn {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
  display: grid; place-items: center; color: var(--ink-500);
}
.icon-btn:hover { background: var(--surface-sunk); }
.icon-btn.send { background: var(--ink-700); border-color: var(--ink-700); color: #fff; }
.icon-btn.send:hover { background: var(--ink-800); }
.icon-btn svg { width: 19px; height: 19px; }

.window-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--marigold-soft); border: 1px solid #f0dcae;
  font-size: 13.5px; margin-bottom: 10px;
}
.window-bar.open { background: #e8f4ef; border-color: #bfe0d3; }

.details {
  width: 300px; flex: 0 0 300px;
  background: var(--surface); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 18px;
}
.details h3 { margin-top: 18px; }
.details h3:first-child { margin-top: 0; }
.detail-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* Rule editor beside its test panel; stacks on narrow screens. */
.split-wide { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.split-wide > .panel { margin-top: 0; }
@media (max-width: 1000px) { .split-wide { grid-template-columns: 1fr; } }

/* ---------- states and cities ---------- */
.split { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.split > .panel + .panel { margin-top: 0; }
.state-list { max-height: 520px; overflow-y: auto; }
.state-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line-soft);
  text-decoration: none; color: inherit; font-size: 14px;
}
.state-row:hover { background: var(--surface-sunk); }
.state-row.is-active { background: #eef1f7; box-shadow: inset 3px 0 0 var(--marigold); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .state-list { max-height: 280px; }
}

/* ---------- tag editor ---------- */
.tag-editor { display: grid; gap: 8px; }
.tag-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag-row input[type=color] { width: 40px; flex: 0 0 40px; padding: 3px; height: 34px; }
.tag-row input[type=text] { width: 240px; flex: 0 1 240px; }

/* Brief highlight on the row that was just saved. */
@keyframes row-saved-fade {
  from { background: var(--marigold-soft); }
  to { background: transparent; }
}
tbody tr.row-saved { animation: row-saved-fade 1.6s ease-out; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(21,28,46,.5);
  display: none; place-items: center; z-index: 50; padding: 18px;
}
.modal-backdrop.is-open { display: grid; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: min(540px, 100%); max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-pop);
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- auth + install ---------- */
.centered {
  min-height: 100vh; display: grid; place-items: center;
  padding: 22px; background: var(--ink-900);
}
.card-narrow {
  width: min(430px, 100%);
  background: var(--surface); border-radius: 14px; padding: 28px;
  box-shadow: var(--shadow-pop);
}
.card-wide { width: min(720px, 100%); }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: var(--marigold); color: var(--ink-900);
  display: grid; place-items: center; font-weight: 700; font-size: 19px;
  margin-bottom: 16px;
}

.steps { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.step-dot {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--ink-300);
  padding: 5px 11px; border-radius: 20px; background: var(--surface-sunk);
}
.step-dot.is-current { background: var(--ink-700); color: #fff; }
.step-dot.is-done { background: #e8f4ef; color: #1f6b4f; }

.check-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px;
}
.check-row .status { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: 0 0 22px; }
.check-row .status.pass { background: #e8f4ef; color: #1f6b4f; }
.check-row .status.fail { background: var(--red-soft); color: var(--red); }
.check-row .status.warn { background: var(--marigold-soft); color: var(--marigold-deep); }
.check-row .grow { flex: 1; }

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; background: var(--surface-sunk);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; overflow-x: auto; word-break: break-all;
}

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat .num { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 13px; color: var(--ink-300); }

.progress { height: 8px; border-radius: 4px; background: var(--line-soft); overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .sent { background: var(--blue); }
.progress .failed { background: var(--red); }
.progress.lg { height: 10px; border-radius: 5px; }

/* Numbers in a stat tile: the count, then its share beside it. */
.stat .num-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stat .pct { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-300); }
.stat .pct.good { color: var(--green); }
.stat .pct.bad { color: var(--red); }
.stat .sub { font-size: 12px; color: var(--ink-200); margin-top: 3px; }

/* Period chips. Unlike the inbox's three short chips these are long labels, so the
   row wraps while each chip stays on one line. */
.range-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.range-filters .chip { white-space: nowrap; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 9px; font-size: 12.5px; color: var(--ink-300); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 8px; }
.legend-dot.sent { background: var(--blue); }
.legend-dot.failed { background: var(--red); }
.legend-dot.waiting { background: var(--line-soft); border: 1px solid var(--line); }

.pagination { display: flex; gap: 8px; align-items: center; padding: 14px 18px; }

/* ---------- responsive ---------- */
.only-mobile { display: none; }

@media (max-width: 1100px) {
  .details { display: none; }
}

@media (max-width: 780px) {
  :root { --rail: 60px; }
  .only-mobile { display: inline-flex; }
  .inbox { height: calc(100vh); }
  .thread-list { width: 100%; flex-basis: 100%; }
  .inbox.has-active .thread-list { display: none; }
  .inbox:not(.has-active) .thread-view { display: none; }
  .bubble { max-width: 86%; }
  .page { padding: 14px; }
  .rail { flex-direction: row; width: 100%; height: auto; position: static; padding: 6px; }
  .shell { flex-direction: column-reverse; }
  .rail-mark { display: none; }
  .rail .spacer { flex: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .thread, .btn, .chip { transition: background-color .12s ease; }
}
