:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3ea;
  --text: #17202b;
  --muted: #5e6b7a;
  --primary: #0b6bcb;
  --primary-hover: #0958a8;
  --primary-text: #ffffff;
  --danger: #c62f2f;
  --ok: #1b7f4b;
  --row-hover: #eef4fb;
  --focus: rgba(11, 107, 203, 0.28);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1c2530;
    --border: #2b3643;
    --text: #e6ebf1;
    --muted: #93a1b1;
    --primary: #3d8fe0;
    --primary-hover: #5aa2e8;
    --primary-text: #0b1118;
    --danger: #ef6b6b;
    --ok: #4cc38a;
    --row-hover: #1f2a36;
    --focus: rgba(61, 143, 224, 0.35);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

/* ---------- topo ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand small { font-weight: 500; color: var(--muted); margin-left: 6px; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }

main { max-width: 1920px; margin: 0 auto; padding: 20px 24px; }

/* ---------- cartões e formulários ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; padding: 32px 28px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 24px; color: var(--muted); }
.login form { display: grid; gap: 14px; }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

input, select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, button:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}

button {
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.secondary:hover { background: var(--surface-2); }
button.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button.danger:hover { background: var(--surface-2); }
button.link { height: auto; padding: 0; background: none; color: var(--primary); font-weight: 600; }

.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0; }
.notice { color: var(--ok); font-size: 14px; min-height: 1.2em; margin: 0; }

/* ---------- filtros ---------- */
.filters {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr) minmax(0, 1.2fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
}

/* ---------- resultados ---------- */
.status { margin: 20px 2px 10px; color: var(--muted); font-size: 14px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  vertical-align: bottom;
  /* Cabeçalhos quebram em 2 linhas para a coluna ficar só da largura do dado. */
  white-space: normal;
  min-width: 56px;
}
th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }
td.desc { white-space: normal; min-width: 240px; font-weight: 500; }
td.num { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: 0; }

.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0 8px; color: var(--muted); }

/* ---------- configuração ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  height: 40px;
  padding: 0 16px;
  background: none;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.access-filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
}
.live { color: var(--ok); font-weight: 600; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 28px 2px 12px; }
.section-title h2 { margin: 0; font-size: 17px; }

.new-user { padding: 18px; display: grid; gap: 14px; }
.new-user .row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }

.cols { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 500; color: var(--text); cursor: pointer; }
.chip input { width: auto; height: auto; margin: 0; accent-color: var(--primary); }
.chip.fixed { opacity: 0.7; cursor: default; }

.users { display: grid; gap: 12px; }
.user-card { padding: 16px 18px; display: grid; gap: 12px; }
.user-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.user-head strong { font-size: 16px; }
.badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.badge.on { color: var(--ok); }
.badge.off { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button { height: 34px; padding: 0 12px; font-size: 13px; }

/* ---------- tablet / celular: cada produto vira um cartão ---------- */
@media (max-width: 900px) {
  .topbar { padding: 10px 16px; }
  .brand small { display: none; }
  main { padding: 16px; }
  .filters { grid-template-columns: 1fr 1fr; padding: 14px; }
  .filters .wide { grid-column: 1 / -1; }
  .new-user .row { grid-template-columns: 1fr; }
  .access-filters { grid-template-columns: 1fr 1fr; padding: 14px; }
  .access-filters label:first-child, .access-filters button { grid-column: 1 / -1; }

  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  table, thead, tbody { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; }
  tbody tr {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px 16px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  tbody tr:hover { background: var(--surface); }
  td, td:first-child, td:last-child { display: grid; gap: 2px; padding: 0; border: 0; white-space: normal; font-size: 14px; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
  td.desc { grid-column: 1 / -1; min-width: 0; font-size: 15px; font-weight: 600; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  td.desc::before { content: none; }
  td.empty { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .filters { gap: 10px; }
  tbody tr { grid-template-columns: 1fr 1fr; }
}
