:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1c2330;
  --muted: #6b7484;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info-soft: #eaf1fb;
  --code: #f0f2f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #1a2029;
    --border: #2a323e;
    --text: #e5e9f0;
    --muted: #97a1b2;
    --accent: #2dd4bf;
    --accent-soft: #123a37;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --bad: #f87171;
    --bad-soft: #3b1717;
    --info-soft: #172538;
    --code: #232a35;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 Vazirmatn, "Segoe UI", Tahoma, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code, pre, input[dir="ltr"] { font-family: ui-monospace, Consolas, monospace; font-size: .88em; }
code { background: var(--code); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.small, small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.wrap { white-space: pre-wrap; word-break: break-word; }
.err { color: var(--bad); }
code.err { background: var(--bad-soft); display: inline-block; max-width: 100%; overflow-wrap: anywhere; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
#nav { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; flex: 1; }
#nav a { padding: .3rem .7rem; border-radius: 8px; color: var(--muted); }
#nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
#nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { margin-inline-start: auto; }
.nav-toggle { display: none; margin-inline-start: auto; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
main.narrow { max-width: 440px; padding-top: 10vh; }

.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head > :last-child:not(h1) { margin-inline-start: auto; }
.head-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.lead { color: var(--muted); margin: -.25rem 0 1.25rem; max-width: 70ch; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1.1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.card.alert { border-color: var(--warn); background: var(--warn-soft); }
.card.reveal, .reveal { border-color: var(--accent); background: var(--accent-soft); border-radius: var(--radius); }
.reveal { padding: .75rem 1rem; }

.auth { text-align: center; }
.auth .stack { text-align: start; margin-top: 1rem; }
.auth-icon { display: block; margin: .25rem auto .5rem; }

/* status */
.state { padding: .2rem .8rem; border-radius: 99px; font-size: .9rem; font-weight: 600; }
.state-ok { background: var(--ok-soft); color: var(--ok); }
.state-busy, .state-degraded { background: var(--warn-soft); color: var(--warn); }
.state-stalled, .state-down { background: var(--bad-soft); color: var(--bad); }

.badge { display: inline-block; padding: 0 .55em; border-radius: 6px; font-size: .8rem; background: var(--code); color: var(--muted); white-space: nowrap; }
.st-sent { background: var(--ok-soft); color: var(--ok); }
.st-pending, .st-digested { background: var(--info-soft); color: var(--accent); }
.st-failed, .st-expired, .st-unrouted { background: var(--bad-soft); color: var(--bad); }
.prio { font-size: .85rem; white-space: nowrap; }
.prio-critical { color: var(--bad); font-weight: 600; }
.prio-high { color: var(--warn); }
code.type { font-size: .75rem; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.tile b { display: block; font-size: 1.6rem; line-height: 1.2; }
.tile span { color: var(--muted); font-size: .85rem; }
.tile.warn b { color: var(--warn); }

.steps { margin: 0; padding-inline-start: 1.3rem; }
.steps li { padding: .15rem 0; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.steps li.done a { color: inherit; }

.lanes { list-style: none; padding: 0; margin: 0; }
.lanes li { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; padding: .5rem 0; border-top: 1px solid var(--border); }

/* tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: start; font-weight: 600; color: var(--muted); font-size: .82rem; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
table.list td { padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.off td { opacity: .55; }
td.empty, p.empty { color: var(--muted); text-align: center; padding: 1.5rem; }
td.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.more { text-align: center; margin: .75rem 0 0; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* forms */
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .65rem; width: 100%;
}
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; line-height: 1.6; unicode-bidi: plaintext; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button, .button {
  font: inherit; cursor: pointer; display: inline-block;
  padding: .42rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.small { padding: .15rem .6rem; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--muted); padding: .3rem .6rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; align-items: end; }
.grid .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0; }
legend { padding: 0 .4rem; font-weight: 600; }
.form-actions { display: flex; gap: 1rem; align-items: center; }
.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: end; }
.filters label { min-width: 170px; flex: 1; }
.copy-row { display: flex; gap: .4rem; }
.recipients { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .6rem; }
.recipient { display: grid; grid-template-columns: 2fr 1fr 1.5fr auto; gap: .5rem; }
.recipient:not(:has(input.short)) { grid-template-columns: 2fr 1.5fr auto; }
details.inline > summary { cursor: pointer; color: var(--accent); }
details.inline[open] { flex-basis: 100%; }
details.inline form { margin: .6rem 0; }
.help { color: var(--muted); font-size: .9rem; }
.help summary { cursor: pointer; color: var(--accent); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .25rem 0; }
pre.code { background: var(--code); padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; text-align: left; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.flash-info { background: var(--info-soft); }
.note { background: var(--info-soft); padding: .6rem .9rem; border-radius: 8px; }

/* message preview */
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 1.1rem; align-items: start; }
.preview { position: sticky; top: 4.5rem; }
.bubble { background: var(--bg); border-radius: 14px; padding: .8rem; }
.message { margin: 0; white-space: pre-wrap; word-break: break-word; font: inherit; background: var(--surface); border-radius: 12px; padding: .7rem .9rem; }
.message.rich { white-space: normal; }
.msg-button { display: block; text-align: center; margin-top: .35rem; padding: .35rem; border-radius: 10px; background: var(--surface); color: var(--accent); font-size: .9rem; }
.delivery { border-top: 1px solid var(--border); padding: .8rem 0; }
.delivery:first-of-type { border-top: 0; }
.delivery header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.delivery p { margin: .3rem 0; }
.delivery details summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.delivery pre.message { background: var(--bg); margin-top: .4rem; }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .preview { position: static; }
}
@media (max-width: 720px) {
  .top { flex-wrap: wrap; padding: .5rem 1rem; }
  .nav-toggle { display: inline-block; }
  #nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; }
  #nav.open { display: flex; }
  .logout { margin: 0; }
  main { padding: 1rem 1rem 3rem; }
  .recipient, .recipient:not(:has(input.short)) { grid-template-columns: 1fr auto; }
  .recipient input:not(:first-child) { grid-column: 1; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dd { margin-bottom: .4rem; }
}
