/* layout.css — Shell do app SST Ágil: header fixo + sidebar + área de views
   Mantém o contrato JS da SPA: .view-section / .active, .nav-link, .hidden/.flex */

/* ── Shell ─────────────────────────────────────────────── */
body.app-shell { height: 100vh; overflow: hidden; }

.app-main {
  position: fixed; top: var(--header-h); left: var(--sidebar-w); right: 0; bottom: 0;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface);   /* v0.3: surface dá contraste sutil para os cards */
}

/* Navegação entre views (contrato ui.js > switchView).
   Correção pós-validação (item 3): overflow-y:auto + padding-bottom na section
   ativa — sem isso, conteúdo dinâmico que cresce além do viewport (ex.: lista
   de eventos eSocial, diagnóstico com muitos bloqueios) ficava cortado sem
   rolagem. O scroll interno do .section-body continua valendo onde existe;
   a section só rola quando o conteúdo realmente excede a altura. */
.view-section { display: none; }
.view-section.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding-bottom: 40px;
  animation: view-enter var(--dur-slow) var(--ease-out);   /* v0.3 item 4.3 */
}
@keyframes view-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .view-section.active { animation: none; }
}

/* ── Toolbar de section (substitui os headers h-16 antigos) ── */
.section-toolbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 32px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.section-toolbar .toolbar-title {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--ff-title); font-weight: 700; font-size: 18px; color: var(--fg);
}
.section-toolbar .toolbar-actions { display: flex; align-items: center; gap: 12px; }
/* v0.3 item 4.5: sombra na toolbar quando o corpo rola (sticky behavior, via JS) */
.section-toolbar { transition: box-shadow var(--dur-base) var(--ease-out); }
.section-toolbar.is-scrolled { box-shadow: var(--shadow-1); }
.btn-icon {
  background: none; border: none; cursor: pointer; color: var(--fg-faint);
  padding: 6px; border-radius: var(--radius); transition: color .15s, background .15s;
  display: inline-flex; align-items: center;
}
.btn-icon:hover { color: var(--brand-blue); background: var(--surface); }

/* Corpo rolável da section */
.section-body { flex: 1; overflow-y: auto; min-height: 0; }

/* ── Section content: fluido por padrão (v0.3) ─────────────
   Sem max-width rígido — ocupa toda a largura útil após a sidebar.
   Antes (.section-content { max-width:1280px; margin:0 auto }) sobravam
   ~180px de cada lado em telas > 1560px. */
.section-content {
  padding: var(--space-8) var(--content-pad-x);
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
@media (min-width: 1440px) {
  .section-content { padding-inline: var(--content-pad-x-wide); }
}
/* Variação "narrow" para telas focadas (login, confirmações, diagnóstico) */
.section-content.narrow {
  max-width: var(--card-max-w);
  margin: 0 auto;
}

/* ── Card de seção (v0.3) — cada bloco vira um cartão próprio ── */
.section-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: var(--shadow-1);
  padding: var(--space-6) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  transition: box-shadow var(--dur-base) var(--ease-out);
}
.section-card:hover { box-shadow: var(--shadow-2); }
.section-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--line);
}
.section-card-header .section-eyebrow {
  font-family: var(--ff-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-faint);
}
.section-card-header .section-title {
  font-family: var(--ff-title);
  font-weight: 700;
  font-size: 18px;
  color: var(--fg);
  letter-spacing: -.01em;
}

/* ── Grid de seções: 1 coluna padrão; 2 colunas em desktop+ ── */
.sections-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}
@media (min-width: 1440px) {
  .sections-grid.cols-2 { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ── Form Grid de 12 colunas (densidade horizontal) ────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-4);
}
.form-grid > .col-12,
.form-grid > .col-8,
.form-grid > .col-6,
.form-grid > .col-5,
.form-grid > .col-4,
.form-grid > .col-3 { grid-column: span 12; }   /* mobile: tudo full-width */

@media (min-width: 1024px) {
  .form-grid > .col-8 { grid-column: span 8; }
  .form-grid > .col-6 { grid-column: span 6; }
  .form-grid > .col-5 { grid-column: span 5; }
  .form-grid > .col-4 { grid-column: span 4; }
  .form-grid > .col-3 { grid-column: span 3; }
}
/* dentro do form-grid, os grupos não repetem a margem inferior do .form-group */
.form-grid > [class^="col-"] { margin-bottom: 0; }

/* ── Painel auxiliar lateral (telas wide >= 1600px) ────── */
.layout-with-aux {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}
@media (min-width: 1600px) {
  .layout-with-aux {
    grid-template-columns: 1fr var(--aux-panel-w);
    align-items: start;
  }
}
.aux-panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  position: sticky;
  top: var(--space-6);
}
/* O painel auxiliar só faz sentido em telas wide; ocultar abaixo de 1600px */
@media (max-width: 1599px) {
  .aux-panel { display: none; }
}
.aux-panel h4 {
  font-family: var(--ff-title);
  font-weight: 700;
  font-size: 14px;
  color: var(--fg);
}
.aux-panel .aux-item {
  font-size: 13px;
  color: var(--fg-dim);
  line-height: 1.5;
}
.aux-panel .aux-shortcut {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--brand-blue);
  background: var(--bg);
  cursor: pointer;
  font-family: var(--ff-body);
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out);
}
.aux-panel .aux-shortcut:hover { background: var(--surface); }

/* ── Skeleton loading (v0.3 item 4.4) ──────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface) 0%, var(--line) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius);
}
@keyframes skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line { height: 14px; margin-bottom: var(--space-2); }
.skeleton-line.lg { height: 20px; width: 40%; }
.skeleton-line.sm { height: 10px; width: 70%; }

/* ── Ícones lucide ─────────────────────────────────────── */
i[data-lucide], svg.lucide { width: 16px; height: 16px; flex-shrink: 0; }
.icon-xs, svg.icon-xs { width: 12px; height: 12px; }
.icon-sm, svg.icon-sm { width: 14px; height: 14px; }
.icon-lg, svg.icon-lg { width: 20px; height: 20px; }
.icon-xl, svg.icon-xl { width: 24px; height: 24px; }

/* ── Utilitários de estado manipulados pelo JS ─────────── */
.pointer-events-none { pointer-events: none; }
.opacity-50 { opacity: .5; }
.opacity-0 { opacity: 0; }
.translate-y-2 { transform: translateY(8px); }

/* ── Tela de login ─────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0; z-index: 90;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--bg);
  border: 1px solid var(--line); border-top: 4px solid var(--brand-blue);
  border-radius: var(--radius); padding: 32px;
}
.login-card .login-brand {
  font-family: var(--ff-title); font-weight: 700; font-size: 28px;
  color: var(--brand-blue); letter-spacing: -.01em; margin-bottom: 24px;
}
.login-card .login-brand .brand-accent { color: var(--accent); }
.login-error {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 16px; background: var(--bg);
}

/* ── Cards de KPI (painel da fundação) ────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.kpi-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); padding: 20px; text-align: center;
}
.kpi-card .kpi-value { font-family: var(--ff-title); font-weight: 700; font-size: 28px; color: var(--fg); letter-spacing: -.01em; }
.kpi-card .kpi-label {
  font-family: var(--ff-mono); font-size: 10px; color: var(--fg-faint);
  text-transform: uppercase; letter-spacing: .08em; margin-top: 4px;
}

/* ── Grids auxiliares ──────────────────────────────────── */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-meses { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }

/* ── Nota informativa (substitui os banners coloridos ad hoc) ── */
.note {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid var(--line); border-left: 4px solid var(--brand-blue);
  border-radius: var(--radius); background: var(--surface);
  padding: 12px 16px; font-size: 13px; color: var(--fg-dim);
}
.note.warn { border-left-color: var(--warn); }
.note.danger { border-left-color: var(--danger); }
.note.ok { border-left-color: var(--ok); }

/* ── Diagnóstico eSocial ───────────────────────────────── */
.diag-grupo-titulo {
  font-family: var(--ff-title); font-weight: 700; font-size: 18px;
  margin: 32px 0 4px; display: flex; align-items: center; gap: 12px;
}
.diag-grupo-titulo.criticos { color: var(--danger); }
.diag-grupo-titulo.avisos { color: var(--warn); }
.diag-grupo-sub { font-size: 13px; color: var(--fg-dim); margin-bottom: 16px; }
.diag-item {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.diag-item .diag-num { font-family: var(--ff-mono); font-size: 11px; color: var(--fg-faint); }
.diag-item .diag-desc { font-weight: 500; font-size: 14px; color: var(--fg); }
.diag-item .diag-acao { font-size: 12px; color: var(--fg-dim); margin-top: 2px; }
.diag-item .diag-amostra { font-family: var(--ff-mono); font-size: 10px; color: var(--fg-faint); margin-top: 4px; }
.diag-preenchimento { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ══════════════════════════════════════════════════════════════════
   v0.3 — Contraste sobre a nova superfície + comportamento responsivo
   ══════════════════════════════════════════════════════════════════ */

/* Com .app-main agora em --surface, blocos soltos viram "cartões" brancos
   para criar a hierarquia visual de SaaS moderno. */
.table-wrap { background: var(--bg); border-radius: calc(var(--radius) * 1.5); box-shadow: var(--shadow-1); }
.table-wrap > .data-table thead th:first-child { border-top-left-radius: calc(var(--radius) * 1.5); }
.table-wrap > .data-table thead th:last-child  { border-top-right-radius: calc(var(--radius) * 1.5); }
/* Dentro de um section-card, a tabela fica plana (sem card-em-card) */
.section-card .table-wrap { box-shadow: none; border: none; border-radius: 0; }
.section-card .table-wrap > .data-table thead th { background: var(--surface); }

/* Nota informativa visível tanto sobre surface quanto dentro de cards brancos */
.note { background: var(--bg); }

/* ── Sidebar: ícone + rótulo (modern SaaS) ─────────────── */
.app-sidebar .nav-item { display: flex; align-items: center; gap: 10px; }
.app-sidebar .nav-item i[data-lucide],
.app-sidebar .nav-item svg.lucide { flex-shrink: 0; }
.app-sidebar .nav-item .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Botão de menu (hamburger) — só aparece em telas pequenas, controlado por JS */
.app-header .header-menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--fg-dim); padding: 6px; }

/* ── Tablet (<= 1024px): sidebar comprime para 72px (só ícones) ── */
@media (max-width: 1024px) and (min-width: 641px) {
  :root { --sidebar-w: 72px; }
  .app-sidebar { padding: 16px 10px; }
  .app-sidebar .sidebar-section h4 { display: none; }
  .app-sidebar .nav-item { justify-content: center; gap: 0; padding: 10px 0; }
  .app-sidebar .nav-item .nav-label { display: none; }
  .workspace-selector .ws-label,
  #btnWorkspaceSelector span,
  #sidebarListaClientes { display: none; }
  #btnWorkspaceSelector { justify-content: center; }
  .app-header .header-title { display: none; }
}

/* ── Mobile (<= 640px): sidebar vira drawer off-canvas ─── */
@media (max-width: 640px) {
  .app-main { left: 0; }
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out);
    box-shadow: var(--shadow-3);
    z-index: 60;
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  .app-header .header-menu-toggle { display: inline-flex; }
  .app-header { padding: 0 16px; }
  .app-header .header-title { display: none; }
  .section-content { padding: var(--space-5) var(--space-4); }
  /* Backdrop do drawer */
  body.sidebar-open::after {
    content: ""; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(15,23,42,.4); z-index: 55;
  }
}
