:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --border: #e1e4e9;
  --text: #15171b;
  --muted: #5e6572;
  --accent: #15171b;
  --on-accent: #ffffff;

  --ok: #1b7a43;
  --ok-soft: #e3f2e9;
  --busy: #2356c2;
  --busy-soft: #e7edfa;
  --warn: #9c5c00;
  --warn-soft: #fcefd8;
  --error: #c0281a;
  --error-soft: #fbe6e3;
  --off: #626a77;
  --off-soft: #eceef1;

  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 20 26 / 6%), 0 4px 16px rgb(16 20 26 / 4%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12;
    --surface: #16191e;
    --surface-2: #1c2026;
    --border: #2a2f37;
    --text: #eceef2;
    --muted: #9ba3af;
    --accent: #eceef2;
    --on-accent: #0d0f12;

    --ok: #46c27a;
    --ok-soft: rgb(70 194 122 / 14%);
    --busy: #74a0ff;
    --busy-soft: rgb(116 160 255 / 14%);
    --warn: #f2a93b;
    --warn-soft: rgb(242 169 59 / 15%);
    --error: #ff6f61;
    --error-soft: rgb(255 111 97 / 15%);
    --off: #9ba3af;
    --off-soft: rgb(155 163 175 / 13%);

    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: var(--busy); }
code { font: 0.9em ui-monospace, SFMono-Regular, Consolas, monospace; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ topo */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px max(16px, calc((100vw - 1400px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.2rem; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.logo { width: 38px; height: 38px; stroke: none; fill: var(--accent); }
.logo .logo-paper { fill: var(--muted); opacity: 0.55; }
.logo .logo-label { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.logo .logo-lines { stroke: var(--accent); stroke-width: 1.6; fill: none; }

.summary { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--lvl-soft);
  color: var(--lvl);
  font-size: 0.9rem;
  font-weight: 600;
}
.pill b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.pill.zero { background: var(--off-soft); color: var(--off); }

/* ------------------------------------------------------------ barra de ferramentas */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px max(16px, calc((100vw - 1400px) / 2)) 0;
}

.sources, .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
}
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.chip.on i { background: var(--ok); }
.chip.off { cursor: pointer; }
.chip.off i { background: var(--warn); }
.chip.demo { color: var(--busy); border-color: var(--busy); }
.chip.demo i { background: var(--busy); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { opacity: 0.88; }
.btn.ghost { background: transparent; }
.btn.small { height: 32px; padding: 0 12px; font-size: 0.85rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.icon-btn.toggle[aria-pressed="true"] { color: var(--text); background: var(--surface-2); border-color: var(--muted); }
.icon-btn.toggle[aria-pressed="false"] { opacity: 0.6; }

.interval { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; }
.interval select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--busy);
  outline-offset: 2px;
}

/* ------------------------------------------------------------ avisos */

.notices {
  display: grid;
  gap: 10px;
  padding: 14px max(16px, calc((100vw - 1400px) / 2)) 0;
}
.notices:empty { display: none; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
}
.notice.lvl-warn { border-color: var(--warn); background: var(--warn-soft); display: block; }
.notice.subtle { color: var(--muted); }
.notice.subtle b { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------ primeira configuração */

.setup {
  max-width: 1040px;
  margin: 28px auto 0;
  padding: 0 16px;
}
.setup h2 { font-size: 1.5rem; letter-spacing: -0.015em; }
.setup .lead { margin: 6px 0 20px; color: var(--muted); max-width: 62ch; }

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

.option {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.option header { display: flex; gap: 12px; align-items: flex-start; }
.option h3 { font-size: 1.08rem; margin-bottom: 4px; }
.option p { margin: 0; }
.option .btn { align-self: flex-start; }
.option .hint { color: var(--muted); font-size: 0.86rem; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.conn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  flex: none;
}

.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

.detect {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.88rem;
}
.detect.ok i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }

.link { padding: 0; border: 0; background: none; color: var(--busy); font: inherit; text-decoration: underline; cursor: pointer; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  flex: none;
}

/* ------------------------------------------------------------ cartões das impressoras */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 16px;
  padding: 18px max(16px, calc((100vw - 1400px) / 2)) 8px;
}

.card {
  --lvl: var(--off);
  --lvl-soft: var(--off-soft);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px 14px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--lvl);
}

.lvl-ok { --lvl: var(--ok); --lvl-soft: var(--ok-soft); }
.lvl-busy { --lvl: var(--busy); --lvl-soft: var(--busy-soft); }
.lvl-info { --lvl: var(--busy); --lvl-soft: var(--busy-soft); }
.lvl-warn { --lvl: var(--warn); --lvl-soft: var(--warn-soft); }
.lvl-error { --lvl: var(--error); --lvl-soft: var(--error-soft); }
.lvl-offline, .lvl-connecting { --lvl: var(--off); --lvl-soft: var(--off-soft); }
.card.lvl-error, .card.lvl-offline { border-color: color-mix(in srgb, var(--lvl) 45%, var(--border)); }

.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-title { min-width: 0; flex: 1; }
.card-title h2 { font-size: 1.05rem; overflow-wrap: anywhere; }
.card-title .meta { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.card-head .icon-btn { width: 30px; height: 30px; border-color: transparent; background: transparent; }
.card-head .icon-btn svg { width: 16px; height: 16px; }

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--lvl-soft);
  color: var(--lvl);
}
.status strong { font-size: 1.35rem; letter-spacing: -0.01em; line-height: 1.15; }
.status-kind {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; flex: none; }
.lvl-error .dot { animation: pulse 1.3s ease-in-out infinite; }
.lvl-busy .dot { animation: pulse 2s ease-in-out infinite; }
.lvl-connecting .dot { animation: pulse 1s ease-in-out infinite; }

.help { margin: 0; font-size: 0.9rem; }

.also { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.also li {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--lvl-soft);
  color: var(--lvl);
  font-size: 0.8rem;
  font-weight: 600;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px 14px;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.facts dt { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.facts dd { margin: 0; font-size: 0.88rem; font-weight: 500; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  min-height: 32px;
}
.updated { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.card.flash { animation: flash 0.9s ease-out 2; }

.footer {
  padding: 24px 16px 36px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ------------------------------------------------------------ diálogos */

dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
}
dialog.wide { width: min(620px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 12 16 / 45%); }
dialog h2 { font-size: 1.2rem; margin-bottom: 8px; }
dialog h3 { font-size: 1rem; margin: 18px 0 8px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }

.field { display: grid; gap: 6px; font-size: 0.85rem; font-weight: 600; }
.field input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
}
.form-error { min-height: 1.4em; margin: 8px 0 0 !important; color: var(--error) !important; font-size: 0.85rem !important; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.ways { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 0.92rem; }
.faq { margin: 0; font-size: 0.9rem; }
.faq dt { font-weight: 600; margin-top: 10px; }
.faq dd { margin: 2px 0 0; color: var(--muted); }

/* ------------------------------------------------------------ animações */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--lvl) 60%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

@media (max-width: 640px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-start; }
  .interval span { display: none; }
  .status strong { font-size: 1.2rem; }
}
