/* WuzAPI dashboard — no external dependencies. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2430;
  --muted: #5f6b7a;
  --primary: #0f766e;
  --primary-hover: #0b5f58;
  --primary-text: #ffffff;
  --danger: #c62828;
  --danger-hover: #a32020;
  --ok: #1b7f3b;
  --warn: #a15c00;
  --info: #1d5fb4;
  --ok-bg: #e4f5ea;
  --warn-bg: #fdf0d8;
  --info-bg: #e3eefb;
  --off-bg: #eceff3;
  --danger-bg: #fbe4e4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --focus: 0 0 0 3px rgba(15, 118, 110, 0.35);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0f1419;
  --surface: #18202a;
  --surface-2: #1f2937;
  --border: #2b3645;
  --text: #e6ebf2;
  --muted: #9aa7b8;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-text: #062a26;
  --danger: #ff6b6b;
  --danger-hover: #ff8f8f;
  --ok: #4ade80;
  --warn: #fbbf24;
  --info: #7cb7ff;
  --ok-bg: #12301e;
  --warn-bg: #3a2c0e;
  --info-bg: #14283f;
  --off-bg: #232d3a;
  --danger-bg: #3d1a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --focus: 0 0 0 3px rgba(45, 212, 191, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--primary); }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 10px 20px;
}
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.topbar .spacer { flex: 1; }
.topbar select { width: auto; min-height: 32px; padding: 4px 8px; }
.topbar select, .topbar .btn { font-size: 0.9rem; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; min-width: 160px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  text-decoration: none; line-height: 1.2; min-height: 36px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 0.85rem; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 0.9rem; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
.field-error { color: var(--danger); font-size: 0.82rem; margin-top: 4px; min-height: 1em; }
input[type='text'], input[type='search'], input[type='password'], input[type='url'], input[type='number'], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[aria-invalid='true'] { border-color: var(--danger); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 4px; }
.card > .lead { color: var(--muted); margin-bottom: 14px; font-size: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; word-break: break-all; }

/* Status chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-online { background: var(--ok-bg); color: var(--ok); }
.chip-pairing { background: var(--warn-bg); color: var(--warn); }
.chip-offline { background: var(--danger-bg); color: var(--danger); }
.chip-new { background: var(--off-bg); color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--info-bg); color: var(--info); font-size: 0.78rem; font-weight: 600; }

/* Summary strip */
.summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.summary button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 8px 14px; cursor: pointer; font: inherit; min-width: 110px; text-align: left; }
.summary button strong { display: block; font-size: 1.35rem; line-height: 1.1; }
.summary button span { font-size: 0.8rem; color: var(--muted); }
.summary button[aria-pressed='true'] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 220px; }
.toolbar .sel { width: 190px; }

/* Instance list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list-head, .list-row {
  display: grid; grid-template-columns: minmax(150px, 2fr) 170px minmax(120px, 1.2fr) minmax(140px, 2fr) 150px;
  gap: 12px; align-items: center; padding: 10px 16px;
}
.list-head { background: var(--surface-2); color: var(--muted); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.list-row { border-top: 1px solid var(--border); }
.list-row:hover { background: var(--surface-2); }
.list-row .name { font-weight: 600; word-break: break-word; }
.list-row .name small { display: block; color: var(--muted); font-weight: 400; font-family: var(--mono); font-size: 0.75rem; }
.list-row .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .actions { display: flex; gap: 6px; justify-content: flex-end; }
.list-empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.list-foot { padding: 12px; text-align: center; border-top: 1px solid var(--border); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: transparent; color: var(--muted); font: inherit; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Event picker */
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 12px; max-height: 260px; overflow-y: auto; overflow-x: hidden; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.events .check { min-width: 0; overflow-wrap: anywhere; }

/* Targets */
.targets { list-style: none; margin: 0 0 14px; padding: 0; }
.targets li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface); }
.targets .url { flex: 1; word-break: break-all; }
.targets .evs { color: var(--muted); font-size: 0.82rem; }

/* QR */
.qr { display: grid; justify-items: center; gap: 8px; padding: 12px; }
.qr img { width: 240px; height: 240px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); }
.code-box { font-family: var(--mono); font-size: 1.6rem; letter-spacing: 0.12em; padding: 10px 18px; background: var(--surface-2); border-radius: 8px; border: 1px dashed var(--border); }

/* Modal */
dialog.modal { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3); }
dialog.modal-sm { width: min(420px, calc(100vw - 24px)); }
dialog.modal-lg { width: min(760px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(10, 15, 22, 0.55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow: auto; max-height: calc(100vh - 120px); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); cursor: pointer; font-size: 0.9rem; word-break: break-word; }
.toast-success { background: var(--ok); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* Login */
.login { max-width: 440px; margin: 8vh auto 0; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 860px) {
  .list-head { display: none; }
  .list-row { grid-template-columns: 1fr auto; row-gap: 6px; }
  .list-row .col-number, .list-row .col-webhook { grid-column: 1 / -1; }
  .list-row .actions { grid-column: 1 / -1; justify-content: flex-start; }
  main { padding: 16px 12px 80px; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* Help badge: "?" that explains a setting on hover, focus or tap. */
.help {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; margin-left: 6px; border-radius: 50%;
  border: 1px solid var(--muted); color: var(--muted); background: var(--surface);
  font-size: 0.72rem; font-weight: 700; line-height: 1; cursor: help; vertical-align: middle; user-select: none;
}
.help:hover, .help:focus-visible, .help.open { color: var(--primary-text); background: var(--primary); border-color: var(--primary); }
.help .tip {
  display: none; position: fixed; z-index: 1000; top: 0; left: 0;
  width: max-content; max-width: min(300px, calc(100vw - 16px)); padding: 9px 12px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: 0.82rem; font-weight: 400; line-height: 1.45;
  text-align: left; white-space: normal; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); cursor: default;
  pointer-events: none;
}
.help.open .tip { display: block; }
.check-row { display: inline-flex; align-items: center; }
.card > h2 .help, .page-head h1 .help { font-size: 0.72rem; }

/* Group list rows */
.group-row { grid-template-columns: minmax(180px, 2.4fr) 140px minmax(130px, 1.4fr) 120px; }
.group-row .name small { font-family: var(--mono); word-break: break-all; }
@media (max-width: 860px) { .group-row { grid-template-columns: 1fr auto; } }
textarea { resize: vertical; }

/* Native storage */
.usage { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2, rgba(127,127,127,.18)); overflow: hidden; margin: 8px 0; }
.usage-fill { height: 100%; background: var(--accent, #2563eb); transition: width .3s; }
.usage-warn .usage-fill { background: var(--warn, #d97706); }
.usage-full .usage-fill { background: var(--danger, #dc2626); }
.usage-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: currentColor; opacity: .55; }
.notice { border-left: 4px solid var(--warn, #d97706); background: var(--surface-2, rgba(127,127,127,.12)); padding: 8px 12px; border-radius: 6px; margin: 8px 0 12px; }
.notice p { margin: 4px 0 0; }

/* API documentation */
.docs-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.docs-side { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; padding-right: 4px; }
.docs-list details { margin: 6px 0; }
.docs-list summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.docs-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; padding: 6px 8px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .88rem; }
.docs-item:hover { background: var(--surface-2, rgba(127,127,127,.12)); }
.docs-item.active { background: var(--primary-soft, rgba(37,99,235,.14)); }
.docs-item .docs-path { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.docs-item .docs-sum { grid-column: 1 / -1; color: var(--muted, #6b7280); font-size: .8rem; }
.method { display: inline-block; min-width: 3.6em; text-align: center; font-size: .68rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; color: #fff; letter-spacing: .03em; }
.method.big { font-size: .85rem; padding: 4px 10px; }
.m-get { background: #0b7d57; } .m-post { background: #2563eb; } .m-put { background: #b45309; } .m-delete { background: #c0392b; } .m-patch { background: #7c3aed; }
.docs-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.docs-url { font-size: 1rem; word-break: break-all; }
.chip.auth-token { background: rgba(37,99,235,.14); } .chip.auth-admin { background: rgba(180,83,9,.16); } .chip.auth-none { background: rgba(11,125,87,.14); }
.docs-content .card { margin-bottom: 16px; }
.docs-content h1 { margin: 8px 0; }
.table-wrap { overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.doc-table th, .doc-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border, rgba(127,127,127,.25)); vertical-align: top; }
.doc-table th { font-weight: 600; white-space: nowrap; }
.req { color: var(--danger, #dc2626); font-weight: 700; }
pre.code { background: var(--surface-2, rgba(127,127,127,.12)); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: .82rem; line-height: 1.45; max-height: 460px; margin: 8px 0; white-space: pre; }
pre.code.curl { max-height: none; white-space: pre-wrap; word-break: break-all; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.status { display: inline-block; font-weight: 700; padding: 2px 8px; border-radius: 4px; font-size: .8rem; }
.s-2xx { background: rgba(11,125,87,.18); color: #0b7d57; } .s-4xx { background: rgba(180,83,9,.2); color: #b45309; } .s-5xx, .s-0xx { background: rgba(192,57,43,.2); color: #c0392b; } .s-3xx { background: rgba(37,99,235,.16); }
.try-output { margin-top: 12px; }
.ev-doc { padding: 3px 0; font-size: .9rem; }
@media (max-width: 900px) { .docs-layout { grid-template-columns: 1fr; } .docs-side { position: static; max-height: 320px; } }

/* Server resources */
.meter { margin: 8px 0 12px; }
.spark { display: block; margin-top: 4px; }
.spark-base { stroke: var(--border, rgba(127,127,127,.3)); stroke-width: 1; }
.spark-line { stroke: var(--primary, #2563eb); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
