:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --text: #1d2422;
  --muted: #66706c;
  --line: #e3dfd6;
  --brand: #0f6b5c;
  --brand-ink: #ffffff;
  --brand-soft: #e2f1ec;
  --on: #13895f;
  --off: #8b928f;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --danger: #b4352c;
  --danger-soft: #fbe9e7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1b2120;
    --text: #e8ecea;
    --muted: #9aa5a1;
    --line: #2c3432;
    --brand: #3fb59a;
    --brand-ink: #08211b;
    --brand-soft: #1d332d;
    --on: #3fcf95;
    --off: #6c7471;
    --warn: #e0a84a;
    --warn-soft: #34291a;
    --danger: #ef7d73;
    --danger-soft: #3a2220;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin-bottom: .35rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .2rem; }
p { margin: .25rem 0 .75rem; }
code { background: var(--brand-soft); padding: .1em .4em; border-radius: 6px; font-size: .95em; }

.app { max-width: 560px; margin: 0 auto; padding: 0 12px 40px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }

.badge {
  font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--line); color: var(--muted);
}
.badge.ok { background: var(--brand-soft); color: var(--on); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.banner {
  background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: .9rem;
  border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; text-align: center;
}

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); font-size: .9rem; }

/* Botão principal liga/desliga */
.power-card { text-align: center; padding-top: 22px; }
.power {
  width: 100%; min-height: 92px; border: 0; border-radius: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font: inherit; font-size: 1.5rem; font-weight: 800; letter-spacing: .02em;
  color: #fff; background: var(--off); transition: background .15s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.power:active { transform: scale(.98); }
.power.on { background: var(--on); }
.power:disabled { opacity: .6; }
.power-icon { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.power-hint { margin: 10px 0 4px; color: var(--muted); font-size: .92rem; min-height: 1.3em; }
.power-hint.warn { color: var(--warn); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 10px 4px; display: flex; flex-direction: column; }
.stats strong { font-size: 1.05rem; }
.stats span { font-size: .72rem; color: var(--muted); }

/* Botões */
.btn {
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 11px 16px; min-height: 44px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.block { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Campos */
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field > span { font-size: .88rem; font-weight: 600; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%;
  min-height: 44px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.search { margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 8px; }
@media (max-width: 420px) {
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form .btn { grid-column: 1 / -1; }
}

/* Interruptor */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--line); margin-top: 8px; cursor: pointer;
}
.switch-row > span { display: flex; flex-direction: column; }
.switch-row small { color: var(--muted); font-size: .82rem; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 52px; height: 30px; min-height: 0; padding: 0; border-radius: 999px; border: 0;
  background: var(--line); position: relative; cursor: pointer; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--on); }
.switch:checked::after { transform: translateX(22px); }
.switch:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list .info { display: flex; flex-direction: column; min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.list .sub { color: var(--muted); font-size: .82rem; }
.list .sub.warn { color: var(--warn); }
.list .sub.bad { color: var(--danger); }
.list .empty { color: var(--muted); font-size: .9rem; justify-content: center; }
.list li.dim .title { color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: 6px; flex: none; }

.chips { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: .88rem;
}
.chips li.empty { padding: 4px 0; border: 0; background: none; color: var(--muted); }
.chips button {
  border: 0; background: var(--line); color: var(--text); width: 26px; height: 26px; border-radius: 50%;
  cursor: pointer; font-size: 1rem; line-height: 1;
}

.tag { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag.ok { background: var(--brand-soft); color: var(--on); }

/* Abas */
.tabs { display: flex; gap: 6px; margin: 6px 0 4px; }
.tab {
  flex: 1; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 10px; padding: 8px;
}
.tab.active { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

/* Conexão */
.connect-card { border-color: var(--warn); }
.qr { display: block; width: 100%; max-width: 280px; margin: 10px auto; border-radius: 12px; background: #fff; padding: 8px; }
.code {
  font: 800 2rem/1.2 ui-monospace, "SFMono-Regular", Menlo, monospace; letter-spacing: .12em; text-align: center;
  background: var(--brand-soft); color: var(--brand); border-radius: 14px; padding: 14px; margin: 10px 0;
}
.steps { margin: 6px 0 12px; padding-left: 1.3rem; }
.steps li { margin: 4px 0; }
.pair-form { display: grid; gap: 8px; }
.divider { text-align: center; color: var(--muted); font-size: .85rem; margin: 14px 0 6px; }

.sim-card { border-style: dashed; }
.sim-actions { display: flex; gap: 8px; }
.sim-actions .btn { flex: 1; }

.shortcuts { margin: 0; padding-left: 1.2rem; }
.shortcuts li { margin: 4px 0; }

.footer { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: .9rem; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .field { text-align: left; }
.login-icon { margin-bottom: 8px; }

/* Aviso rápido */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1d2422; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }
