/*
 * layout.css — Shell, Sidebar (240px expandida), Topbar, Main
 * Padrão Velzon: sidebar escura vertical com grupos de navegação.
 */

/* Reset mínimo */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-brand);
  background: var(--canvas);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: var(--fs-md);
  line-height: 1.5;
}

/* ── App Shell ────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width, 240px) 1fr;
  grid-template-rows: 74px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns .25s ease;
}
.app-shell.sidebar-collapsed {
  --sidebar-width: 72px;
}

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  transition: width .25s ease;
  width: var(--sidebar-width, 240px);
  z-index: 100;
}

/* Logo */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 74px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-logo-full {
  height: 50px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.sidebar-logo-mini {
  height: 40px;
  width: auto;
  display: none;
  flex-shrink: 0;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

/* Section label */
.sidebar-section-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-section-label);
  padding: 14px 22px 6px;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}

/* Nav item */
.side-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 18px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  border-radius: 0;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
  overflow: hidden;
  min-height: 42px;
  margin: 1px 8px;
  border-radius: 6px;
  user-select: none;
}
.side-item:hover {
  background: var(--sidebar-item-hover);
  color: var(--sidebar-text-active);
}
.side-item.active {
  background: var(--sidebar-item-active);
  color: var(--sidebar-text-active);
}
.side-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--sidebar-accent);
  margin-left: -8px;
}
.side-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .85;
}
.side-item.active .side-icon { opacity: 1; }
.side-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-badge {
  background: var(--risk-critical);
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: 700;
  border-radius: 9999px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 8px 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

/* Sidebar collapsed — hide labels */
.app-shell.sidebar-collapsed .sidebar-section-label,
.app-shell.sidebar-collapsed .side-label,
.app-shell.sidebar-collapsed .sidebar-logo-full,
.app-shell.sidebar-collapsed .side-badge {
  display: none;
}
.app-shell.sidebar-collapsed .sidebar-logo-mini {
  display: block;
}
.app-shell.sidebar-collapsed .side-item {
  justify-content: center;
  padding: 10px;
}
.app-shell.sidebar-collapsed .side-item::before {
  margin-left: -8px;
}
.app-shell.sidebar-collapsed .sidebar-header {
  justify-content: center;
  padding: 0 10px;
}

/* ── Topbar ───────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 74px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow-soft);
}

/* Toggle de sidebar */
.sidebar-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background .15s ease, color .15s ease;
}
.sidebar-toggle:hover { background: var(--surface-3); color: var(--text); }

/* Breadcrumb / page title */
.page-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}
.page-sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-left: 4px;
}

/* Search */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  width: 240px;
  transition: border-color .15s ease;
}
.topbar-search:focus-within {
  border-color: var(--accent);
}
.topbar-search input {
  border: none;
  background: transparent;
  font-size: var(--fs-base);
  color: var(--text);
  width: 100%;
  outline: none;
  font-family: var(--font-ui);
}
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search .search-icon { color: var(--text-muted); font-size: 15px; flex-shrink: 0; }

/* Chip de saude das fontes — fica no vao entre a busca e os icones da direita */
.topbar-fontes { position: relative; margin-left: auto; }
.topbar-fontes-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease;
}
.topbar-fontes-chip:hover { border-color: var(--accent); }
.topbar-fontes-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.topbar-fontes-dot.saude-dot-ok { background: var(--risk-low); }
.topbar-fontes-dot.saude-dot-atrasada { background: var(--risk-medium); }
.topbar-fontes-dot.saude-dot-erro { background: var(--risk-critical); }
.topbar-fontes-sep { color: var(--border); }
.topbar-fontes-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 12px 14px;
  z-index: 250;
}
.topbar-fontes-popover-titulo { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: 8px; }
.topbar-fontes-popover-body { display: flex; flex-direction: column; gap: 6px; }
.topbar-fontes-popover-linha { display: flex; align-items: center; justify-content: space-between; font-size: var(--fs-sm); }
.topbar-fontes-popover-rodape { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 8px; font-size: var(--fs-xs); color: var(--text-muted); }
.topbar-fontes-popover-link { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 0 0; margin-top: 4px; font-size: var(--fs-xs); color: var(--accent); cursor: pointer; font-family: var(--font-ui); }
.topbar-fontes-popover-link:hover { text-decoration: underline; }

/* Topbar right group */
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Icon buttons (notification, fullscreen etc.) */
.topbar-icon-btn {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  padding: 7px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
  text-decoration: none;
}
.topbar-icon-btn:hover { background: var(--surface-3); color: var(--text); }
.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--risk-critical);
  border: 2px solid var(--surface);
}

/* Theme switch pill */
.theme-switch { position: relative; }
.theme-switch-btn {
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s ease;
}
.theme-switch-btn:hover { background: var(--surface-3); }
.theme-switch-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-xl);
  padding: 6px;
  min-width: 220px;
  z-index: 1500;
}
.theme-switch-menu.open { display: block; }
.tsm-group-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding: 8px 10px 4px;
}
.tsm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  color: var(--text-2);
}
.tsm-item:hover { background: var(--surface-3); }
.tsm-item.active { color: var(--text); font-weight: 600; }
.tsm-item .tsm-dot { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border); flex-shrink: 0; }
.tsm-item .tsm-check { margin-left: auto; color: var(--accent); font-size: var(--fs-base); }
.tsm-item:not(.active) .tsm-check { visibility: hidden; }
.tsm-divider { height: 1px; background: var(--border); margin: 4px 6px; }

/* Tenant chip */
.tenant-chip {
  font-size: var(--fs-sm);
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-family: var(--font-ui);
  white-space: nowrap;
}

/* ── Main content ─────────────────────────────────── */
.main {
  grid-area: main;
  padding: 24px;
  overflow-x: hidden;
  min-height: calc(100vh - 74px);
  isolation: isolate;
}

/* Sections */
.section { display: none; }
.section.active { display: block; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header-title {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.page-header-sub {
  font-size: var(--fs-base);
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toast container */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
