/* K6 WhatsApp Admin — no inline styles anywhere (strict CSP) */
:root {
  --ink: #120f26;
  --ink-2: #1c1838;
  --ink-3: #2a2450;
  --gold: #d4a95f;
  --gold-2: #f0d29a;
  --bg: #f5f3fa;
  --card: #ffffff;
  --line: #e7e3f0;
  --text: #1f1a33;
  --muted: #6e6886;
  --wa: #25d366;
  --wa-dark: #128c4b;
  --danger: #d64545;
  --warn: #d89a1e;
  --info: #4b6bd6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 14, 50, .06), 0 8px 24px -12px rgba(20, 14, 50, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.55 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
p { margin: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  padding: .6em 1.1em; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-weight: 600; font-size: .92rem; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .input:focus-visible, .switch input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--ink-3); }
.btn--gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: var(--ink); }
.btn--wa { background: var(--wa); color: #06210f; }
.btn--wa:hover:not(:disabled) { background: #2ee874; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: #efecf6; }
.btn--danger { background: transparent; border-color: rgba(214, 69, 69, .35); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: rgba(214, 69, 69, .08); }
.btn--sm { padding: .4em .75em; font-size: .82rem; border-radius: 8px; }
.btn--block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; }
.icon { width: 18px; height: 18px; flex: none; }

.field { display: grid; gap: .35rem; }
.field + .field { margin-top: 1rem; }
.field label, .label { font-weight: 600; font-size: .85rem; }
.hint { color: var(--muted); font-size: .8rem; }
.input {
  width: 100%; padding: .65em .8em; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212, 169, 95, .2); outline: none; }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.55; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row + .field, .field + .row { margin-top: 1rem; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  position: relative; width: 40px; height: 22px; border-radius: 999px; background: #d9d4e6; transition: background .2s; flex: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s;
}
.switch input:checked + span { background: var(--wa); }
.switch input:checked + span::after { transform: translateX(18px); }

/* ---------- login ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(900px 600px at 80% -10%, rgba(91, 70, 150, .55), transparent 60%), radial-gradient(700px 500px at 0% 100%, rgba(212, 169, 95, .18), transparent 60%), var(--ink);
}
.login__card { width: 100%; max-width: 380px; background: var(--card); border-radius: 20px; padding: 2rem; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .6); }
.login__brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.login__brand img { width: 48px; height: 48px; border-radius: 50%; }
.login__brand h1 { font-size: 1.15rem; }
.login__brand p { color: var(--muted); font-size: .85rem; }
.login .btn { margin-top: 1.25rem; padding: .8em; }
.pw { position: relative; }
.pw .input { padding-right: 3rem; }
.pw button { position: absolute; right: .4rem; top: 50%; translate: 0 -50%; border: 0; background: none; color: var(--muted); cursor: pointer; padding: .3rem .5rem; font-size: .8rem; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar {
  background: var(--ink); color: #d9d4ee; padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .65rem; padding: 0 .4rem; text-decoration: none; }
.brand img { width: 38px; height: 38px; border-radius: 50%; }
.brand b { display: block; color: var(--gold-2); font-size: .95rem; letter-spacing: .04em; }
.brand small { color: #8e88ab; font-size: .75rem; }
.nav { display: grid; gap: .2rem; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .65rem .8rem; border-radius: 10px; text-decoration: none;
  color: #bdb6d8; font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.is-active { background: linear-gradient(135deg, rgba(240, 210, 154, .18), rgba(212, 169, 95, .08)); color: var(--gold-2); box-shadow: inset 2px 0 0 var(--gold); }
.sidebar__foot { margin-top: auto; display: grid; gap: .5rem; font-size: .82rem; color: #8e88ab; padding: 0 .4rem; }
.sidebar__foot .btn { color: #d9d4ee; border-color: rgba(255, 255, 255, .15); }
.sidebar__foot .btn:hover { background: rgba(255, 255, 255, .06); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 1rem 2rem; background: rgba(245, 243, 250, .85);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.25rem; margin-right: auto; }
.menu-btn { display: none; border: 0; background: none; cursor: pointer; padding: .3rem; }
.content { padding: 1.75rem 2rem 3rem; display: grid; gap: 1.25rem; align-content: start; max-width: 1200px; width: 100%; }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: .45rem; padding: .35em .8em; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #ece9f3; color: var(--muted); text-decoration: none; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--connected { background: rgba(37, 211, 102, .14); color: var(--wa-dark); }
.pill--qr, .pill--connecting { background: rgba(216, 154, 30, .14); color: #a06d07; }
.pill--qr::before, .pill--connecting::before { animation: blink 1s infinite; }
.pill--disconnected { background: rgba(214, 69, 69, .1); color: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.4rem; }
.card__head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card__head h2 { font-size: 1.02rem; margin-right: auto; }
.card__head p { width: 100%; color: var(--muted); font-size: .85rem; margin-top: -.6rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.stat { padding: 1.1rem 1.25rem; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat b { display: block; font-size: 1.9rem; line-height: 1.2; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .78rem; }
.stat--gold { background: linear-gradient(135deg, var(--ink-2), var(--ink-3)); color: #fff; border-color: transparent; }
.stat--gold span, .stat--gold small { color: #bdb6d8; }
.stat--gold b { color: var(--gold-2); }

.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .85rem 1rem; border-radius: 12px; font-size: .88rem; }
.alert--warn { background: rgba(216, 154, 30, .12); color: #7a5205; }
.alert--danger { background: rgba(214, 69, 69, .1); color: #9b2c2c; }
.alert--info { background: rgba(75, 107, 214, .08); color: #2c4296; }
.alert--ok { background: rgba(37, 211, 102, .12); color: #0f6b39; }
.alert .btn { margin-left: auto; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty b { display: block; color: var(--text); font-size: 1rem; margin-bottom: .3rem; }

/* list items */
.list { display: grid; }
.list__item { display: flex; gap: .8rem; align-items: center; padding: .7rem 0; border-top: 1px solid var(--line); }
.list__item:first-child { border-top: 0; padding-top: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: var(--ink); background: linear-gradient(135deg, var(--gold-2), var(--gold)); flex: none; }
.list__body { min-width: 0; flex: 1; }
.list__body b { font-weight: 600; }
.list__body p { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { color: var(--muted); font-size: .78rem; white-space: nowrap; }

/* chart */
.chart { width: 100%; height: 190px; }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.chart .bar-in { fill: #c9c2e3; }
.chart .bar-auto { fill: var(--gold); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.legend .l-in { background: #c9c2e3; }
.legend .l-auto { background: var(--gold); }

/* ---------- WhatsApp page ---------- */
.link { display: grid; grid-template-columns: 340px 1fr; gap: 2rem; align-items: center; }
.qr-box {
  aspect-ratio: 1; border-radius: 16px; border: 1px dashed var(--line); background: #faf9fd;
  display: grid; place-items: center; text-align: center; padding: 1rem; position: relative; overflow: hidden;
}
.qr-box img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.qr-box .logo-badge { position: absolute; width: 56px; height: 56px; border-radius: 50%; border: 4px solid #fff; left: 50%; top: 50%; translate: -50% -50%; }
.pair-code { font: 700 2rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; color: var(--ink); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: .8rem; }
.steps li { counter-increment: s; display: flex; gap: .75rem; align-items: flex-start; }
.steps li::before { content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--gold-2); font-weight: 700; font-size: .8rem; }
.connected { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.connected__icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(37, 211, 102, .15); color: var(--wa-dark); }
.connected__icon .icon { width: 30px; height: 30px; }
.connected h3 { font-size: 1.35rem; }
.connected p { color: var(--muted); }
.connected__actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.or { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1.25rem 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.inline-form { display: flex; gap: .5rem; }
.inline-form .input { flex: 1; }

/* ---------- rules ---------- */
.toolbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 180px; }
.rules { display: grid; gap: .75rem; }
.rule {
  display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: start;
  padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; transition: border-color .15s, opacity .15s;
}
.rule:hover { border-color: #d2cbe4; }
.rule.is-off { opacity: .55; }
.rule__title { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.rule__title b { font-size: .98rem; }
.tag { display: inline-block; padding: .12em .55em; border-radius: 6px; font-size: .72rem; font-weight: 600; background: #efecf6; color: var(--muted); }
.tag--type { background: rgba(75, 107, 214, .1); color: var(--info); }
.tag--prio { background: rgba(212, 169, 95, .18); color: #8a6420; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.chip { padding: .2em .65em; border-radius: 999px; background: var(--ink); color: var(--gold-2); font-size: .78rem; }
.rule__reply { color: var(--muted); font-size: .85rem; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rule__meta { display: flex; gap: 1rem; color: var(--muted); font-size: .78rem; margin-top: .45rem; flex-wrap: wrap; }
.rule__actions { display: flex; gap: .35rem; }
.tester { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.test-result { margin-top: .9rem; }

/* WhatsApp-style preview */
.phone { background: #e9e1d8; border-radius: 14px; padding: 1rem; display: grid; gap: .5rem; min-height: 120px; align-content: start; }
.bubble { max-width: 85%; padding: .5rem .7rem .35rem; border-radius: 10px; font-size: .88rem; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0, 0, 0, .1); }
.bubble small { display: block; text-align: right; font-size: .68rem; color: #7b8a83; margin-top: .15rem; }
.bubble--in { background: #fff; justify-self: start; border-top-left-radius: 2px; }
.bubble--out { background: #d9fdd3; justify-self: end; border-top-right-radius: 2px; }
.placeholders { display: flex; gap: .35rem; flex-wrap: wrap; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.4rem; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: .7rem 1rem; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; border-top: 0; background: #faf9fd; }
td.msg { max-width: 420px; white-space: pre-wrap; word-break: break-word; }
.dir { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; font-size: .78rem; }
.dir--in { color: var(--info); }
.dir--out { color: var(--wa-dark); }
.kind { font-size: .72rem; }
.err { color: var(--danger); font-size: .78rem; display: block; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; color: var(--muted); font-size: .85rem; }
.pager div { display: flex; gap: .4rem; }

/* ---------- modal, toast, spinner ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; background: rgba(18, 15, 38, .55); backdrop-filter: blur(3px); animation: fade .15s; }
.modal__card { width: 100%; max-width: 760px; max-height: calc(100vh - 2rem); overflow: auto; background: #fff; border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5); animation: pop .2s; }
.modal__card--sm { max-width: 420px; }
.modal__head { display: flex; align-items: center; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal__head h2 { font-size: 1.05rem; margin-right: auto; }
.modal__body { padding: 1.4rem; }
.modal__foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.4rem; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }
.modal__split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.5rem; }
.x { border: 0; background: none; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .4rem; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

.toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 200; display: grid; gap: .5rem; }
.toast { padding: .75rem 1rem; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow); font-size: .88rem; max-width: 360px; animation: pop .2s; }
.toast--error { background: var(--danger); }
.toast--ok { background: var(--wa-dark); }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid rgba(0, 0, 0, .12); border-top-color: currentColor; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: grid; place-items: center; gap: .75rem; color: var(--muted); }
.muted { color: var(--muted); }
.mt { margin-top: 1rem; }
.right { text-align: right; }
.counter { font-size: .78rem; color: var(--muted); text-align: right; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .25s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(18, 15, 38, .5); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: .8rem 1rem; }
  .content { padding: 1.1rem 1rem 3rem; }
  .grid-2, .link, .modal__split { grid-template-columns: 1fr; }
  .link { gap: 1.25rem; }
  .qr-box { max-width: 320px; width: 100%; margin: 0 auto; }
  .rule { grid-template-columns: auto 1fr; }
  .rule__actions { grid-column: 1 / -1; justify-content: flex-end; }
  .connected__actions { margin-left: 0; width: 100%; }
  .table-wrap { margin: 0 -1.4rem; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat b { font-size: 1.5rem; }
  .row { grid-template-columns: 1fr; }
  .inline-form, .tester { grid-template-columns: 1fr; display: grid; }
  .topbar h1 { font-size: 1.05rem; }
  .card { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; }
  .modal { padding: 0; align-items: end; }
  .modal__card { max-height: 92vh; border-radius: 18px 18px 0 0; }
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.row { align-items: start; }
#typeHelp { margin-top: .4rem; }
.card__head .input.grow { width: auto; }
.card__head .toolbar { width: 100%; }

@media (min-width: 901px) { .layout { background: linear-gradient(to right, var(--ink) 240px, transparent 240px); } }
.row > .field + .field { margin-top: 0; }
.toolbar .input { width: auto; }
.toolbar .input.grow { flex: 1; }
.card__head .toolbar, .card__head .toolbar[class] { width: 100%; }

/* phone fixes: never let a grid child push the page wider than the screen */
.content > *, .grid-2 > *, .grid-3 > *, .stats > * { min-width: 0; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .link, .modal__split { grid-template-columns: minmax(0, 1fr); }
  .alert { flex-wrap: wrap; }
  .alert .btn { margin-left: 0; }
}
/* message log becomes stacked cards on phones */
@media (max-width: 640px) {
  .table-wrap { margin: 0; overflow: visible; }
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { display: grid; grid-template-columns: auto 1fr auto; gap: .25rem .6rem; padding: .85rem 0; border-top: 1px solid var(--line); }
  tbody tr:first-child { border-top: 0; }
  td { padding: 0; border: 0; }
  td:nth-child(1) { grid-column: 3; grid-row: 1; text-align: right; }
  td:nth-child(2) { grid-column: 1; grid-row: 1; }
  td:nth-child(3) { grid-column: 2; grid-row: 1; }
  td:nth-child(3) br { display: none; }
  td:nth-child(3) .muted { margin-left: .35rem; font-size: .8rem; }
  td.msg { grid-column: 1 / -1; max-width: none; }
  td:nth-child(5) { grid-column: 1 / -1; }
  td:nth-child(5) br { display: none; }
  td:nth-child(5) .hint { margin-left: .4rem; }
  td[colspan] { grid-column: 1 / -1; }
  .pager { flex-wrap: wrap; }
}
.list > *, .card { min-width: 0; }
