/* Provisional light-mode palette inspired by WhatsApp - tune here only. */
:root {
  color-scheme: light;
  --page-bg: #e9edef;
  --chat-bg: #efeae2;
  --header-bg: #008069;
  --header-fg: #ffffff;
  --bubble-business: #ffffff;
  --bubble-user: #d9fdd3;
  --text: #111b21;
  --text-muted: #54656f;
  --accent: #008069;
  --accent-strong: #00a884;
  --selected-bg: #e7f6f1;
  --border: #d1d7db;
  --system-bg: #fff6c9;
  --error-bg: #fde8e8;
  --error-fg: #8a1c1c;
  --warn-fg: #7a4b00;
  --banner-bg: #1f2c33;
  --banner-fg: #ffffff;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --radius: 8px;
  --font: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.sim-banner {
  background: var(--banner-bg);
  color: var(--banner-fg);
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: center;
  text-align: center;
}

.stage {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
}

/* Phone frame */
.phone {
  position: relative;
  width: 390px;
  max-width: 100%;
  height: min(820px, calc(100dvh - 90px));
  min-height: 520px;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  border: 10px solid #1b1b1b;
  border-radius: 36px;
  overflow: hidden;
  overflow: clip; /* not a scroll container, so focusing a list row cannot shift the header */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  background: var(--header-bg);
  color: var(--header-fg);
}
.chat-header .icon-btn { color: var(--header-fg); }
.chat-header .icon-btn:disabled { opacity: 1; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
}
.icon-btn svg { width: 22px; height: 22px; }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dfe5e7;
  color: var(--header-bg);
  font-weight: 700;
}
.chat-name { font-weight: 600; font-size: 16px; }
.chat-status { font-size: 12px; opacity: 0.9; }

.bridge-error {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--error-bg);
  color: var(--error-fg);
  font-size: 13px;
}
.bridge-error[hidden] { display: none; }
.bridge-error button {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  padding: 2px 8px;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Bubble side follows the speaker: business on the right, user on the left (dir=rtl). */
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 4px; }
.msg.business { align-self: flex-start; }
.msg.user { align-self: flex-end; }

.bubble {
  position: relative;
  padding: 6px 9px 4px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.business .bubble { background: var(--bubble-business); border-start-start-radius: 0; }
.user .bubble { background: var(--bubble-user); border-start-end-radius: 0; }

.bubble p { margin: 0; white-space: pre-wrap; text-align: start; }
.bubble .b-header { font-weight: 700; margin-bottom: 2px; }
.bubble .b-footer { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.bubble .b-reply-desc { color: var(--text-muted); font-size: 13px; }

.meta {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  align-items: center;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}
.meta .sim { font-size: 10px; border: 1px solid var(--border); border-radius: 4px; padding: 0 3px; }
.ticks { letter-spacing: -3px; }

.variant-bar { display:flex; justify-content:center; gap:12px; flex-wrap:wrap; padding:12px; background:#dfe5e7; }
.variant-bar a { color:var(--text); text-decoration:none; background:#fff; border:1px solid var(--border); border-radius:8px; padding:8px 12px; }
.variant-bar a:hover { border-color:var(--accent); }
.start-chip { align-self:center; border:0; border-radius:20px; background:var(--accent); color:#fff; padding:10px 18px; margin:auto; }
.row-text { flex:1; padding:10px; }
.row input { margin:0 10px; }
.sheet-section-title { padding:10px; color:var(--text-muted); font-weight:600; }
.sheet-head { display:flex; align-items:center; justify-content:space-between; padding:12px; }
.sheet-head h2 { margin:0; font-size:18px; }
.sheet-head button { border:0; background:transparent; color:var(--accent); }
.sheet-foot { padding:12px; }
.primary-btn { width:100%; border:0; border-radius:8px; padding:10px; background:var(--accent); color:white; }
.primary-btn:disabled { opacity:.5; }
.reset-chat { margin-inline-start:auto; margin-left:-5px; border:1px solid rgba(255,255,255,.7); border-radius:7px; padding:6px 9px; background:transparent; color:#fff; font-size:12px; white-space:nowrap; }
.reset-chat:hover { background:rgba(255,255,255,.14); }
.system { margin:auto; background:var(--error-bg); color:var(--error-fg); padding:12px; border-radius:8px; }
.sheet-panel { max-height:80vh; overflow:auto; }
.stage { padding-top:16px; }
@media (max-width:600px) {
  .stage { padding:0; }
  .phone { width:100%; height:calc(100dvh - 110px); min-height:440px; border-width:0; border-radius:0; }
  .sim-banner { font-size:12px; }
  .variant-bar { gap:6px; padding:7px; }
  .variant-bar a { padding:6px 8px; font-size:12px; }
}

.list-open {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  width: calc(100% + 18px);
  margin: 6px -9px -4px;
  padding: 10px;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  border-radius: 0 0 var(--radius) var(--radius);
}
.list-open svg { width: 18px; height: 18px; }

.reply-buttons { display: flex; flex-direction: column; gap: 4px; }
.reply-btn {
  padding: 9px;
  border: 0;
  border-radius: var(--radius);
  background: var(--bubble-business);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.list-open:hover, .reply-btn:hover { background: #f5f6f6; }
body.busy .list-open, body.busy .reply-btn, body.busy .start-chip { pointer-events: none; opacity: 0.6; }

.system {
  align-self: center;
  max-width: 92%;
  background: var(--system-bg);
  color: var(--text);
  font-size: 12.5px;
  padding: 5px 10px;
  border-radius: 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.system.error { background: var(--error-bg); color: var(--error-fg); }
.system.warn { color: var(--warn-fg); }
.system .label { font-weight: 700; }

.start-chip {
  align-self: center;
  border: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 18px;
  font-weight: 600;
}

.composer {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: #f0f2f5;
}
.composer input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
.send-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:disabled { opacity: 0.6; }

/* List sheet */
.sheet { position: absolute; inset: 0; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.sheet-panel {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  max-height: 82%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px 16px 0 0;
  animation: slide-up 0.18s ease-out;
}
@keyframes slide-up { from { transform: translateY(30%); } }
@media (prefers-reduced-motion: reduce) { .sheet-panel { animation: none; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 4px 0 8px; }
.sheet-section-title {
  margin: 10px 16px 4px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.row {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  border-inline-start: 4px solid transparent;
}
.row:hover { background: #f5f6f6; }
.row input { position: absolute; opacity: 0; pointer-events: none; }
.row .row-text { flex: 1; min-width: 0; }
.row .row-title { display: block; }
.row .row-desc { display: block; font-size: 13px; color: var(--text-muted); }
.radio {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  display: grid;
  place-items: center;
}
.row:has(input:checked) { background: var(--selected-bg); border-inline-start-color: var(--accent); }
.row:has(input:checked) .radio { border-color: var(--accent); }
.row:has(input:checked) .radio::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.row:has(input:focus-visible) { outline: 2px solid var(--accent-strong); outline-offset: -2px; }

.sheet-foot { padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.primary-btn {
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.primary-btn:disabled { background: #b8c4c9; }

/* Developer panel */
.dev {
  width: 420px;
  max-width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
}
.dev h2 { margin: 0 0 10px; font-size: 17px; }
.dev h3 { margin: 18px 0 4px; font-size: 14px; }
.tag {
  font-size: 11px;
  font-weight: 600;
  background: var(--system-bg);
  border-radius: 4px;
  padding: 1px 6px;
  vertical-align: middle;
}
.status-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.status-grid dt { color: var(--text-muted); }
.status-grid dd { margin: 0; font-weight: 600; }
.ok { color: var(--accent); }
.bad { color: var(--error-fg); }

.dev-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.dev-actions button {
  border: 1px solid var(--border);
  background: #f7f8f8;
  color: var(--text);
  border-radius: 6px;
  padding: 5px 9px;
}
.hint, .muted { color: var(--text-muted); font-size: 12.5px; margin: 6px 0; }

.limits { max-height: 320px; overflow: auto; }
.limits table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.limits th, .limits td { padding: 3px 4px; border-bottom: 1px solid #eef0f1; text-align: start; vertical-align: top; overflow-wrap: anywhere; }
.limits th:first-child { width: 38%; }
.limits th:last-child { width: 22%; }
.limits td.path { font-family: ui-monospace, Menlo, monospace; font-size: 11px; text-align: left; }
.limits tr.near td.count { color: var(--warn-fg); font-weight: 700; }
.limits tr.over td.count { color: var(--error-fg); font-weight: 700; }

.log { display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow-y: auto; }
.log details { border: 1px solid #eef0f1; border-radius: 6px; padding: 4px 8px; }
.log summary { cursor: pointer; font-size: 12.5px; }
.log pre {
  margin: 6px 0 2px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f8f8;
  padding: 6px;
  border-radius: 4px;
  text-align: left;
}

@media (max-width: 860px) {
  .stage { flex-direction: column; align-items: center; padding: 0 0 16px; gap: 16px; }
  .sim-banner { padding: 6px 12px; height: 32px; align-items: center; font-size: 12.5px; }
  .sim-banner span { display: none; }
  .phone { width: 100%; border: 0; border-radius: 0; height: calc(100dvh - 32px); min-height: 0; box-shadow: none; }
  .dev { width: auto; margin: 0 16px; align-self: stretch; }
}

/* Variant switch (A = lists/buttons, B = numbered menu) */
.variant-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 12px 16px 0;
}
.variant-bar a {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bubble-business);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
}
.variant-bar a strong { color: var(--text); margin-inline-end: 4px; }
.variant-bar a.active { border-color: var(--accent); background: var(--selected-bg); color: var(--text); }
