:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8a93a3;
  --line: #e6e8ef;
  --line-2: #f0f1f5;
  --accent: #2f54eb;
  --accent-2: #1e3fc7;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 4px 16px rgba(17, 24, 39, .04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Topo */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1160px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; }
.nav { margin-left: auto; display: flex; gap: 4px; }
.nav a, .nav button { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 9px; color: var(--ink-2); font-weight: 500; background: none; border: 0; cursor: pointer; }
.nav a:hover, .nav button:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.main { max-width: 1160px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; margin-bottom: 14px; }
.back:hover { color: var(--ink); text-decoration: none; }

/* ---------- Botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; color: var(--ink); transition: background .15s, border-color .15s; }
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: #fecaca; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Cartões */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card h2 { font-size: 16px; font-weight: 600; }
.card .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .hint { color: var(--ink-3); font-size: 12px; }

/* ---------- Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Avisos */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); border: 1px solid #fde68a; color: #78350f; margin-bottom: 18px; }
.notice.info { background: var(--accent-soft); border-color: #c7d2fe; color: #1e3a8a; }
.notice svg { flex: none; margin-top: 2px; }
.notice b { font-weight: 600; }

/* ---------- Lista de QRs */
.search { position: relative; margin-bottom: 14px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search input { width: 100%; padding: 11px 14px 11px 42px; border: 1px solid var(--line); border-radius: 12px; background: #fff; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,84,235,.12); }

.qr-list { display: flex; flex-direction: column; gap: 10px; }
.qr-row { display: grid; grid-template-columns: 56px 1fr auto auto auto auto; align-items: center; gap: 18px; padding: 14px 16px; cursor: pointer; transition: border-color .15s, transform .15s; }
.qr-row:hover { border-color: #c7d2fe; }
.qr-thumb { width: 56px; height: 56px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.qr-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; font-size: 15px; }
.qr-sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
.metric { text-align: right; min-width: 70px; }
.metric b { display: block; font-size: 18px; font-weight: 700; }
.metric span { color: var(--ink-3); font-size: 12px; }

.empty { text-align: center; padding: 56px 20px; }
.empty .logo { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 16px; }
.empty h2 { font-size: 18px; margin-bottom: 6px; }
.empty p { color: var(--ink-2); margin: 0 0 18px; }

/* ---------- Detalhe */
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; margin-bottom: 18px; }
.detail-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 8px; }
.kv { margin-top: 16px; }
.kv .k { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin-bottom: 4px; }
.kv .v { color: var(--ink); word-break: break-all; }
.kv a.v { color: var(--accent); }
.linkbox { display: flex; align-items: center; gap: 8px; background: var(--line-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; }
.linkbox code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.meta-line { display: flex; gap: 24px; flex-wrap: wrap; color: var(--ink-3); font-size: 12px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.qr-big { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.qr-big img { width: 100%; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.qr-big .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.qr-big select { width: 100%; }
.tiny { font-size: 12px; color: var(--ink-3); }

.tabs { display: inline-flex; gap: 2px; background: #eceef4; padding: 4px; border-radius: 11px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: var(--accent-2); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: inherit; }

.breakdowns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 14px; }
.bd h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.bd-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 10px; font-size: 13px; }
.bd-row .track { grid-column: 1 / -1; height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.bd-row .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bd-row .n { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; align-items: end; height: 90px; }
.hours div { background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.hours-axis { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 11px; margin-top: 6px; }

/* ---------- Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 16px 1fr; gap: 12px; padding-bottom: 18px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .pin { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); background: #fff; margin-top: 2px; }
.timeline li:first-child .pin { border-color: var(--accent); }
.timeline .url { word-break: break-all; font-weight: 500; }

/* ---------- Formulários */
.form-grid { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.form-col { display: flex; flex-direction: column; gap: 18px; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.section-title .num { width: 24px; height: 24px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.field { margin-top: 16px; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field .help { color: var(--ink-3); font-size: 12px; margin-top: 5px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid #d9dce5; border-radius: 10px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,84,235,.12); }
.input[readonly] { background: var(--line-2); color: var(--ink-2); }
textarea.input { resize: vertical; min-height: 84px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.prefixed { display: flex; align-items: stretch; border: 1px solid #d9dce5; border-radius: 10px; overflow: hidden; background: #fff; }
.prefixed span { padding: 10px 0 10px 12px; color: var(--ink-3); white-space: nowrap; max-width: 60%; overflow: hidden; text-overflow: ellipsis; }
.prefixed input { border: 0; outline: none; padding: 10px 12px 10px 1px; flex: 1; min-width: 60px; }
.prefixed:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,84,235,.12); }

.switch-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.switch-row .t { font-weight: 600; }
.switch-row .d { color: var(--ink-3); font-size: 13px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #d1d5db; border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.checks { display: flex; gap: 18px; flex-wrap: wrap; }
.checks label { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 0; cursor: pointer; }
.checks input { width: 16px; height: 16px; accent-color: var(--accent); }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-in { display: flex; align-items: center; gap: 8px; border: 1px solid #d9dce5; border-radius: 10px; padding: 5px 10px 5px 5px; }
.color-in input[type=color] { width: 32px; height: 32px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 6px; }
.color-in code { font-size: 13px; color: var(--ink-2); }
.sticky { position: sticky; top: 80px; }
.preview-img { width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: block; }
.actions-bar { display: flex; justify-content: flex-end; gap: 10px; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 14px; font-weight: 500; }
.collapsible[hidden] { display: none; }

/* ---------- Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 500px at 50% -10%, #e0e7ff 0%, transparent 60%), var(--bg); }
.auth { width: 100%; max-width: 400px; padding: 32px 28px; }
.auth .logo { width: 48px; height: 48px; border-radius: 14px; margin: 0 auto 14px; }
.auth h1 { text-align: center; font-size: 22px; }
.auth .sub { text-align: center; color: var(--ink-2); margin: 6px 0 8px; }
.auth .btn { width: 100%; margin-top: 20px; padding: 12px; }

/* ---------- Modal e toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .15s; }
.modal { width: 100%; max-width: 440px; padding: 24px; }
.modal h2 { font-size: 18px; margin-bottom: 8px; }
.modal p { color: var(--ink-2); margin: 0 0 16px; }
.modal .actions-bar { margin-top: 20px; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: up .2s; }
.toast.err { background: var(--danger); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .detail-grid, .form-grid, .settings-grid { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .qr-row { grid-template-columns: 48px 1fr auto; }
  .qr-row .metric.opt { display: none; }
  .qr-thumb { width: 48px; height: 48px; }
}
@media (max-width: 640px) {
  .nav .lbl { display: none; }
  .breakdowns, .two { grid-template-columns: 1fr; }
  .qr-sub { max-width: 220px; }
  .qr-row .actions { display: none; }
  .main { padding-top: 20px; }
}
