:root {
  --panel: #ffffff;
  --head: #f0f2f5;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --line: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --icon: #54656f;
  --green: #00a884;
  --green-ink: #008069;
  --chip: #f0f2f5;
  --chip-on: #d9fdd3;
  --out: #d9fdd3;
  --in: #ffffff;
  --wallpaper: #efeae2;
  --search: #f0f2f5;
  --field: #ffffff;
  --day: #ffffff;
  --badge: #25d366;
  --danger: #ea0038;
  --warn-bg: #fff4d6;
  --warn: #8a6a12;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  color: var(--text);
  background: var(--panel);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14.5px;
}

:root[data-theme="dark"] {
  --panel: #111b21;
  --head: #202c33;
  --hover: #202c33;
  --active: #2a3942;
  --line: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --icon: #aebac1;
  --green: #00a884;
  --green-ink: #00a884;
  --chip: #202c33;
  --chip-on: #0b3d33;
  --out: #005c4b;
  --in: #202c33;
  --wallpaper: #0b141a;
  --search: #202c33;
  --field: #2a3942;
  --day: #182229;
  --badge: #00a884;
  --danger: #f15c6d;
  --warn-bg: #3a3118;
  --warn: #f7c948;
  --shadow: 0 1px 0.5px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--panel); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 16px; font-weight: 500; }
h2 { font-size: 15px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.wa {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  background: var(--panel);
}

.chats {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.pane-head, .chat-head, .page-head {
  height: 60px;
  min-height: 60px;
  background: var(--head);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { color: #25d366; display: grid; }
.logo svg { width: 28px; height: 28px; }
.word { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.head-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  display: grid;
  place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--active); }
.icon-btn.on { color: var(--green); }

.search-wrap { position: relative; padding: 8px 12px 4px; background: var(--panel); }
.search-ico {
  position: absolute;
  left: 22px;
  top: 8px;
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}
.search-ico svg { width: 18px; height: 18px; }
.search-wrap input, .composer textarea, input, textarea, select {
  width: 100%;
  border: 0;
  background: var(--field);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
.search-wrap input { height: 35px; padding: 0 12px 0 36px; background: var(--search); }
::placeholder { color: var(--muted); opacity: 1; }
.filters { display: flex; gap: 8px; padding: 8px 12px 10px; }
.chip {
  border: 0;
  background: var(--chip);
  color: var(--icon);
  border-radius: 16px;
  height: 32px;
  padding: 0 12px;
}
.chip.on { background: var(--chip-on); color: var(--green-ink); }
.chat-list { overflow: auto; flex: 1; }
.person {
  position: relative;
  width: 100%;
  height: 72px;
  display: grid;
  grid-template-columns: 49px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0 15px 0 13px;
}
.person::after {
  content: "";
  position: absolute;
  left: 74px;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--line);
}
.person:hover { background: var(--hover); }
.person:hover::after, .person.active::after { background: transparent; }
.person.active { background: var(--active); }
.who { min-width: 0; display: grid; gap: 2px; }
.who strong { font-size: 16px; font-weight: 400; }
.preview {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trail { display: grid; justify-items: end; gap: 6px; }
.when { color: var(--muted); font-size: 12px; }
.when.fresh { color: var(--green); }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--badge);
  color: #fff;
  font-size: 12px;
  display: grid;
  place-items: center;
}
.avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 500;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.tone-0 { background: #00a884; }
.tone-1 { background: #53bdeb; }
.tone-2 { background: #7f66ff; }
.tone-3 { background: #e6a23c; }
.tone-4 { background: #ee6c8a; }
.tone-5 { background: #25d366; }

.thread {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--wallpaper);
  background-image: radial-gradient(rgba(17, 27, 33, 0.045) 0.8px, transparent 0.9px);
  background-size: 18px 18px;
}
:root[data-theme="dark"] .thread {
  background-image: radial-gradient(rgba(233, 237, 239, 0.05) 0.8px, transparent 0.9px);
}
.chat-id { min-width: 0; display: grid; }
.chat-id strong { font-size: 16px; font-weight: 400; }
.chat-sub { color: var(--muted); font-size: 13px; }
.sender {
  width: auto;
  margin-left: auto;
  background: transparent;
  color: var(--muted);
  padding: 0;
}
.messages {
  flex: 1;
  overflow: auto;
  padding: 12px 7% 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.day {
  align-self: center;
  margin: 8px 0 10px;
  background: var(--day);
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.bubble {
  align-self: flex-start;
  width: fit-content;
  max-width: min(620px, 75%);
  margin: 1px 0 2px;
  padding: 6px 7px 8px 9px;
  border-radius: 7.5px;
  background: var(--in);
  box-shadow: var(--shadow);
  display: flow-root;
}
.bubble.out { align-self: flex-end; background: var(--out); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta {
  float: right;
  margin: 6px 0 0 12px;
  font-size: 11px;
  line-height: 15px;
  color: var(--muted);
  white-space: nowrap;
}
.tick-read { color: #53bdeb; }
.empty-chat {
  margin: auto;
  color: var(--muted);
  background: var(--day);
  border-radius: 8px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
}
.composer {
  background: var(--head);
  padding: 5px 16px 8px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea {
  min-height: 42px;
  max-height: 120px;
  background: var(--field);
  border-radius: 8px;
}
.send {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.send svg { width: 22px; height: 22px; }
.send:hover { color: var(--green); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 16px 0; background: var(--head); }
.quick button, .btn.secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 500;
}
.template-box {
  background: var(--head);
  padding: 12px 16px;
  display: grid;
  gap: 10px;
}
.btn {
  border: 0;
  border-radius: 24px;
  padding: 10px 18px;
  background: var(--green);
  color: #111b21;
  font-weight: 600;
  justify-self: start;
}
.btn.danger { background: var(--danger); color: #fff; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }
#thread-error { padding: 0 16px 10px; background: var(--head); }
.boot-error { padding: 24px; }
.muted { color: var(--muted); }
.empty-note { padding: 16px; }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; }

.page { flex: 1; overflow: auto; background: var(--panel); background-image: none; min-height: 0; }
.page-body { padding: 16px; display: grid; gap: 12px; align-content: start; }
.card { background: var(--head); border-radius: 8px; padding: 14px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input, .row select, .row textarea { flex: 1; min-width: 140px; background: var(--field); }
input[type="checkbox"] { width: auto; min-width: 0; flex: 0 0 auto; accent-color: var(--green); }
textarea { min-height: 80px; resize: vertical; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.checks { max-height: 260px; overflow: auto; background: var(--panel); border-radius: 8px; }
.checkline { display: flex; gap: 8px; align-items: center; padding: 8px 10px; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; align-items: start; }
.account { display: grid; gap: 4px; }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--wallpaper);
  background-image: radial-gradient(rgba(17, 27, 33, 0.045) 0.8px, transparent 0.9px);
  background-size: 18px 18px;
}
:root[data-theme="dark"] .gate {
  background-image: radial-gradient(rgba(233, 237, 239, 0.05) 0.8px, transparent 0.9px);
}
.gate-card {
  width: min(400px, 100%);
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(11, 20, 26, 0.12);
  padding: 22px 22px 18px;
  display: grid;
  gap: 14px;
}
.gate-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pass-field { position: relative; }
.pass-field input { height: 44px; padding-right: 46px; background: var(--search); }
.pass-toggle {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  display: grid;
  place-items: center;
}
.pass-toggle svg { width: 20px; height: 20px; }
.pass-toggle:hover { background: var(--active); }
.gate .btn { width: 100%; }
.gate .error { min-height: 1.2em; }

@media (max-width: 860px) {
  .wa { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 40vh) minmax(0, 1fr); }
  .messages { padding: 12px; }
  .split { grid-template-columns: 1fr; }
}
