:root {
  --bg: #f4f5f2; --panel: #ffffff; --panel-2: #f9faf8; --line: #e3e5df; --line-2: #d2d5cc;
  --text: #1c1d1a; --text-2: #5d6058; --text-3: #8b8e85;
  --accent: #128c5e; --accent-2: #0d6b48; --accent-bg: #e3f5ec; --accent-text: #0b5c3e;
  --blue-bg: #e6f0fb; --blue-text: #134f8c; --amber-bg: #fbf0dc; --amber-text: #7a4a07;
  --red-bg: #fbe9e8; --red-text: #9a2a24; --gray-bg: #eeefeb; --gray-text: #4f514c;
  --bubble-out: #d9f7e3; --bubble-in: #ffffff; --chat-bg: #efeae2;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05);
  --font: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412; --panel: #1b1d1b; --panel-2: #202320; --line: #2c302c; --line-2: #3a3f3a;
    --text: #eceee9; --text-2: #a9ada5; --text-3: #7c8079;
    --accent: #2fbf86; --accent-2: #4fd49e; --accent-bg: #133a2a; --accent-text: #8fe6bf;
    --blue-bg: #152a40; --blue-text: #9cc8f2; --amber-bg: #3a2a10; --amber-text: #f2c879;
    --red-bg: #3d1a18; --red-text: #f3a7a1; --gray-bg: #262926; --gray-text: #c3c6bf;
    --bubble-out: #1d4433; --bubble-in: #232623; --chat-bg: #171a17;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--text-2); } .small { font-size: 13px; } .tiny { font-size: 12px; color: var(--text-3); }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 10px; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand b { display: block; font-size: 15px; } .brand span { font-size: 12px; color: var(--text-3); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); cursor: pointer; border: 0; background: none; width: 100%; text-align: right; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; }
.nav-item .ico { width: 20px; text-align: center; font-size: 17px; }
.nav-item .badge { margin-inline-start: auto; }
.side .spacer { flex: 1; }
.main { overflow: auto; min-width: 0; }
.page { padding: 24px 28px 60px; max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 14px; }
.grid.metrics { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.metric .label { font-size: 13px; color: var(--text-2); }
.metric .value { font-size: 26px; font-weight: 600; margin-top: 2px; letter-spacing: -.5px; }
.metric .sub { font-size: 12px; color: var(--text-3); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--red-text); border-color: color-mix(in srgb, var(--red-text) 35%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--gray-bg); color: var(--gray-text); white-space: nowrap; }
.badge.green { background: var(--accent-bg); color: var(--accent-text); }
.badge.blue { background: var(--blue-bg); color: var(--blue-text); }
.badge.amber { background: var(--amber-bg); color: var(--amber-text); }
.badge.red { background: var(--red-bg); color: var(--red-text); }
.badge.count { background: var(--accent); color: #fff; min-width: 20px; text-align: center; padding: 1px 6px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=url], input[type=datetime-local], input[type=search], input[type=time], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); outline: none; min-height: 38px;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input[dir=ltr], .ltr { direction: ltr; text-align: left; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; top: 3px; right: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(-18px); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: right; font-weight: 500; color: var(--text-2); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty .big { font-size: 34px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-size: 13px; }
.chip.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-text); }
.bar { height: 8px; border-radius: 99px; background: var(--gray-bg); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--amber-bg); color: var(--amber-text); font-size: 14px; margin-bottom: 14px; }
.notice.info { background: var(--blue-bg); color: var(--blue-text); }
.notice.ok { background: var(--accent-bg); color: var(--accent-text); }
.notice.err { background: var(--red-bg); color: var(--red-text); }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 16px; align-items: start; }
.sticky { position: sticky; top: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }
code, .mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--gray-bg); padding: 1px 6px; border-radius: 5px; direction: ltr; unicode-bidi: embed; }

/* toast + modal */
#toasts { position: fixed; bottom: 18px; left: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.toast.err { background: var(--red-text); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; }

/* whatsapp bubble preview */
.wa-preview { background: var(--chat-bg); border-radius: 12px; padding: 16px; min-height: 120px; }
.bubble { max-width: 85%; padding: 7px 10px 5px; border-radius: 10px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; position: relative; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.out { background: var(--bubble-out); margin-inline-start: auto; border-top-left-radius: 3px; }
.bubble.in { background: var(--bubble-in); margin-inline-end: auto; border-top-right-radius: 3px; }
.bubble .meta { font-size: 11px; color: var(--text-3); text-align: left; margin-top: 2px; display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.bubble .tick.read { color: #34b7f1; } .bubble .tick.failed { color: var(--red-text); }
.bubble .btns { border-top: 1px solid var(--line); margin: 6px -10px -5px; display: flex; flex-direction: column; }
.bubble .btns div { text-align: center; color: var(--accent); padding: 6px; font-size: 13px; border-top: 1px solid var(--line); }
.bubble .btns div:first-child { border-top: 0; }
.bubble img.media, .bubble video.media { max-width: 260px; width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.bubble .tag { font-size: 11px; color: var(--text-3); margin-bottom: 2px; }
.bubble .err { font-size: 12px; color: var(--red-text); margin-top: 3px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.convs { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.convs-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.convs-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.conv:hover { background: var(--panel-2); } .conv.active { background: var(--accent-bg); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-bg); color: var(--accent-text); display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.conv .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 12px; color: var(--text-3); flex: none; }
.conv .prev { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .name, .conv.unread .prev { font-weight: 600; color: var(--text); }
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.thread-head .info { flex: 1; min-width: 0; }
.thread-msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; background: var(--panel); color: var(--text-2); font-size: 12px; padding: 3px 12px; border-radius: 8px; margin: 8px 0; box-shadow: var(--shadow); }
.composer { padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.composer .row { flex-wrap: nowrap; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; border-radius: 20px; padding: 10px 16px; }
.composer .send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; font-size: 18px; flex: none; }
.window-note { font-size: 13px; color: var(--amber-text); background: var(--amber-bg); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.back-btn { display: none; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }

/* mobile */
.bottom-nav { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side { display: none; }
  .bottom-nav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav .nav-item { flex-direction: column; gap: 0; font-size: 11px; padding: 6px 4px; text-align: center; position: relative; justify-content: center; }
  .bottom-nav .nav-item .ico { font-size: 19px; }
  .bottom-nav .nav-item .badge { position: absolute; top: 2px; left: 50%; margin-left: 6px; }
  .page { padding: 16px 16px 40px; }
  .split { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .inbox { grid-template-columns: 1fr; height: 100%; }
  .inbox.has-thread .convs { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  .back-btn { display: inline-flex; }
  .thread-msgs { padding: 12px 10px; }
  .hide-m { display: none; }
}
