/* ============================================================
   DESIGN SYSTEM — Controle de Acesso (RBAC + ACL Demo)
   Dark theme · Glassmorphism · Inter font · Sidebar Layout
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-body: #0f1117;
  --bg-surface: rgba(22, 27, 45, 0.7);
  --bg-card: rgba(30, 36, 60, 0.55);
  --bg-input: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --border-focus: #6c63ff;
  --text-primary: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #5a5f72;
  --accent: #6c63ff;
  --accent-hover: #7f78ff;
  --accent-glow: rgba(108,99,255,0.35);
  --green: #34d399;
  --green-bg: rgba(52,211,153,0.12);
  --red: #f87171;
  --red-bg: rgba(248,113,113,0.12);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251,191,36,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --transition: .25s cubic-bezier(.4,0,.2,1);
  --sidebar-width: 240px;
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(108,99,255,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(52,211,153,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

/* ---------- Typography ---------- */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); margin: 0; padding: 0; border: none; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; }
h4 { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Inputs ---------- */
input[type=text], input[type=password], select {
  font-family: inherit;
  font-size: .9rem;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border var(--transition), box-shadow var(--transition);
  width: 100%;
}
input[type=text]:focus, input[type=password]:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--text-muted); }
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b90a0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
select option { background: #1e2438; color: var(--text-primary); }

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.15); transform: translateY(-1px); }
button:active { transform: translateY(0); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 4px 20px var(--accent-glow); }

.btn-danger { color: var(--red); border-color: rgba(248,113,113,0.25); }
.btn-danger:hover { background: var(--red-bg); }

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

.btn-logout { color: var(--red); border-color: rgba(248,113,113,0.2); }
.btn-logout:hover { background: var(--red-bg); border-color: rgba(248,113,113,0.35); }

/* ---------- Status ---------- */
.ok  { color: var(--green); font-size: .9rem; }
.err { color: var(--red); font-size: .9rem; }

/* ---------- Layout Wrapper ---------- */
.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
}

/* ---------- Glass Card ---------- */
.glass {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#tela-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  animation: fadeUp .5s ease;
}
#tela-login h1 {
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 2rem;
}
#tela-login .subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: .9rem; }

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 32px;
}
.login-box h2 { text-align: center; border: none; padding: 0; margin-bottom: 24px; }
.login-box label { display: block; margin-bottom: 16px; font-size: .85rem; color: var(--text-secondary); font-weight: 500; }
.login-box label span { display: block; margin-bottom: 6px; }
.login-box .btn-primary { width: 100%; justify-content: center; padding: 12px; font-size: .95rem; margin-top: 8px; }

.login-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: .7rem; font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 24px;
  letter-spacing: .03em;
}

/* ============================================================
   CHANGE PASSWORD SCREEN
   ============================================================ */
#tela-trocar-senha {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 100vh;
  padding: 24px;
  animation: fadeUp .5s ease;
}

.senha-box { width: 100%; max-width: 420px; padding: 32px; }
.senha-box label { display: block; margin-bottom: 16px; font-size: .85rem; color: var(--text-secondary); font-weight: 500; }
.senha-box label span { display: block; margin-bottom: 6px; }
.senha-box .btn-primary { width: 100%; justify-content: center; padding: 12px; margin-top: 8px; }

.aviso {
  background: var(--yellow-bg);
  border: 1px solid rgba(251,191,36,0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  color: var(--yellow);
  font-size: .9rem;
  display: flex; align-items: center; gap: 8px;
}

#criterios-senha span, #criterios-perfil span {
  display: block;
  font-size: .82rem;
  margin: 3px 0;
  transition: color var(--transition);
}

/* ============================================================
   APP SHELL — Top Bar
   ============================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 {
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.2rem;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; color: #fff;
}
.topbar-info { line-height: 1.3; }
.topbar-name { font-weight: 600; font-size: .9rem; }
.topbar-role { font-size: .75rem; color: var(--text-secondary); }

/* Sidebar Toggle */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
}
.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition);
}

/* ============================================================
   APP LAYOUT — Sidebar + Content
   ============================================================ */
.app-layout {
  display: flex;
  min-height: calc(100vh - 70px);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  border-radius: 0;
  border-top: none;
  border-bottom: none;
  border-left: none;
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: calc(100vh - 70px);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-title {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  padding: 16px 20px 6px;
}
.sidebar-section-title:first-child { padding-top: 4px; }

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 20px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: .85rem;
  font-weight: 500;
  text-align: left;
  transition: all var(--transition);
  position: relative;
}
.sidebar-btn:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text-primary);
  transform: none;
}
.sidebar-btn.active {
  background: rgba(108,99,255,0.1);
  color: var(--accent);
  border-right: 3px solid var(--accent);
}
.sidebar-btn.active .sidebar-icon { filter: none; }

.sidebar-icon { font-size: 1rem; width: 22px; text-align: center; }
.sidebar-label { flex: 1; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 98;
}
.sidebar-overlay.active { display: block; }

/* ---------- Content Area ---------- */
.content-area {
  flex: 1;
  padding: 24px 32px;
  min-width: 0;
  overflow-y: auto;
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section-subtitle {
  font-size: .88rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ============================================================
   PAGES
   ============================================================ */
.page { display: none; animation: fadeUp .35s ease; }
.page.active { display: block; }

/* ---------- Welcome / Dashboard ---------- */
.bv-nome { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.bv-cargo {
  color: var(--text-secondary);
  font-size: .85rem;
  display: inline-flex;
  align-items: center; gap: 6px;
  background: var(--bg-input);
  padding: 4px 12px;
  border-radius: 20px;
}
.bv-modulos { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 32px; }

/* Dashboard Section */
.dashboard-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.dashboard-section-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.dashboard-modules {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.module-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .82rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.module-tag:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Dashboard Stats */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 40px 20px;
  min-height: 200px;
}
.stat-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
  margin-bottom: 8px;
}
.stat-value { font-size: 2.5rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.stat-label { font-size: .9rem; color: var(--text-secondary); margin-top: 8px; font-weight: 500; }

/* ---------- Module Content Cards ---------- */
.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color var(--transition);
}
.module-card:hover { border-color: rgba(255,255,255,0.15); }
.module-card-info { flex: 1; }
.module-card-title { font-weight: 600; font-size: .92rem; margin-bottom: 2px; }
.module-card-sub { font-size: .8rem; color: var(--text-secondary); }
.module-card-actions { display: flex; gap: 6px; }

/* ---------- Info Banner ---------- */
.info-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .88rem;
  color: var(--text-secondary);
}
.info-banner-icon { font-size: 1.3rem; }

/* ---------- User cards ---------- */
.usuario-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
  transition: border-color var(--transition);
}
.usuario-card:hover { border-color: rgba(255,255,255,0.15); }
.usuario-card-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.usuario-nome { font-weight: 600; font-size: .95rem; }
.usuario-cargo { font-size: .8rem; color: var(--text-secondary); margin-top: 2px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  margin-left: 8px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge-ativo   { background: var(--green-bg); color: var(--green); }
.badge-inativo { background: var(--red-bg); color: var(--red); }

/* ---------- User form ---------- */
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.form-row label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; color: var(--text-secondary); font-weight: 500; flex: 1; min-width: 180px; }
.form-row input, .form-row select { width: 100%; }

.cargo-desc {
  font-size: .85rem;
  color: var(--text-secondary);
  margin: 8px 0 16px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-input);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  line-height: 1.6;
}

.perm-grupos { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 14px; }

.perm-grupo h4 { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.perm-grupo label {
  display: flex; align-items: center; gap: 8px;
  font-size: .85rem; color: var(--text-secondary);
  margin-bottom: 6px; cursor: pointer;
  padding: 4px 6px; border-radius: 4px;
  transition: background var(--transition);
}
.perm-grupo label:hover { background: var(--bg-input); color: var(--text-primary); }
.perm-grupo input[type=checkbox] {
  width: 16px; height: 16px; cursor: pointer;
  accent-color: var(--accent);
}

#form-usuario {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

/* ---------- Camera Grid ---------- */
.cam-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.cam-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  font-size: .82rem;
  color: var(--text-secondary);
  background: var(--bg-card);
}
.cam-preview {
  background: #0a0e15;
  height: 80px;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  color: var(--green);
  font-weight: 600;
  letter-spacing: .04em;
}
.cam-preview.no-access { color: var(--text-muted); }

/* ---------- Perfil ---------- */
.perfil-form-wrapper { max-width: 420px; }
.perfil-form-wrapper label { display: block; margin-bottom: 16px; font-size: .85rem; color: var(--text-secondary); font-weight: 500; }
.perfil-form-wrapper label span { display: block; margin-bottom: 6px; }

/* ---------- Table ---------- */
table { border-collapse: collapse; width: 100%; margin: 10px 0; }
td, th { border: 1px solid var(--border); padding: 10px 14px; text-align: left; font-size: .88rem; }
th { background: var(--bg-input); color: var(--text-secondary); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

/* ============================================================
   RBAC/ACL Info Badge
   ============================================================ */
.info-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .65rem; font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.pill-rbac { background: rgba(108,99,255,0.15); color: #a78bfa; }
.pill-acl  { background: rgba(52,211,153,0.12); color: var(--green); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    height: 100vh;
    z-index: 99;
    border-radius: 0;
    background: rgba(15, 17, 23, 0.97);
    transition: left var(--transition);
    padding-top: 20px;
  }
  .sidebar.open { left: 0; }

  .content-area { padding: 16px; }

  .dashboard-stats { grid-template-columns: 1fr 1fr; }

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

  .perm-grupos { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .topbar { padding: 12px 16px; }
  .dashboard-stats { grid-template-columns: 1fr; }
  .topbar-left h1 { font-size: 1rem; }
  .info-pill { display: none; }
}
