/* WhatsApp-ish: white surfaces, the brand greens, generous whitespace.
   #25D366 is the brand green, #128C7E the darker "teal green", #075E54 the header teal. */
:root {
  --green: #25d366;
  --green-dark: #128c7e;
  --teal: #075e54;
  --green-wash: #e7fce3;
  --green-line: #b9e6c4;

  --bg: #f0f2f5;      /* the chat-list grey WhatsApp Web uses behind panels */
  --surface: #ffffff;
  --line: #e4e6eb;
  --ink: #111b21;
  --ink-2: #3b4a54;
  --muted: #667781;

  --red: #d9342b;
  --red-wash: #fdeceb;
  --amber: #b26a00;
  --amber-wash: #fff5e5;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 20, 26, .08), 0 1px 3px rgba(11, 20, 26, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.15rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: .8rem; margin: 0 0 .75rem; font-weight: 600; color: var(--muted);
     text-transform: uppercase; letter-spacing: .06em; }
h3 { margin: 0 0 .5rem; font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
@media (max-width: 860px) { .shell { grid-template-columns: 1fr; } }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--teal);
  color: #fff;
  display: flex; flex-direction: column;
  padding: 1rem .75rem;
}
@media (max-width: 860px) { .sidebar { flex-direction: row; align-items: center; flex-wrap: wrap; gap: .5rem; } }

.side-brand { display: flex; align-items: center; gap: .6rem; padding: .3rem .5rem 1.1rem; }
.wa-mark { width: 30px; height: 30px; fill: var(--green); flex: none; }
.side-title { font-weight: 600; font-size: 1.02rem; }
.side-host { font-size: .74rem; opacity: .65; }

.nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
@media (max-width: 860px) { .nav { flex-direction: row; flex: 1 1 100%; } }

.nav-item {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  background: transparent; border: 0; border-radius: 10px;
  padding: .6rem .65rem; cursor: pointer; text-align: left;
  color: rgba(255,255,255,.72); font: inherit;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-text { display: flex; flex-direction: column; min-width: 0; }
.nav-label { font-weight: 600; font-size: .9rem; }
.nav-sub { font-size: .7rem; opacity: .65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.35); flex: none; }
.nav-dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,.22); }
.nav-dot.warn { background: #ffb020; box-shadow: 0 0 0 3px rgba(255,176,32,.2); }
.nav-dot.bad { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.2); }

.side-foot { display: flex; flex-direction: column; gap: .2rem; padding-top: .75rem; border-top: 1px solid rgba(255,255,255,.12); }
@media (max-width: 860px) { .side-foot { flex-direction: row; border: 0; padding-top: 0; } }
.linkish { background: none; border: 0; color: rgba(255,255,255,.72); font: inherit;
  text-align: left; padding: .4rem .65rem; cursor: pointer; border-radius: 8px; }
.linkish:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ---------- main ---------- */
.main { padding: 1.1rem 1.35rem 2rem; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.top-right { display: flex; align-items: center; gap: .5rem; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c9ced3; display: inline-block; }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }

.panels { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 1050px) { .panels { grid-template-columns: 1fr; } }
.span2 { grid-column: 1 / -1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; box-shadow: var(--shadow); }
.skeleton { color: var(--muted); }

/* ---------- alerts ---------- */
#alerts:not(:empty) { margin-bottom: 1rem; display: grid; gap: .6rem; }
.alert { border-radius: 10px; padding: .75rem .9rem; border: 1px solid; font-size: .88rem; }
.alert strong { display: block; margin-bottom: .1rem; }
.alert.error { background: var(--red-wash); border-color: #f3bdb9; color: #7d1a15; }
.alert.warn { background: var(--amber-wash); border-color: #f0d49b; color: #7a4a00; }

/* ---------- process ---------- */
.proc-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.proc-name { font-weight: 600; font-size: 1rem; }
.pill { font-size: .7rem; padding: .12rem .5rem; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); background: #f6f7f9; font-weight: 600; letter-spacing: .02em; }
.pill.online { color: #0b6b3a; background: var(--green-wash); border-color: var(--green-line); }
.pill.stopped { color: var(--muted); }
.pill.errored { color: #7d1a15; background: var(--red-wash); border-color: #f3bdb9; }
.pill.warn { color: #7a4a00; background: var(--amber-wash); border-color: #f0d49b; }
.stats { color: var(--muted); font-size: .84rem; margin: .55rem 0 0; font-variant-numeric: tabular-nums; }
.stats b { color: var(--ink-2); font-weight: 600; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.inline { display: inline-flex; align-items: center; gap: .35rem; margin: 0; }

/* ---------- buttons ---------- */
button { font: inherit; padding: .45rem .85rem; border-radius: 8px; cursor: pointer;
  background: #fff; color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
button:hover:not(:disabled) { background: #f6f7f9; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--green-dark); border-color: var(--green-dark); }
button.ghost { background: transparent; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.danger:hover:not(:disabled) { background: #b92b23; }
button.subtle { padding: .28rem .6rem; font-size: .8rem; }

/* ---------- session ---------- */
.verdict { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.verdict.HEALTHY { color: var(--green-dark); }
.verdict.DEGRADED { color: var(--amber); }
.verdict.UNREACHABLE { color: var(--red); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .9rem; margin-top: .85rem; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.callout { margin-top: .8rem; padding: .65rem .75rem; border-radius: 9px; font-size: .85rem;
  background: var(--amber-wash); border: 1px solid #f0d49b; color: #7a4a00; }
.stamp { margin-top: .7rem; font-size: .8rem; }

/* ---------- outbox ---------- */
.counts { font-weight: 500; color: var(--muted); font-size: .76rem; margin-left: .5rem;
  text-transform: none; letter-spacing: 0; }
.chat-row { border-top: 1px solid var(--line); padding: .6rem 0; }
.chat-row:first-child { border-top: 0; }
.chat-head { display: flex; align-items: baseline; gap: .55rem; cursor: pointer; flex-wrap: wrap; }
.chat-name { font-weight: 600; }
.jid { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .75rem; }
.chat-nums { margin-left: auto; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg-row { background: #f7f9fa; border: 1px solid var(--line); border-radius: 9px;
  padding: .6rem; margin: .5rem 0; font-size: .84rem; }
.msg-row .err { color: var(--red); margin-top: .25rem; }
.chip { font-size: .68rem; padding: .08rem .45rem; border: 1px solid var(--line);
  border-radius: 999px; color: var(--muted); background: #f6f7f9; }

/* ---------- activity ---------- */
.act { display: flex; align-items: center; gap: .5rem; padding: .45rem 0;
  border-top: 1px solid var(--line); font-size: .87rem; }
.act:first-child { border-top: 0; }
.act .nums { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; }
.act.quiet { opacity: .45; }

/* ---------- logs ---------- */
.chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .6rem; }
.chips button { padding: .22rem .6rem; font-size: .78rem; border-radius: 999px; }
.chips button.active { background: var(--green-wash); border-color: var(--green-line); color: #0b6b3a; font-weight: 600; }
.logpane {
  background: #fbfcfd; border: 1px solid var(--line); border-radius: 9px;
  padding: .7rem; height: 360px; overflow: auto; margin: .6rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .755rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.logline { display: block; }
.logline .t { color: #93a1ab; }
.logline .g { color: var(--green-dark); font-weight: 600; }
.logline.err .m { color: var(--red); }
.logline.marker { color: var(--amber); font-style: italic; }

/* ---------- forms ---------- */
input[type="text"], input:not([type]), input[type="password"], textarea {
  width: 100%; font: inherit; padding: .5rem .65rem; border-radius: 9px;
  background: #fff; border: 1px solid var(--line); color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid rgba(37,211,102,.35); outline-offset: 0; border-color: var(--green); }
textarea { resize: vertical; }
label { display: block; font-size: .8rem; color: var(--muted); margin: .65rem 0 .25rem; }
.target { font-size: 1.1rem; font-weight: 600; margin: .15rem 0; }
.preview { background: var(--green-wash); border: 1px solid var(--green-line); border-radius: 9px;
  padding: .65rem; white-space: pre-wrap; font-size: .82rem; max-height: 180px; overflow: auto; margin: .6rem 0 0; }
.error-box { background: var(--red-wash); border: 1px solid #f3bdb9; color: #7d1a15;
  border-radius: 9px; padding: .55rem .7rem; font-size: .85rem; margin-top: .6rem; }
.ok-box { background: var(--green-wash); border: 1px solid var(--green-line); color: #0b6b3a;
  border-radius: 9px; padding: .55rem .7rem; font-size: .85rem; }
.note { background: #f7f9fa; border: 1px dashed var(--line); border-radius: 9px;
  padding: .7rem .8rem; font-size: .86rem; color: var(--muted); }

/* ---------- audit ---------- */
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(11,20,26,.45); display: grid;
  place-items: center; z-index: 50; padding: 1rem; }
.modal-card { background: #fff; border-radius: var(--radius); padding: 1.25rem;
  max-width: 520px; width: 100%; box-shadow: 0 12px 32px rgba(11,20,26,.2); }
.warn-text { background: var(--red-wash); border: 1px solid #f3bdb9; color: #7d1a15;
  border-radius: 9px; padding: .7rem; font-size: .86rem; margin: .6rem 0; }
.modal code { background: #f0f2f5; padding: .05rem .3rem; border-radius: 4px; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh;
  background: linear-gradient(180deg, var(--teal) 0 200px, var(--bg) 200px 100%); }
.login-card { background: #fff; border-radius: var(--radius); padding: 1.75rem;
  width: min(380px, 92vw); box-shadow: 0 10px 30px rgba(11,20,26,.16); }
.login-card h1 { font-size: 1.3rem; margin-bottom: .1rem; }
.login-card button { width: 100%; margin-top: 1rem; }
.login-mark { width: 44px; height: 44px; fill: var(--green); display: block; margin-bottom: .6rem; }

/* ---------- subnav ---------- */
.subnav { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.subnav button {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: .55rem .85rem; color: var(--muted); font-weight: 600; font-size: .88rem; cursor: pointer;
}
.subnav button:hover:not(:disabled) { color: var(--ink); background: none; }
.subnav button.active { color: var(--green-dark); border-bottom-color: var(--green); }
.subnav button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- queue tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.tile { background: #f7f9fa; border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .5rem; text-align: center; }
.tile .n { display: block; font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.tile .l { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile.bad { background: var(--red-wash); border-color: #f3bdb9; }
.tile.bad .n { color: var(--red); }

/* ---------- chats list ---------- */
.chat-line { display: flex; align-items: center; gap: .6rem; padding: .5rem 0;
  border-top: 1px solid var(--line); font-size: .88rem; }
.chat-line:first-child { border-top: 0; }
.chat-line .chat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-line .jid { flex: none; }
.chat-kind { flex: none; font-size: .66rem; padding: .08rem .45rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.chat-kind.grp { background: var(--green-wash); color: #0b6b3a; border: 1px solid var(--green-line); }
.chat-kind.dm { background: #eef1f4; color: var(--muted); border: 1px solid var(--line); }

/* ---------- templates ---------- */
.tpl { border-top: 1px solid var(--line); padding: .65rem 0; }
.tpl:first-child { border-top: 0; }
.tpl-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tpl-name { font-weight: 600; }
.tpl-body { background: #f7f9fa; border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .6rem; margin: .4rem 0 0; font-size: .78rem; white-space: pre-wrap;
  max-height: 110px; overflow: auto; color: var(--ink-2); }

.hint { font-size: .78rem; margin-top: .35rem; }
.hint code { background: #f0f2f5; padding: .05rem .3rem; border-radius: 4px; font-size: .95em; }

/* ---------- chat adder ---------- */
.adder { border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd; margin-top: .3rem; }
.adder > summary { cursor: pointer; padding: .55rem .8rem; font-weight: 600; font-size: .86rem; color: var(--green-dark); }
.adder[open] > summary { border-bottom: 1px solid var(--line); }
.adder-body { padding: .8rem; }
.grid3 { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: .6rem; }
@media (max-width: 720px) { .grid3 { grid-template-columns: 1fr; } }
.grid3 label { margin-top: 0; }
select { width: 100%; font: inherit; padding: .5rem .6rem; border-radius: 9px;
  background: #fff; border: 1px solid var(--line); color: var(--ink); }

/* ---------- message log ---------- */
.msg-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.msg-when { margin-left: auto; color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.chat-line .chat-name .chip { margin-left: .35rem; }

/* ---------- diagnostics ---------- */
.diag-layer { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 1.1rem 0 .4rem; font-weight: 600; }
.diag-group:first-child .diag-layer { margin-top: .6rem; }
.diag { border: 1px solid var(--line); border-radius: 9px; margin-bottom: .4rem; background: #fff; }
.diag > summary { cursor: pointer; padding: .55rem .7rem; display: flex; align-items: center;
  gap: .5rem; flex-wrap: wrap; list-style: none; }
.diag > summary::-webkit-details-marker { display: none; }
.diag[open] > summary { border-bottom: 1px solid var(--line); }
.diag-code { font-weight: 600; font-size: .88rem; }
.diag-detail { margin-left: auto; color: var(--muted); font-size: .78rem; text-align: right; }
.diag-state { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #cfd6db; }
.diag-state.ok { background: var(--green); }
.diag-state.warn { background: #e8a33d; }
.diag-state.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(217,52,43,.15); }
.diag-state.unknown { background: #cfd6db; }
.diag-body { padding: .7rem; }
.diag-body .kv { grid-template-columns: 5.5rem 1fr; margin-top: 0; }
.diag-body .kv dd { color: var(--ink); }
.diag-body code { background: #f0f2f5; padding: .05rem .3rem; border-radius: 4px; font-size: .93em; }
.chip.seen { background: var(--amber-wash); border-color: #f0d49b; color: #7a4a00; font-weight: 600; }
.diag.hit { outline: 2px solid var(--green); outline-offset: 1px; }
#diag-search { margin-top: .2rem; }

/* ---------- why? links ---------- */
.why { background: transparent; border: 0; padding: 0 .15rem; margin-left: .35rem;
  color: var(--green-dark); font: inherit; font-size: .82em; font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer; border-radius: 4px; }
.why:hover { background: var(--green-wash); }
.callout .why, .err .why { color: inherit; }

/* ---------- flash ---------- */
#flash:not(:empty) { margin-bottom: 1rem; display: grid; gap: .6rem; }
#flash .alert { position: relative; padding-right: 2.2rem; }
.flash-x { position: absolute; top: .35rem; right: .45rem; background: none; border: 0;
  font-size: 1.1rem; line-height: 1; color: inherit; opacity: .6; cursor: pointer; padding: .1rem .3rem; }
.flash-x:hover { opacity: 1; background: none; }
