/* Estrutura comum do app: sidebar, topbar e conteúdo responsivo. */
:root {
  --sidebar-w: 252px;
  --topbar-h: 62px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 10px 28px rgba(16, 24, 40, .10);
  --shadow-lg: 0 24px 60px rgba(2, 6, 23, .28);
}

html, body { height: 100%; }
body.app {
  display: flex; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
}

/* ---- sidebar ---- */
.sidebar {
  position: fixed; z-index: 1100; top: 0; bottom: 0; left: 0;
  width: var(--sidebar-w); display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #2563eb, #1d4ed8);
  box-shadow: 0 6px 16px rgba(37, 99, 235, .32);
}
.brand-mark svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 10px; color: var(--text); text-decoration: none;
  font-size: 14px; font-weight: 500; line-height: 1.2;
  transition: background-color .15s, color .15s;
}
.nav a svg {
  width: 20px; height: 20px; flex: none; opacity: .78;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav a:hover { background: var(--code); }
.nav a.active { background: color-mix(in srgb, var(--accent) 12%, var(--card)); color: var(--accent); font-weight: 650; }
.nav a.active svg { opacity: 1; }

/* a regra global .admin-only usa !important; aqui mantemos o flex dos links */
.nav a.admin-only { display: none !important; }
.is-admin .nav a.admin-only { display: flex !important; }
.is-admin .topbar-actions .admin-only { display: inline-flex !important; }

.sidebar-foot { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 4px 4px 10px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--code);
  color: var(--muted); font-size: 12px; font-weight: 700;
}
.user-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name:empty::after { content: "sessão"; color: var(--muted); }
.sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sidebar-actions button {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px; font-size: 12px; color: var(--muted);
}
.sidebar-actions button:hover:not(:disabled) { color: var(--text); }
.sidebar-actions svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---- área principal ---- */
.app-main {
  flex: 1; min-width: 0; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
}
.topbar {
  position: sticky; top: 0; z-index: 900;
  min-height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 8px clamp(12px, 2.2vw, 24px);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.topbar-title h1 { font-size: clamp(17px, 2.2vw, 21px); line-height: 1.2; letter-spacing: -.02em; }
.topbar-sub { display: flex; align-items: center; gap: 6px; min-height: 16px; font-size: 12px; color: var(--muted); }
.topbar-sub .dot { margin-right: 0; }  /* o gap do flex já separa */
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; justify-content: flex-end; flex-wrap: wrap; }
.page-body { flex: 1; min-height: 0; padding: clamp(14px, 2.2vw, 24px); }
.page-body.map-body { padding: 0; display: flex; min-height: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-size: 18px; flex: none;
}
.icon-btn svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* indicador de estado (conexão etc.) */
.dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); vertical-align: middle; flex: none; margin-right: 6px;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* botões que também são links */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.menu-btn { display: none; }
.overlay {
  position: fixed; inset: 0; z-index: 1050;
  background: rgba(2, 6, 23, .5); backdrop-filter: blur(2px);
}
.only-mobile { display: none !important; }

/* ---- blocos reutilizáveis ---- */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.stat h2 { margin-bottom: 8px; }
.stat .big { font-size: clamp(20px, 3vw, 26px); }
.card { box-shadow: var(--shadow-sm); }
.section-gap { display: flex; flex-direction: column; gap: 14px; }
.table-wrap { width: 100%; overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
.table-wrap table { min-width: 560px; }
.check-inline, .select-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.check-inline input { width: 18px; height: 18px; }
.select-inline select { width: auto; }
.btn-soft { background: var(--code); }

/* ---- celular ---- */
@media (max-width: 960px) {
  .sidebar {
    width: min(84vw, 300px); transform: translateX(-100%);
    transition: transform .22s ease, box-shadow .22s ease; border-right: 0;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .app-main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .only-mobile { display: inline-flex !important; }
  #sidebarClose { margin-left: auto; }
  body.nav-open { overflow: hidden; }
}
@media (min-width: 961px) {
  .overlay { display: none !important; }
}
@media (max-width: 600px) {
  .topbar { gap: 6px; padding: 8px 10px; }
  .topbar-title { flex: 1 1 auto; }
  .topbar-title h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions {
    gap: 6px; flex-wrap: nowrap; overflow-x: auto; max-width: 100%;
    justify-content: flex-start; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions > * { flex: none; white-space: nowrap; }
  .topbar-actions button, .topbar-actions .btn { padding: 6px 9px; font-size: 12px; }
  .topbar-actions .check-inline, .topbar-actions .select-inline { font-size: 12px; }
  .topbar-actions .select-inline > span { display: none; }
  .page-body { padding: 12px; }
  .hide-xs { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
