/* ===== Design system =====
   Visual profissional/flat (07-31): sidebar escura sólida tipo Stripe/Vercel,
   conteúdo claro sem vidro/blur, sem gradientes decorativos — cor de destaque
   usada só em botões, indicador de aba ativa e status. Ícones de navegação
   viraram SVG de linha monocromático (antes eram emoji). */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --border: #e2e5ec;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #4056e0; /* personalizável no painel */
  --accent-2: color-mix(in srgb, var(--accent) 70%, #7c3aed 30%); /* 2ª cor p/ gráficos (série 2) */
  --accent-strong: color-mix(in srgb, var(--accent) 85%, #000);
  --accent-text: color-mix(in srgb, var(--accent) 85%, var(--text));
  --ok-bg: #ddf5e2; --ok-text: #14691f;
  --warn-bg: #fff2cf; --warn-text: #8a6100;
  --err-bg: #fde1df; --err-text: #b3261e;
  --shadow: 0 1px 2px rgba(18, 28, 60, 0.04), 0 2px 8px rgba(18, 28, 60, 0.05);
  --shadow-lg: 0 12px 34px rgba(10, 16, 40, 0.16);
  --radius: 10px;

  /* Sidebar: navy sólido, propositalmente FIXO (não segue claro/escuro do
     conteúdo) — é a "moldura" do produto, igual Stripe/Vercel/Linear */
  --sidebar-bg: #0b1220;
  --sidebar-bg-hover: #161f33;
  --sidebar-active-bg: #1b2540;
  --sidebar-text: #9aa5b8;
  --sidebar-text-hover: #e7ebf7;
  --sidebar-text-active: #ffffff;
  --sidebar-border: #1b2436;
  --sidebar-muted: #5b6478;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1322;
    --surface: #161d30;
    --surface-2: #1b2338;
    --border: #2a3350;
    --text: #e7ebf7;
    --muted: #94a0bd;
    --accent-strong: color-mix(in srgb, var(--accent) 80%, #fff);
    --accent-text: color-mix(in srgb, var(--accent) 55%, #fff);
    --ok-bg: #143723; --ok-text: #7fdd96;
    --warn-bg: #3a2e0d; --warn-text: #f0c667;
    --err-bg: #3f1b18; --err-text: #ff9a92;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 34px rgba(0, 0, 0, 0.5);
    /* --sidebar-* não muda: a moldura escura é a mesma nos dois temas */
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  font-size: 15px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}
.hidden { display: none !important; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 0.9rem; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; font-size: 0.85em; }
.mono { font-family: ui-monospace, 'Cascadia Mono', monospace; font-size: 0.82rem; word-break: break-all; }

/* ===== Ícones de linha (SVG inline) ===== */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -4px;
}
/* Ícone dentro de texto corrido (botões, títulos) — a sidebar já centraliza
   via flex, então essa margem só importa fora dela */
h2 .icon, h3 .icon, .btn .icon, .badge .icon, .stat-ico .icon { margin-right: 4px; }
.stat-ico .icon { width: 20px; height: 20px; vertical-align: middle; margin-right: 0; }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 26px;
  box-shadow: var(--shadow-lg);
}
.login-logo { font-size: 2.6rem; text-align: center; line-height: 1; }
.login-card h1 { margin: 0; font-size: 1.35rem; text-align: center; letter-spacing: -0.02em; }

/* ===== Layout: sidebar + conteúdo ===== */
#app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: 234px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 12px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  padding: 4px 10px;
  letter-spacing: -0.02em;
  color: var(--sidebar-text-active);
}
.brand-name { font-size: 0.98rem; }
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  /* min-height:0 é o que permite o flex item ROLAR em vez de estourar a
     altura fixa da sidebar quando a lista de abas não cabe na tela */
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, #fff 20%, transparent) transparent;
}
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }
.sidebar nav::-webkit-scrollbar-thumb { background: color-mix(in srgb, #fff 16%, transparent); border-radius: 99px; }
.sidebar nav::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, #fff 28%, transparent); }
.tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: none;
  background: none;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.94rem;
  color: var(--sidebar-text);
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab .ico { width: 22px; display: inline-flex; align-items: center; justify-content: center; }
.tab:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-hover); }
.tab.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  font-weight: 600;
  box-shadow: inset 3px 0 0 0 var(--accent);
}
.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 2px;
  border-top: 1px solid var(--sidebar-border);
  color: var(--sidebar-muted);
}
.sidebar-foot .btn { background: transparent; border-color: var(--sidebar-border); color: var(--sidebar-text); }
.sidebar-foot .btn:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-hover); }
#user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; min-width: 0; padding: 26px 28px 60px; max-width: 1180px; }
.page-title { margin: 0 0 16px; font-size: 1.35rem; letter-spacing: -0.02em; }
.subhead { margin: 26px 0 6px; font-size: 1.05rem; }

.panel-head { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.panel-head input[type='text'],
.panel-head input:not([type]),
.panel-head input[type='date'],
.panel-head select { flex: 0 1 320px; }

/* ===== Cards e tabelas ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.wa-card { max-width: 480px; margin: 0 auto; text-align: center; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tr:last-child td { border-bottom: none; }
tbody tr, table tr { transition: background 0.15s ease; }
table tr:hover td { background: var(--surface-2); }

/* ===== Inputs e botões ===== */
input, select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; color: var(--muted); }
input[type='file'] { border: 1px dashed var(--border); background: var(--surface-2); }

.btn {
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--err-text); border-color: color-mix(in srgb, var(--err-text) 35%, var(--border)); }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 5px 10px; font-size: 0.84rem; }
.error { color: var(--err-text); min-height: 1.2em; margin: 0; font-size: 0.9rem; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
}
.badge.ok { background: color-mix(in srgb, var(--ok-bg) 80%, transparent); color: var(--ok-text); border-color: color-mix(in srgb, var(--ok-text) 20%, transparent); }
.badge.warn { background: color-mix(in srgb, var(--warn-bg) 80%, transparent); color: var(--warn-text); border-color: color-mix(in srgb, var(--warn-text) 20%, transparent); }
.badge.err { background: color-mix(in srgb, var(--err-bg) 80%, transparent); color: var(--err-text); border-color: color-mix(in srgb, var(--err-text) 20%, transparent); }
.badge.info { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }

/* Barra de presença (abas Acessos/Visitantes) */
#access-stats, #visit-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
#access-stats .badge, #visit-stats .badge { padding: 10px 16px; font-size: 0.95rem; border-radius: 10px; box-shadow: var(--shadow); }

/* ===== Visão Geral (dashboard) ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: inset 3px 0 0 0 var(--accent), var(--shadow);
}
.stat-card .stat-ico {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--accent);
}
.stat-card .stat-num { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat-card .stat-label { color: var(--muted); font-size: 0.84rem; }
.stat-card.warn { box-shadow: inset 3px 0 0 0 var(--warn-text), var(--shadow); }
.stat-card.warn .stat-ico { color: var(--warn-text); }
.stat-card.err { box-shadow: inset 3px 0 0 0 var(--err-text), var(--shadow); }
.stat-card.err .stat-ico { color: var(--err-text); }
.stat-card.ok { box-shadow: inset 3px 0 0 0 var(--ok-text), var(--shadow); }
.stat-card.ok .stat-ico { color: var(--ok-text); }

.dash-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.chart-card canvas { width: 100%; display: block; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #080c1c 55%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade-in 0.15s ease;
}
.modal-card {
  width: 480px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.18s ease;
}
.modal-card.wide { width: 940px; }
.modal-card h2 { margin: 0 0 14px; font-size: 1.1rem; letter-spacing: -0.01em; }
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* ===== DVR (gravações) ===== */
.dvr-toolbar { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.dvr-timeline {
  position: relative;
  height: 52px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
  cursor: crosshair;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.dvr-timeline.panning { cursor: grabbing; }
.dvr-block { position: absolute; top: 18px; bottom: 7px; background: var(--accent); min-width: 2px; border-radius: 2px; }
.dvr-block.rec { background: #e2574c; }
.dvr-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); }
.dvr-tick span { position: absolute; top: 2px; left: 3px; font-size: 10px; color: var(--muted); }
.dvr-playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); display: none; pointer-events: none; }

/* ===== Avatares e chips ===== */
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* ===== Personalização ===== */
.brand-logo { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; }
.login-logo img { width: 64px; height: 64px; object-fit: contain; }
.brand-form { max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.brand-file-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-file-row img { width: 48px; height: 48px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); padding: 4px; }
input[type='color'] { padding: 3px; width: 56px; height: 40px; cursor: pointer; }

/* Temas de cor prontos — atalho que só preenche o seletor de cor acima;
   o valor salvo é sempre --accent */
.theme-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.theme-swatch:hover { transform: scale(1.08); }
.theme-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 15%, transparent); }

/* ===== Responsivo ===== */
.menu-toggle {
  display: none;
  margin-left: auto;
  border: none;
  background: none;
  color: var(--sidebar-text);
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.menu-toggle:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-hover); }
.menu-backdrop { display: none; }

@media (max-width: 860px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
    z-index: 40;
    position: relative;
  }
  .brand { padding: 0 4px; flex: 1; }
  .menu-toggle { display: block; }

  /* Gaveta: some por padrão, some de cima quando .sidebar.open — lista
     vertical completa (nada de rolar barra horizontal pra achar aba) */
  .sidebar nav {
    position: absolute;
    top: calc(100% + 8px);
    left: 12px;
    right: 12px;
    flex-direction: column;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: max-height 0.22s ease, opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
  }
  .sidebar.open nav {
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
  .sidebar.open .menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: color-mix(in srgb, #080c1c 35%, transparent);
  }
  .tab { width: 100%; padding: 11px 12px; gap: 10px; }
  .tab .ico { width: 22px; }
  .sidebar-foot { border-top: none; padding: 0; }
  #user-name { display: none; }
  main { padding: 18px 14px 40px; }
  .page-title { font-size: 1.2rem; }
}

@media (max-width: 760px) {
  /* Tabelas viram área rolável na horizontal */
  #students-list table, #guardians-list table, #devices-list table,
  #access-list table, #notif-list table, #classrooms-list table,
  #schedules-list table { display: block; overflow-x: auto; }
  th, td { white-space: nowrap; }
  #access-stats .badge, #visit-stats .badge { flex: 1 1 40%; text-align: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  /* Modal vira "folha" ancorada embaixo, estilo app */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-card {
    width: 100%;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    animation: sheet-in 0.2s ease;
  }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0.5; } }
}
