:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #6b6f78;
  --line: #e4e3de;
  --accent: #0f7b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f2ec;
  --danger: #c2392b;
  --warn: #b7791f;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-weight: 700; letter-spacing: -.02em; display: flex; gap: 8px; align-items: center; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar nav { display: flex; gap: 18px; align-items: center; font-size: .9rem; }
.topbar nav a { color: var(--muted); }
main { max-width: 1040px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.agent-card { display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color .15s; }
.agent-card:hover { border-color: var(--accent); }
.empty { text-align: center; padding: 48px 20px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: #eee; color: var(--muted); width: fit-content; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.connected { background: var(--accent-soft); color: var(--accent); }
.badge.awaiting_qr, .badge.disconnected { background: #fdf3e1; color: var(--warn); }
.badge.pending_payment { background: #eef0f6; color: #4a5578; }
.badge.suspended { background: #fbe9e7; color: var(--danger); }

/* Forms */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .row { grid-template-columns: 1fr; } main { padding: 20px 14px 60px; } }

.toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; margin: 0; }
.toggle input { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: #d5d4cf; position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(16px); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9c8c2; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; font-size: .92rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-color: var(--accent); }

/* Behavior sections */
.section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; }
.section-head .desc { font-size: .85rem; color: var(--muted); font-weight: 400; }
.section-body { padding: 4px 18px 6px; border-top: 1px solid var(--line); padding-top: 16px; }
.section.off .section-body { display: none; }

/* Tables / lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

/* QR */
.qr-box { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr-placeholder { width: 260px; height: 260px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.steps { padding-left: 18px; margin: 0; } .steps li { margin-bottom: 6px; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-switch { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 9px; margin-bottom: 20px; }
.auth-switch button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.auth-switch button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* Toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .9rem; opacity: 0; transition: all .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,17,20,.4); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 22px; }
.tri { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tri select { width: auto; }
