:root {
  --bg: #f4f6f5; --panel: #fff; --ink: #17211d; --muted: #6b7772; --line: #e2e7e4;
  --brand: #128c7e; --brand-2: #0b6b60; --brand-soft: #e3f4f0;
  --ok: #1a7f4b; --ok-bg: #e2f5ea; --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #b42318; --bad-bg: #fde8e6;
  --bubble-out: #d9fdd3; --wa-bg: #efeae2; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513; --panel: #17201d; --ink: #e5ece9; --muted: #92a09a; --line: #26322e;
    --brand: #25b39f; --brand-2: #1e9886; --brand-soft: #173a33;
    --ok: #6fd69c; --ok-bg: #173526; --warn: #f0c060; --warn-bg: #3a2e12; --bad: #ff8a80; --bad-bg: #3d1a17;
    --bubble-out: #144d37; --wa-bg: #0c1311; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); display: flex; min-height: 100vh; }
a { color: var(--brand); text-decoration: none; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
code { background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
code.copy { cursor: pointer; } code.copy.copied { outline: 2px solid var(--brand); }
code.big { display: inline-block; font-size: 1.05em; padding: 6px 10px; margin-top: 6px; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 18px 0 8px; }

/* Layout */
.sidebar { width: 220px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 18px 18px 14px; display: flex; gap: 8px; align-items: center; }
.brand.big { font-size: 20px; padding: 0 0 12px; justify-content: center; }
.logo { background: var(--brand); color: #fff; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.sidebar nav { flex: 1; padding: 4px 10px; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.ico { width: 20px; text-align: center; opacity: .8; }
.user { padding: 14px 18px; border-top: 1px solid var(--line); font-size: 13px; }
main { flex: 1; padding: 20px 28px 40px; min-width: 0; }
.topbar { margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; overflow-x: auto; }
.card.narrow { max-width: 760px; }
.callout { border-left: 4px solid var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); }
.hidden { display: none !important; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.grow { flex: 1; }
.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; } .stat .l { color: var(--muted); font-size: 12px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.dim td { opacity: .55; }
.actions { white-space: nowrap; } .actions form { display: inline; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .tiny { font-size: 11px; } .right { float: right; }
.bad-text { color: var(--bad); } .star { color: #e3a008; }
.pad { padding: 12px; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 10px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
label > input:not([type=checkbox]):not([type=file]), label > select, label > textarea, textarea { display: block; width: 100%; margin-top: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid.one { grid-template-columns: 1fr; }
.span2 { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row { display: grid; grid-template-columns: 140px minmax(0,1fr) minmax(0,1.4fr) minmax(0,1fr); gap: 6px; margin-bottom: 6px; }
.btn-row > * { min-width: 0; width: 100%; }
#std-fields > input { width: 100%; }
details summary { cursor: pointer; color: var(--brand); margin: 4px 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 4px; font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); } .btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btn.full { width: 100%; justify-content: center; padding: 10px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Badges, alerts */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.count { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; margin-left: auto; font-weight: 600; }
.tag { display: inline-block; font-size: 12px; background: var(--brand-soft); color: var(--brand); border-radius: 5px; padding: 0 6px; margin: 0 4px 2px 0; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid transparent; }
.alert.success { background: var(--ok-bg); color: var(--ok); } .alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warning { background: var(--warn-bg); color: var(--warn); } .alert.info { background: var(--brand-soft); color: var(--ink); }
pre.json, pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; font-size: 12px; max-height: 420px; white-space: pre; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 12px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.progress { height: 6px; background: var(--bg); border-radius: 9px; overflow: hidden; width: 140px; } .progress span { display: block; height: 100%; background: var(--brand); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; } .tabs a { padding: 7px 16px; border-radius: 8px; color: var(--ink); } .tabs a.active { background: var(--brand); color: #fff; }
.pager { display: flex; gap: 4px; margin-top: 12px; flex-wrap: wrap; } .pager a { padding: 2px 9px; border: 1px solid var(--line); border-radius: 6px; } .pager a.active { background: var(--brand); color: #fff; }
.row-link { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--ink); } .row-link:last-child { border: 0; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }

/* WhatsApp bubbles */
.bubble { background: var(--bubble-out); border-radius: 8px; padding: 8px 10px; max-width: 420px; margin: 8px 0; white-space: normal; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.bubble:empty { display: none; }
.bubble .footer { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bubble .wa-btn { border-top: 1px solid rgba(0,0,0,.08); text-align: center; color: #0a84c7; padding: 6px 0 2px; margin-top: 6px; font-weight: 500; }
.media-ph { background: rgba(0,0,0,.08); border-radius: 6px; height: 110px; display: grid; place-items: center; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; font-size: 12px; }
.wa-screen { background: var(--wa-bg); border-radius: 12px; padding: 16px; min-height: 240px; }
.phone-preview { position: sticky; top: 20px; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 16px; height: calc(100vh - 110px); }
.conv-list { padding: 10px; overflow-y: auto; margin: 0; }
.conv-list .filters { margin-bottom: 8px; } .conv-list select { width: 100%; }
.conv { display: block; padding: 10px; border-radius: 8px; color: var(--ink); border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--bg); } .conv.active { background: var(--brand-soft); }
.conv .row { display: flex; gap: 6px; align-items: center; } .conv .row .right { margin-left: auto; }
.thread { display: flex; flex-direction: column; padding: 0; margin: 0; overflow: hidden; }
.thread-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; background: var(--wa-bg); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 7px 10px; border-radius: 8px; background: var(--panel); align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.06); word-wrap: break-word; }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .meta .badge { font-size: 10px; padding: 0 6px; }
.reply { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); margin: 0; align-items: flex-end; }
.reply textarea { flex: 1; margin: 0; resize: vertical; }
.reply.closed { align-items: center; justify-content: space-between; color: var(--muted); }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }

/* Auth */
body.auth { align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; overflow-x: auto; padding: 0 8px 8px; } .sidebar nav a { white-space: nowrap; }
  .user { display: none; }
  main { padding: 16px; }
  .grid2, .grid2.wide-left, .form-grid, .inbox { grid-template-columns: 1fr; }
  .inbox { height: auto; } .messages { max-height: 60vh; }
  .btn-row { grid-template-columns: 1fr 1fr; }
}
