:root {
  --bg: #0d1014;
  --surface: #151a20;
  --surface-2: #1c232b;
  --line: #27303a;
  --text: #e7ecf1;
  --muted: #8b97a5;
  --accent: #ef4444;
  --accent-ink: #fff;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: #38bdf8;
  --off: #5b6673;
  --chart: #38bdf8;
  --code-bg: #0a0d10;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f0f3f6;
    --line: #dde3ea;
    --text: #151a20;
    --muted: #5d6874;
    --off: #9aa4ae;
    --chart: #0284c7;
    --code-bg: #f4f6f9;
    --shadow: 0 10px 40px rgba(20, 30, 40, .15);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 17px; font-weight: 650; }
.brand p { margin: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.topbar-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 550; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------ main */
main { padding: 24px clamp(16px, 4vw, 40px) 64px; max-width: 1440px; margin: 0 auto; }

.summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.chip b { color: var(--text); font-weight: 650; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.info { background: var(--info); }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
}
.dot.ok.pulse { color: var(--ok); }
.dot.warn.pulse { color: var(--warn); }
.dot.bad.pulse { color: var(--bad); }

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px;
  background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--bad) 35%, var(--line));
}
.banner.warn { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.banner svg { margin-top: 2px; }
.banner p { margin: 2px 0 0; }

/* ------------------------------------------------ cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  position: relative; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--text) 25%, var(--line)); }
.card:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.card.live { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.card.live.unstable { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.card.live.bad { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }

.card-head { display: flex; align-items: center; gap: 12px; }
.type-icon {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--muted);
}
.type-icon svg { width: 22px; height: 22px; stroke-width: 1.7; }
.card.live .type-icon { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface-2)); }
.card-title { min-width: 0; flex: 1; }
.card-title h3 { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title p { margin: 0; font-size: 13px; color: var(--muted); }

.status {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; letter-spacing: .02em;
  background: var(--surface-2); color: var(--muted);
}
.status.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.status.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }
.status.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.status.info { color: var(--info); background: color-mix(in srgb, var(--info) 13%, transparent); }

.card-body { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: end; }
.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; }
.big small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.big-label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.spark { width: 100%; height: 48px; display: block; stroke: none; }
.spark path.line { stroke: var(--chart); stroke-width: 1.8; fill: none; vector-effect: non-scaling-stroke; }
.spark path.area { fill: color-mix(in srgb, var(--chart) 16%, transparent); stroke: none; }

.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.facts span { display: inline-flex; align-items: center; gap: 5px; }
.facts svg { width: 14px; height: 14px; }

.meter { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.meter-track { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; background: var(--ok); transition: width .4s; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.bad { background: var(--bad); }

.card-empty { font-size: 13px; color: var(--muted); padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.card-empty b { color: var(--text); font-weight: 600; }

.add-card {
  display: grid; place-items: center; gap: 8px; min-height: 200px; border-style: dashed;
  color: var(--muted); text-align: center; background: transparent;
}
.add-card:hover { color: var(--text); }
.add-card svg { width: 28px; height: 28px; }

/* ------------------------------------------------ drawer */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(720px, 100vw); background: var(--bg); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { padding: 18px 22px 0; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-title { display: flex; align-items: center; gap: 12px; }
.drawer-title .card-title h3 { font-size: 19px; }
.tabs { display: flex; gap: 2px; margin-top: 14px; overflow-x: auto; scrollbar-width: none; }
.tab {
  padding: 10px 14px; border: 0; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 22px; }

.section h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin-bottom: 10px; }
.section > p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.metric .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .l { font-size: 12px; color: var(--muted); }

.chart { width: 100%; height: auto; display: block; stroke: none; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--mono); stroke: none; }
.chart .line { stroke: var(--chart); stroke-width: 2; fill: none; }
.chart .area { fill: color-mix(in srgb, var(--chart) 14%, transparent); }
.chart .gap { fill: color-mix(in srgb, var(--bad) 14%, transparent); }

.preview { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; display: grid; place-items: center; }
.preview video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.preview .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; text-align: center; padding: 20px; font-size: 14px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* credenciais */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.field label, .field .label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.copy {
  display: flex; align-items: center; gap: 8px;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 4px 4px 12px; margin: 8px 0 2px; min-width: 0;
}
.copy code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 6px 0; scrollbar-width: thin; }
.copy .icon-btn { width: 30px; height: 30px; }
.copy.copied { border-color: var(--ok); }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.conn-list { display: flex; flex-direction: column; gap: 10px; }
.conn { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.conn-head { display: flex; align-items: center; gap: 10px; }
.conn-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; min-width: 0; }

input[type="text"], input[type="password"], textarea, select {
  height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--code-bg); color: var(--text); font: inherit; width: 100%;
}
textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--info) 60%, transparent); outline-offset: 0; border-color: transparent; }

/* tutorial */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: flex; flex-direction: column; gap: 14px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 30px 1fr; gap: 12px; }
.steps li::before {
  content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700;
}
.steps li > div { padding-top: 3px; min-width: 0; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.app-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); margin-bottom: 10px; }

/* diagnóstico */
.log { width: 100%; border-collapse: collapse; font-size: 13px; }
.log th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.log td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log td.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.log tr.challenge { opacity: .5; }
.log-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.mut { background: var(--surface-2); color: var(--muted); }
.attempts { display: flex; flex-direction: column; gap: 8px; }
.attempt { padding: 10px 12px; border-radius: 9px; background: var(--surface-2); font-size: 13px; }
.attempt .mono { color: var(--muted); word-break: break-all; }

/* ------------------------------------------------ modal */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .55); }
.dialog {
  width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.dialog.wide { width: min(1100px, 100%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 18px; }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 22px; }

.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.type-opt {
  display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 12px; cursor: pointer; text-align: left;
  border: 1.5px solid var(--line); background: var(--surface);
}
.type-opt:hover { border-color: color-mix(in srgb, var(--text) 30%, var(--line)); }
.type-opt[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.type-opt .type-icon { width: 38px; height: 38px; }
.type-opt b { font-size: 15px; }
.type-opt span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.error { color: var(--bad); font-size: 13px; margin: 0; }

/* ------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 550; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------ mobile */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .drawer-head { padding: 14px 16px 0; }
  .drawer-body { padding: 16px; }
  .dialog-body { padding: 16px; }
  .dialog-head { padding: 14px 16px; }
  .dialog-foot { padding: 0 16px 16px; }
  .log th:nth-child(4), .log td:nth-child(4) { display: none; }
}
