:root {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-sidebar: #10152a;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
  --text: #1b2140;
  --text-muted: #6b7280;
  --text-inverse: #e7e9f7;
  --text-inverse-muted: #9aa1c4;
  --border: #e6e9f2;
  --accent: #6d5efc;
  --accent-2: #22d3ee;
  --success: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(16, 21, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 21, 42, 0.08);
  --shadow-lg: 0 20px 48px rgba(16, 21, 42, 0.16);
  --transition: 180ms cubic-bezier(.4, 0, .2, 1);
}

[data-theme='dark'] {
  --bg: #0b0e1a;
  --bg-elevated: #131829;
  --bg-sidebar: #0b0e1a;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
  --text: #e7e9f7;
  --text-muted: #9aa1c4;
  --text-inverse: #e7e9f7;
  --text-inverse-muted: #9aa1c4;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

a { color: inherit; text-decoration: none; }

.app-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-sidebar) 0%, #171d38 100%);
  color: var(--text-inverse);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 8px 10px 22px;
}

.sidebar-logo {
  width: 100%;
  max-width: 190px;
  height: auto;
}

.public-brand {
  text-align: center;
  margin-bottom: 26px;
}

.public-brand img {
  width: 200px;
  max-width: 60vw;
  height: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-inverse-muted);
  font-weight: 500;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.nav-link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-inverse);
  transform: translateX(2px);
}

.nav-link.active {
  background: linear-gradient(90deg, rgba(109, 94, 252, .25), rgba(34, 211, 238, .08));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(109, 94, 252, .35);
}

.nav-link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .9;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

/* ---------- Main area ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.topbar h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 700;
}

.content {
  padding: 28px;
  animation: fadeInUp 320ms ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  /* "none" (não "translateY(0)") - um transform residual, mesmo zerado, faz o elemento
     virar containing block de descendentes position:fixed (ex.: o backdrop dos modais),
     cortando/deslocando o modal em vez de centralizar na tela inteira. */
  to { opacity: 1; transform: none; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-body { padding: 22px; }

.grid {
  display: grid;
  gap: 18px;
}

.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1100px) {
  .grid-cols-4, .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 800;
  margin-top: 6px;
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
}

.stat-card .glow {
  position: absolute;
  right: -30px;
  top: -30px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  filter: blur(10px);
  opacity: .35;
}

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: linear-gradient(120deg, var(--accent), #8b7bff);
  color: #fff;
  box-shadow: 0 6px 18px rgba(109, 94, 252, .35);
}

.btn-primary:hover { box-shadow: 0 10px 24px rgba(109, 94, 252, .45); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: var(--bg); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 94, 252, .15);
}

/* ---------- Table ---------- */
table.data { width: 100%; border-collapse: collapse; }

table.data th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

table.data tr { transition: background var(--transition); }
table.data tbody tr:hover { background: var(--bg); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-admin { background: rgba(109, 94, 252, .15); color: var(--accent); }
.badge-manager { background: rgba(34, 211, 238, .15); color: #0891b2; }
.badge-operator { background: rgba(148, 163, 184, .2); color: var(--text-muted); }
.badge-on { background: rgba(22, 163, 74, .15); color: var(--success); }
.badge-off { background: rgba(239, 68, 68, .15); color: var(--danger); }

/* ---------- Modules checkbox grid (Acessos) ---------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.module-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.module-chip:hover { border-color: var(--accent); }

.module-chip input { margin-top: 3px; }

.module-chip .name { font-weight: 600; }
.module-chip .desc { font-size: 12px; color: var(--text-muted); }

/* ---------- Flash / toast ---------- */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-weight: 600;
  animation: slideDown 220ms ease both;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.flash-success { background: rgba(22, 163, 74, .12); color: var(--success); }
.flash-error { background: rgba(239, 68, 68, .12); color: var(--danger); }

/* ---------- Login page ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, rgba(109, 94, 252, .25), transparent 40%),
              radial-gradient(circle at 80% 80%, rgba(34, 211, 238, .2), transparent 40%),
              var(--bg-sidebar);
}

.login-card {
  width: 380px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  animation: fadeInUp 400ms ease both;
}

.login-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.login-card p.sub {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 13.5px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 12, 24, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  /* backdrop rola (não só o painel) e o painel usa margin:auto - evita o bug clássico de
     flexbox onde "align-items:center" + conteúdo mais alto que a tela deixa o topo do modal
     inacessível (sem como rolar até ele), mesmo com overflow-y no próprio painel. */
  overflow-y: auto;
  padding: 5vh 16px;
  z-index: 50;
}

.modal-panel {
  width: 480px;
  max-width: 100%;
  margin: auto;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  animation: fadeInUp 220ms ease both;
}

[x-cloak] { display: none !important; }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
