:root {
  --bg: #0b141a;
  --sidebar: #111b21;
  --sidebar-hover: #202c33;
  --sidebar-active: #2a3942;
  --panel: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008f72;
  --blue: #53bdeb;
  --customer: #202c33;
  --agent: #005c4b;
  --error: #f15c6d;
  --wa: #25d366;
  --badge: #25d366;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#layout { display: flex; height: 100%; }

/* ---------- Sidebar (WhatsApp-like chat list) ---------- */
#sidebar {
  width: 340px;
  min-width: 280px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#sideHeader {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
}
#sideHeader h1 { font-size: 16px; font-weight: 600; }
#sideHeader .side-btns { display: flex; gap: 6px; }
.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--sidebar-hover); color: var(--text); }
#waMini {
  padding: 5px 14px;
  font-size: 11.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
#waMini .dot.ok { color: var(--wa); }
#waMini .dot.bad { color: var(--error); }
#waMini .dot.wait { color: #e2c25a; }

#searchWrap { padding: 8px 12px; background: var(--sidebar); }
#searchInput {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
}
#searchInput:focus { outline: none; border-color: var(--accent); }

#chatList { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(134,150,160,0.08);
}
.chat-item:hover { background: var(--sidebar-hover); }
.chat-item.active { background: var(--sidebar-active); }
.avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #0b141a;
}
.chat-item .info { flex: 1; min-width: 0; }
.chat-item .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-item .name {
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.chat-item.unread .time { color: var(--badge); }
.chat-item .row2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 3px; }
.chat-item .snippet {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item.unread .snippet { color: var(--text); }
.chat-item .badge {
  background: var(--badge);
  color: #0b141a;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}
.chat-item .wa-mark { font-size: 10px; color: var(--wa); margin-right: 3px; }
#emptyList { padding: 30px 20px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* ---------- Chat pane ---------- */
#chatPane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chatHeader {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#backBtn { display: none; }
#chatHeader .avatar { width: 38px; height: 38px; min-width: 38px; font-size: 15px; }
#chatTitleWrap { flex: 1; min-width: 0; }
#chatName { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chatSub { font-size: 11.5px; color: var(--muted); }

#noteBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
#noteBar label { color: var(--muted); white-space: nowrap; }
#noteInput {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 5px 10px;
  font-size: 12.5px;
  font-family: inherit;
}
#noteInput:focus { outline: none; border-color: var(--accent); }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 6%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.bubble {
  max-width: 72%;
  padding: 9px 12px;
  border-radius: 10px;
  line-height: 1.45;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.bubble .meta { font-size: 10.5px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 10px; }
.bubble .tr {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed rgba(134,150,160,0.35);
  font-size: 12.5px;
  color: var(--muted);
}
.customer { align-self: flex-start; background: var(--customer); border-top-left-radius: 3px; }
.agent { align-self: flex-end; background: var(--agent); border-top-right-radius: 3px; }
.bubble-actions { margin-top: 7px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bubble-actions button {
  font-size: 11.5px;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
.bubble-actions button:hover { background: rgba(255,255,255,0.18); }
.bubble-actions .wa-send { background: var(--wa); color: #0b141a; font-weight: 600; }
.bubble-actions .wa-send:hover { opacity: 0.9; }
.bubble-actions .del { color: var(--error); background: none; padding: 4px 6px; }
.sent-label { font-size: 11px; color: var(--wa); }
#emptyChat {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.8;
}

/* ---------- Suggestions + composer ---------- */
#suggestBar {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 10px 16px;
  background: #182229;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}
#suggestBar.open { display: flex; }
.suggest-row { display: flex; align-items: center; gap: 8px; }
.suggest-row .text { flex: 1; }
#suggestTitle { color: var(--muted); font-size: 11.5px; }

#composer {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.row { display: flex; gap: 8px; align-items: stretch; }
.field { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--muted); }
.field.incoming label { color: var(--blue); }
.field.outgoing label { color: var(--wa); }
textarea {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  height: 50px;
}
textarea:focus { outline: none; border-color: var(--accent); }
.field.incoming textarea:focus { border-color: var(--blue); }
.field.outgoing textarea:focus { border-color: var(--wa); }
.btn {
  border: 1px solid var(--border);
  background: var(--sidebar);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.primary { background: var(--accent); color: #06120e; border: none; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn.blue { background: var(--blue); color: #06222e; border: none; font-weight: 600; }
.btn.blue:hover:not(:disabled) { opacity: 0.9; }
.btn-col { display: flex; flex-direction: column; gap: 5px; align-self: end; }
.btn-col .btn { height: 23px; min-width: 148px; padding: 1px 10px; font-size: 12px; }
select {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  align-self: end;
  height: 32px;
}
#templateChips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#templateChips .chip {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  padding: 3px 12px;
  font-size: 12px;
  cursor: pointer;
}
#templateChips .chip:hover { border-color: var(--blue); color: var(--text); }
#quoteRow {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
}
#quoteRow .quote-label { color: var(--muted); }
#quoteRow input, #quoteRow select {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  height: 28px;
}
#quoteRow input { width: 110px; }
#quoteRow input:focus, #quoteRow select:focus { outline: none; border-color: var(--accent); }
#quoteRow .btn { height: 28px; padding: 2px 10px; font-size: 12px; }
#quoteResult { color: var(--accent); font-size: 12px; }

.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.price-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
  color: var(--muted);
}
.price-grid input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 9px;
  font-size: 13px;
  font-family: inherit;
}
.price-grid input:focus { outline: none; border-color: var(--accent); }

.summary-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.summary-stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.summary-stat .num { font-size: 20px; font-weight: 700; color: var(--accent); }
.summary-stat .label { font-size: 11.5px; color: var(--muted); }
.summary-wait {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.summary-wait:hover { border-color: var(--accent); }
.summary-wait .hours { color: var(--error); flex-shrink: 0; }
.summary-wait .who { font-weight: 600; }
.summary-wait .what { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#orderChip {
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1px 8px;
  margin-left: 6px;
}
.bubble img.media-thumb {
  margin-top: 8px;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
}

.hidden { display: none !important; }
#status { font-size: 12px; color: var(--muted); min-height: 15px; }
#status.error { color: var(--error); }

/* ---------- Panels ---------- */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(460px, 94vw);
  background: var(--sidebar);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
  box-shadow: -8px 0 30px rgba(0,0,0,0.5);
  overflow-y: auto;
}
.panel.open { display: flex; }
.panel h2 { font-size: 15px; }
.panel h3 { font-size: 13px; margin-top: 6px; }
.panel p { font-size: 12px; color: var(--muted); line-height: 1.5; }
.panel textarea { height: 140px; font-size: 13px; line-height: 1.55; }
.panel-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.saved-note { color: var(--accent); font-size: 12px; margin-right: auto; }
.tpl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
}
.tpl-item .name { font-weight: 600; }
.tpl-item .preview { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-item .del { border: none; background: none; color: var(--error); cursor: pointer; font-size: 14px; }
.tpl-add { display: flex; flex-direction: column; gap: 6px; }
.tpl-add input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}
.tpl-add input:focus { outline: none; border-color: var(--accent); }
.tpl-add textarea { height: 70px; }
#waPanel img { align-self: center; background: #fff; padding: 10px; border-radius: 10px; }
.wa-status { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.wa-status .dot { font-size: 11px; }
.wa-status.ok .dot { color: var(--wa); }
.wa-status.bad .dot { color: var(--error); }
.wa-status.wait .dot { color: #e2c25a; }
.toggle-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12.5px;
  line-height: 1.5;
  cursor: pointer;
}
.toggle-row input { margin-top: 3px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  #sidebar { width: 100%; min-width: 0; }
  #chatPane { display: none; }
  body.chat-open #sidebar { display: none; }
  body.chat-open #chatPane { display: flex; }
  #backBtn { display: block; }
  .row { flex-direction: column; }
  .btn-col { width: 100%; }
  .btn-col .btn { height: 40px; width: 100%; }
  select { width: 100%; }
  .bubble { max-width: 90%; }
  #chat { padding: 12px 4%; }
}
