:root {
  --green: #1f7a4d;
  --green-soft: #e3f2ea;
  --bubble-out: #dcf3e5;
  --bubble-in: #ffffff;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --line: #e2e4df;
  --text: #1d211e;
  --muted: #67706a;
  --amber: #a86400;
  --amber-soft: #fff4e0;
  --red: #b3261e;
  --red-soft: #fdecea;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--red); min-height: 1.2em; }
.link { background: none; border: 0; color: var(--green); padding: 0; }
.link:hover { text-decoration: underline; }
.primary {
  background: var(--green); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 14px; font-weight: 600;
}

.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); display: inline-block; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; display: grid; gap: 12px;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 14px; }
.login-card input { padding: 10px; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- layout ---------- */
.app {
  height: 100vh; display: grid;
  grid-template-columns: 240px 340px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "banner banner banner" "side list thread";
}
.banner { grid-area: banner; padding: 10px 16px; font-size: 14px; display: flex; gap: 12px; align-items: center; }
.banner.warn { background: var(--amber-soft); color: var(--amber); border-bottom: 1px solid #f0d9b0; }
.banner.critical { background: var(--red-soft); color: var(--red); border-bottom: 1px solid #f3c4c0; font-weight: 600; }

.sidebar {
  grid-area: side; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 16px; min-height: 0;
}
.numbers { display: grid; gap: 2px; overflow-y: auto; }
.number {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px;
  text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--text);
}
.number:hover { background: var(--bg); }
.number.active { background: var(--green-soft); }
.number .name { font-weight: 600; font-size: 14px; }
.number .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.count { background: var(--green); color: #fff; border-radius: 999px; font-size: 11.5px; padding: 1px 7px; font-weight: 600; }
.count.zero { background: var(--line); color: var(--muted); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.user-row { display: flex; justify-content: space-between; align-items: center; }

/* ---------- conversation list ---------- */
.list-pane { grid-area: list; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.list-tools { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.list-tools input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.list-tools select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; background: var(--panel); }
.mobile-only { display: none; }
.chips { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--text); }
.chip.active { background: var(--green); border-color: var(--green); color: #fff; }

.conversations { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conversation {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.conversation:hover { background: #fafbf9; }
.conversation.active { background: var(--green-soft); }
.conversation .who { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation .when { font-size: 12px; color: var(--muted); }
.conversation .preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation .meta { display: flex; gap: 6px; align-items: center; grid-column: 1 / -1; font-size: 12px; }
.tag { font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.tag.awaiting { background: var(--amber-soft); color: var(--amber); font-weight: 600; }
.list-empty { padding: 24px; color: var(--muted); font-size: 14px; }

/* ---------- thread ---------- */
.thread-pane { grid-area: thread; display: flex; flex-direction: column; min-height: 0; }
.thread-empty { margin: auto; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.thread-head > div:nth-child(2) { flex: 1; min-width: 0; }
.thread-title { font-weight: 700; font-size: 16px; }
.back { display: none; font-size: 20px; }
.messages {
  flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px;
  background: #ecefe8;
}
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 8px; padding: 3px 10px; margin: 10px 0 4px; }
.bubble {
  max-width: min(560px, 78%); padding: 8px 10px 6px; border-radius: 10px;
  box-shadow: 0 1px 0 rgba(0,0,0,.06); font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble .foot { display: flex; gap: 8px; justify-content: flex-end; font-size: 11.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.bubble .note { font-size: 12.5px; margin-top: 4px; padding: 4px 6px; border-radius: 6px; white-space: normal; }
.note.edit { background: var(--bg); color: var(--muted); }
.note.revoke { background: var(--red-soft); color: var(--red); }
.note.unsupported { background: var(--amber-soft); color: var(--amber); }
.bubble img, .bubble video { max-width: 100%; max-height: 360px; border-radius: 8px; display: block; margin-bottom: 4px; }
.bubble audio { width: 260px; max-width: 100%; display: block; }
.attachment { display: inline-flex; gap: 6px; align-items: center; padding: 6px 8px; background: var(--bg); border-radius: 8px; margin-bottom: 4px; }
.thread-foot { padding: 8px 18px; background: var(--panel); border-top: 1px solid var(--line); }

/* ---------- alerts ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.25); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 17px; }
#alerts-body { padding: 8px 18px 18px; max-height: 70vh; overflow-y: auto; }
.alert { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sev { font-size: 11.5px; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; align-self: start; }
.sev.critical { background: var(--red-soft); color: var(--red); }
.sev.warning { background: var(--amber-soft); color: var(--amber); }
.sev.info { background: var(--bg); color: var(--muted); }

/* ---------- small screens: one pane at a time ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "banner" "list"; }
  .sidebar { display: none; }
  .thread-pane { display: none; }
  .app.show-thread { grid-template-areas: "banner" "thread"; }
  .app.show-thread .list-pane { display: none; }
  .app.show-thread .thread-pane { display: flex; }
  .back { display: inline; }
  .mobile-only { display: block; }
}
