:root {
  --brand: #2f5d4f;
  --brand-soft: #e8f0ec;
  --bg: #f6f7f6;
  --panel: #ffffff;
  --line: #e5e7e4;
  --text: #1c211e;
  --muted: #6d746f;
  --accent: #c8963e;
  --danger: #dc2626;
  --radius: 10px;
  --sidebar: 66px;
  --list: 330px;
  --aside: 300px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }

.hidden { display: none !important; }

#login {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #2f5d4f 0%, #1d3b32 100%);
}
#login form {
  background: #fff;
  padding: 34px 32px;
  border-radius: 14px;
  width: 340px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
}
#login h1 { margin: 0 0 4px; font-size: 20px; }
#login p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
#login label { display: block; font-size: 12.5px; font-weight: 600; margin: 12px 0 5px; }
#login input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; outline: none;
}
#login input:focus { border-color: var(--brand); }
#login button {
  width: 100%; margin-top: 20px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 600;
}
#login .error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

#app { height: 100%; display: grid; grid-template-columns: var(--sidebar) var(--list) 1fr; }

.rail {
  background: var(--brand); color: #fff; display: flex; flex-direction: column;
  align-items: center; padding: 14px 0; gap: 6px;
}
.rail .logo {
  width: 36px; height: 36px; border-radius: 9px; background: rgba(255,255,255,.16);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-bottom: 10px;
}
.rail button {
  width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent;
  color: rgba(255,255,255,.72); display: grid; place-items: center;
}
.rail button:hover { background: rgba(255,255,255,.12); color: #fff; }
.rail button.active { background: rgba(255,255,255,.2); color: #fff; }
.rail button svg { width: 20px; height: 20px; }
.rail .spacer { flex: 1; }
.rail .me {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; font-weight: 600; font-size: 12px; cursor: pointer;
}

.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0 0 10px; font-size: 16px; }
.search { position: relative; }
.search input {
  width: 100%; padding: 8px 10px 8px 30px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); outline: none;
}
.search input:focus { border-color: var(--brand); background: #fff; }
.search svg { position: absolute; left: 9px; top: 9px; width: 15px; height: 15px; color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 20px;
  font-size: 12.5px; color: var(--muted); font-weight: 500;
}
.tabs button:hover { background: var(--bg); }
.tabs button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tabs .count { font-size: 11px; opacity: .8; margin-left: 3px; }

.conversations { flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; position: relative;
}
.conv:hover { background: #fafbfa; }
.conv.active { background: var(--brand-soft); }
.conv .avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto; display: grid;
  place-items: center; color: #fff; font-weight: 600; font-size: 13px;
}
.conv .body { min-width: 0; flex: 1; }
.conv .row1 { display: flex; align-items: baseline; gap: 6px; }
.conv .name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .when { margin-left: auto; font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.conv .snippet {
  font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 2px;
}
.conv .meta { display: flex; align-items: center; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.chip {
  font-size: 10.5px; padding: 1px 7px; border-radius: 10px; background: var(--bg);
  color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.chip.channel-whatsapp { background: #e7f8ec; color: #157a3a; border-color: #c9ecd5; }
.chip.channel-instagram { background: #fdeaf4; color: #b2295f; border-color: #f7cfe3; }
.chip.channel-web { background: #e9f1fb; color: #1d5ba6; border-color: #cfe0f5; }
.chip.label { color: #fff; border: 0; }
.conv .unread {
  position: absolute; right: 12px; bottom: 12px; min-width: 18px; height: 18px;
  border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px;
  font-weight: 600; display: grid; place-items: center; padding: 0 5px;
}
.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.pane { display: grid; grid-template-columns: 1fr var(--aside); min-width: 0; }
.thread { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.thread-head {
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 11px 16px;
  display: flex; align-items: center; gap: 12px; flex: 0 0 auto;
}
.thread-head .who { min-width: 0; }
.thread-head .who h3 { margin: 0; font-size: 15px; }
.thread-head .who p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.thread-head .actions { margin-left: auto; display: flex; gap: 7px; align-items: center; }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 11px;
  font-size: 12.5px; font-weight: 500;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #26493e; }
.btn.warn { color: var(--danger); }
select.btn { padding-right: 24px; }

.messages { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 3px; }
.day { text-align: center; font-size: 11.5px; color: var(--muted); margin: 14px 0 10px; }
.bubble-row { display: flex; flex-direction: column; margin-bottom: 9px; }
.bubble-row.out { align-items: flex-end; }
.bubble {
  max-width: 68%; padding: 9px 13px; border-radius: 13px; white-space: pre-wrap;
  word-wrap: break-word; font-size: 14px; background: #fff; border: 1px solid var(--line);
}
.bubble-row.out .bubble { background: var(--brand); color: #fff; border-color: var(--brand); }
.bubble-row.bot .bubble { background: #f2f0ff; border-color: #ddd8f7; color: #2a2550; }
.bubble-row.note .bubble { background: #fff7e0; border-color: #f0e0b0; color: #6b5208; }
.bubble-row .stamp { font-size: 11px; color: var(--muted); margin-top: 3px; padding: 0 3px; }
.bubble-row .stamp .failed { color: var(--danger); font-weight: 600; }
.system { text-align: center; font-size: 11.5px; color: var(--muted); margin: 8px 0; }

.composer { background: var(--panel); border-top: 1px solid var(--line); flex: 0 0 auto; }
.composer .modes { display: flex; gap: 2px; padding: 8px 12px 0; }
.composer .modes button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 7px 7px 0 0;
  font-size: 12.5px; color: var(--muted); font-weight: 500;
}
.composer .modes button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.composer.note .modes button.active { background: #fff7e0; color: #7a5c09; }
.composer .box { padding: 8px 12px 12px; }
.composer textarea {
  width: 100%; min-height: 62px; max-height: 190px; resize: none; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; outline: none; background: var(--bg);
}
.composer.note textarea { background: #fff7e0; border-color: #f0e0b0; }
.composer textarea:focus { border-color: var(--brand); }
.composer .foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.composer .hint { font-size: 11.5px; color: var(--muted); }
.composer .foot .right { margin-left: auto; display: flex; gap: 8px; }

.aside { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.aside section { padding: 15px 16px; border-bottom: 1px solid var(--line); }
.aside h4 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.aside .big-avatar {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 19px; margin-bottom: 9px;
}
.aside .field { margin-bottom: 9px; }
.aside .field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.aside .field input, .aside .field textarea {
  width: 100%; border: 1px solid transparent; background: var(--bg); border-radius: 7px;
  padding: 6px 9px; outline: none;
}
.aside .field input:focus, .aside .field textarea:focus { border-color: var(--brand); background: #fff; }
.aside .labels { display: flex; flex-wrap: wrap; gap: 5px; }
.aside .labels .chip.label { cursor: pointer; }
.aside .add-label {
  border: 1px dashed var(--line); background: none; border-radius: 10px; font-size: 11px;
  padding: 1px 8px; color: var(--muted);
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1c211e; color: #fff; padding: 9px 17px; border-radius: 8px;
  font-size: 13px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: .95; }

@media (max-width: 1100px) { .pane { grid-template-columns: 1fr; } .aside { display: none; } }
