/* ==========================================================================
   Atlas Tecnologia — sistema de design sobre o vocabulário do Shopify Admin
   (Polaris). Superfícies neutras, uma cor de marca (teal) reservada para a
   ação primária, tons de badge para comunicar situação. Fonte única: Inter.

   Seções: 1.Tokens 2.Base 3.Shell 4.Componentes 5.Layouts 6.Responsivo 7.Login
   ========================================================================== */

/* 1. Tokens ================================================================ */
:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Canvas e superfícies */
  --bg:            #F1F1F1;
  --surface:       #FFFFFF;
  --surface-2:     #F7F7F7;
  --border:        #E3E3E3;
  --border-2:      #EBEBEB;
  --input-border:  #8A8A8A;
  --input-border-hover: #616161;

  /* Texto */
  --text:    #303030;
  --text-2:  #616161;
  --text-3:  #B5B5B5;

  /* Ação */
  --link:    #005BD3;
  --brand:       #0A6675;
  --brand-hover: #085560;
  --brand-active:#064650;

  /* Shell */
  --topbar:      #1A1A1A;
  --topbar-field:#303030;
  --nav:         #EBEBEB;

  /* Tons — fundo / texto */
  --tone-default-bg: #E3E3E3;    --tone-default-fg: #303030;
  --tone-info-bg:     #E0F0FF;   --tone-info-fg:     #00527C;
  --tone-success-bg:  #CDFEE1;   --tone-success-fg:  #0C5132;
  --tone-attention-bg:#FFEF9D;   --tone-attention-fg:#4F4700;
  --tone-warning-bg:  #FFD79D;   --tone-warning-fg:  #5E4200;
  --tone-critical-bg: #FEDAD9;   --tone-critical-fg: #8E1F0B;

  /* Categórica — gráficos (charts.js lê via getComputedStyle) */
  --cat-1: #2E5FD1; --cat-2: #A9C3F5; --cat-3: #7B61D9;
  --cat-4: #B5B5B5; --cat-5: #29845A; --cat-6: #E51C00;

  /* Espaço — base 4px */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;

  /* Raio */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;

  /* Sombra */
  --sh-card: 0 1px 0 rgba(26, 26, 26, 0.07);
  --sh-pop:  0 4px 12px rgba(0, 0, 0, 0.12);

  /* Tipografia — um só corpo, sem escala decorativa */
  --fs-body-sm: 12px; --lh-body-sm: 16px;
  --fs-body:    13px; --lh-body:    20px;
  --fs-body-lg: 14px; --lh-body-lg: 20px;
  --fs-head-md: 16px; --lh-head-md: 24px;
  --fs-head-lg: 20px; --lh-head-lg: 24px;
  --fs-head-xl: 24px; --lh-head-xl: 28px;

  /* Alturas de controle */
  --h-btn:    28px;
  --h-btn-lg: 32px;
  --h-btn-sm: 24px;
  --h-input:  32px;
  --h-row:    44px;
  --h-thead:  36px;
  --h-nav:    32px;
  --h-topbar: 56px;

  --t: 0.15s ease;
}

/* 2. Base ================================================================== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, p { margin: 0; }

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

button, input, select, textarea { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

svg { display: block; }

/* Reafirma o comportamento nativo de [hidden] — sem isso, qualquer classe
   de autor com display próprio (ex: .alert { display: flex }) o anula. */
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 3. Shell ================================================================== */
.topbar {
  height: var(--h-topbar);
  background: var(--topbar);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 120;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: #FFFFFF;
  flex-shrink: 0;
}
.topbar-brand-mark { width: 24px; height: 24px; flex-shrink: 0; }
.topbar-brand-mark .brand-mark { width: 100%; height: 100%; display: block; }
.topbar-brand strong { font-size: var(--fs-body-lg); font-weight: 700; }
.brand-accent { color: #6FD6E3; }

.nav-toggle {
  display: none;
  background: none;
  border: 0;
  color: #FFFFFF;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle:hover { background: rgba(255, 255, 255, 0.08); }
.nav-toggle svg { width: 22px; height: 22px; }

.topbar-search { flex: 1; max-width: 560px; margin: 0 auto; position: relative; }
.topbar-search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: #8A8A8A; pointer-events: none;
}
.topbar-search input {
  width: 100%; height: var(--h-btn-lg);
  background: var(--topbar-field);
  border: 1px solid var(--topbar-field);
  border-radius: var(--r-md);
  padding: 0 var(--sp-3) 0 34px;
  color: #E3E3E3;
  font-size: var(--fs-body);
}
.topbar-search input::placeholder { color: #8A8A8A; }
.topbar-search input:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; background: #3D3D3D; }

.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

.user-menu { position: relative; }
.user-trigger {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; cursor: pointer;
  padding: 2px 6px 2px 2px; border-radius: var(--r-pill); color: #E3E3E3;
}
.user-trigger:hover { background: rgba(255, 255, 255, 0.08); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-body-sm); font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: var(--fs-body); display: none; }
@media (min-width: 640px) { .user-name { display: inline; } }

.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--sh-pop);
  min-width: 220px; padding: var(--sp-2);
  opacity: 0; pointer-events: none; transform: translateY(-4px);
  transition: opacity var(--t), transform var(--t);
  z-index: 130;
}
.user-menu.is-open .user-dropdown { opacity: 1; pointer-events: auto; transform: translateY(0); }
.user-dropdown-head { padding: var(--sp-2) var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border-2); margin-bottom: 4px; }
.user-dropdown-head strong { display: block; font-size: var(--fs-body); }
.user-dropdown-head span { font-size: var(--fs-body-sm); color: var(--text-2); }
.user-dropdown a {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2); border-radius: var(--r-sm);
  font-size: var(--fs-body); color: var(--text);
}
.user-dropdown a:hover { background: var(--surface-2); text-decoration: none; }
.user-dropdown a svg { width: 16px; height: 16px; }
.user-dropdown a.is-danger { color: var(--tone-critical-fg); }

.shell { display: flex; min-height: calc(100vh - var(--h-topbar)); position: relative; }

.nav {
  width: 240px; flex-shrink: 0;
  background: var(--nav);
  padding: var(--sp-3) var(--sp-2);
  position: sticky; top: var(--h-topbar);
  height: calc(100vh - var(--h-topbar));
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.nav-section { margin-bottom: var(--sp-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-2);
  height: var(--h-nav); padding: 0 var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--fs-body); font-weight: 500; color: #4A4A4A;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.8; }
.nav-item:hover { background: rgba(0, 0, 0, 0.05); text-decoration: none; }
.nav-item.is-active { background: #FFFFFF; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.nav-divider { height: 1px; background: rgba(0, 0, 0, 0.08); margin: var(--sp-2) var(--sp-2); }

.nav-collapsible { margin-bottom: var(--sp-1); }
.nav-collapsible summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: var(--sp-2);
  height: var(--h-nav); padding: 0 var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--fs-body); font-weight: 500; color: #4A4A4A;
}
.nav-collapsible summary::-webkit-details-marker { display: none; }
.nav-collapsible summary:hover { background: rgba(0, 0, 0, 0.05); }
.nav-collapsible summary svg:first-child { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.8; }
.nav-caret { margin-left: auto; width: 16px; height: 16px; transition: transform var(--t); flex-shrink: 0; }
.nav-collapsible[open] .nav-caret { transform: rotate(90deg); }
.nav-sub { padding-left: var(--sp-5); display: flex; flex-direction: column; gap: 1px; margin-top: 1px; }

.nav-foot { margin-top: auto; padding-top: var(--sp-2); border-top: 1px solid rgba(0, 0, 0, 0.08); }
.nav-version { font-size: 11px; color: var(--text-3); padding: 0 var(--sp-2); margin-top: var(--sp-2); }

.nav-backdrop { display: none; }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .nav {
    position: fixed; top: var(--h-topbar); left: 0; bottom: 0; width: 240px;
    transform: translateX(-100%);
    transition: transform var(--t);
    z-index: 150;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }
  .shell.nav-open .nav { transform: translateX(0); }
  .nav-backdrop {
    display: block;
    position: fixed; top: var(--h-topbar); left: 0; right: 0; bottom: 0;
    background: rgba(26, 26, 26, 0.4);
    opacity: 0; pointer-events: none;
    transition: opacity var(--t);
    z-index: 140;
  }
  .shell.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
}

.main { flex: 1; min-width: 0; background: var(--bg); }

/* 4. Componentes ============================================================ */

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-card);
  margin-bottom: var(--sp-4);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-2);
}
.card-head h2 { font-size: var(--fs-body-lg); font-weight: 600; }
.card-head-note { font-size: var(--fs-body-sm); color: var(--text-2); }
.card-body { padding: var(--sp-4); }
.card-body.is-compact { padding: var(--sp-3) var(--sp-4); }
.card-foot {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border-2);
  display: flex; justify-content: flex-end; gap: var(--sp-2);
}
.is-narrow-sm { max-width: 560px; }
.is-narrow { max-width: 560px; }
.is-narrow-md { max-width: 640px; }
.is-narrow-lg { max-width: 720px; }

/* Botões */
.btn {
  height: var(--h-btn);
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-body-sm);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(26, 26, 26, 0.05);
  transition: background var(--t), border-color var(--t);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #FFFFFF; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-active); }

.btn-plain { background: transparent; border-color: transparent; box-shadow: none; color: var(--link); }
.btn-plain:hover { background: var(--surface-2); }

.btn-critical { color: var(--tone-critical-fg); border-color: #F3C6C2; }
.btn-critical:hover { background: var(--tone-critical-bg); }

.btn-icon { width: var(--h-btn); padding: 0; }
.btn-icon.is-lg { width: var(--h-btn-lg); }

.btn.is-lg { height: var(--h-btn-lg); padding: 0 var(--sp-4); font-size: var(--fs-body); }
.btn.is-sm { height: var(--h-btn-sm); padding: 0 var(--sp-2); font-size: var(--fs-body-sm); }
.btn.is-wide { width: 100%; justify-content: center; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-body-sm);
  font-weight: 500;
  background: var(--tone-default-bg);
  color: var(--tone-default-fg);
  white-space: nowrap;
}
.badge.is-info      { background: var(--tone-info-bg);      color: var(--tone-info-fg); }
.badge.is-success    { background: var(--tone-success-bg);   color: var(--tone-success-fg); }
.badge.is-attention  { background: var(--tone-attention-bg); color: var(--tone-attention-fg); }
.badge.is-warning    { background: var(--tone-warning-bg);   color: var(--tone-warning-fg); }
.badge.is-critical   { background: var(--tone-critical-bg);  color: var(--tone-critical-fg); }
.badge svg { width: 11px; height: 11px; }

/* Índice — filtros */
.index-filters {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  flex-wrap: wrap;
}
/* Borda inferior só quando há algo depois (index-table) — como .card
   standalone (barra de filtro de relatório), .index-filters fica sem risco
   solto no rodapé. */
.index-filters:not(:last-child) { border-bottom: 1px solid var(--border-2); }
.index-tabs { display: flex; gap: 2px; margin-right: auto; flex-wrap: wrap; }
.index-tab {
  height: var(--h-btn); padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-body-sm); font-weight: 500; color: var(--text-2);
  display: inline-flex; align-items: center;
  border: 0; background: none; cursor: pointer;
}
.index-tab:hover { background: var(--surface-2); text-decoration: none; }
.index-tab.is-active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.index-search { position: relative; flex: 0 1 240px; min-width: 160px; }
.index-search svg {
  position: absolute; left: var(--sp-2); top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-2); pointer-events: none;
}
.index-search input {
  width: 100%; height: var(--h-input);
  padding: 0 var(--sp-2) 0 30px;
  border: 1px solid var(--input-border);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  background: var(--surface);
}

.index-controls { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.index-controls select, .index-controls input {
  height: var(--h-input);
  border: 1px solid var(--input-border);
  border-radius: var(--r-md);
  padding: 0 var(--sp-2);
  font-size: var(--fs-body);
  background: var(--surface);
  color: var(--text);
}
.index-controls input { width: auto; }
.index-controls label { font-size: 11px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.02em; margin-right: -4px; }

.index-dates {
  display: none; align-items: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) 0;
  flex-basis: 100%;
}
.index-dates.is-visible { display: flex; }
.index-dates label { display: block; font-size: 11px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.02em; }
.index-dates input {
  height: var(--h-input); border: 1px solid var(--input-border);
  border-radius: var(--r-md); padding: 0 var(--sp-2); font-size: var(--fs-body);
}

/* Índice — tabela */
.index-table { overflow-x: auto; }
.index-table table { width: 100%; border-collapse: collapse; }
.index-table thead th {
  height: var(--h-thead);
  padding: 0 var(--sp-4);
  text-align: left;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.index-table thead th.num { text-align: right; }
.index-table tbody tr { height: var(--h-row); border-bottom: 1px solid var(--border-2); }
.index-table tbody tr:last-child { border-bottom: 0; }
.index-table tbody tr[data-href] { cursor: pointer; }
.index-table tbody tr[data-href]:hover { background: var(--surface-2); }
.index-table td {
  padding: var(--sp-1) var(--sp-4);
  font-size: var(--fs-body);
  color: var(--text);
  vertical-align: middle;
}
.index-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.index-table td:first-child { font-weight: 500; }
.index-table td .text-2 { display: block; font-weight: 400; font-size: var(--fs-body-sm); }
.index-table a.row-link { color: inherit; display: block; }
.index-table input, .index-table select { height: var(--h-input); font-size: var(--fs-body); }

.table-scroll { overflow-x: auto; }

/* Métricas */
.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-card);
  padding: var(--sp-4);
}
.metric-label { font-size: var(--fs-body-sm); color: var(--text-2); margin-bottom: 4px; }
.metric-value { font-size: var(--fs-head-xl); font-weight: 700; line-height: var(--lh-head-xl); font-variant-numeric: tabular-nums; }
.metric-value.is-md { font-size: var(--fs-head-lg); line-height: var(--lh-head-lg); }
.metric-delta { font-size: var(--fs-body-sm); margin-top: 4px; display: flex; align-items: center; gap: 2px; color: var(--text-2); }
.metric-delta.is-positive { color: var(--tone-success-fg); }
.metric-delta.is-negative { color: var(--tone-critical-fg); }
.metric-sub { font-size: var(--fs-body-sm); color: var(--text-2); margin-top: 4px; }

/* Campos e formulário */
.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-size: var(--fs-body); font-weight: 500; color: var(--text); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; height: var(--h-input);
  padding: 0 var(--sp-2);
  border: 1px solid var(--input-border);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--t);
}
.field select { height: var(--h-input); }
.field textarea { height: auto; min-height: 80px; padding: var(--sp-2); resize: vertical; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--input-border-hover); }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 2px solid var(--link); outline-offset: 1px; border-color: var(--link);
}
.field-help { font-size: var(--fs-body-sm); color: var(--text-2); margin-top: 4px; }
.field-error { font-size: var(--fs-body-sm); color: var(--tone-critical-fg); margin-top: 4px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--tone-critical-fg); }
.field.no-mb { margin-bottom: 0; }
.required { color: var(--tone-critical-fg); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.form-row .field { margin-bottom: 0; }
.form-row.no-mb { margin-bottom: 0; }

.form-section { padding: var(--sp-4); border-top: 1px solid var(--border-2); }
.form-section:first-child { border-top: 0; }
.form-section-title { font-size: var(--fs-body-lg); font-weight: 600; margin-bottom: var(--sp-3); }

/* Grupo de checkboxes de permissão — uma linha por opção */
.field-group { display: flex; flex-direction: column; gap: var(--sp-3); }
.check-field { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--fs-body); cursor: pointer; }
.check-field input { margin-top: 3px; flex-shrink: 0; }
.check-field strong { font-weight: 600; }

/* Layout de página */
.page { max-width: 998px; margin: 0 auto; padding: var(--sp-6) var(--sp-4) var(--sp-8); }
.page.is-wide { max-width: 1200px; }

.page-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.page-head-main { flex: 1; min-width: 0; }
.page-head-titlebar { display: flex; align-items: center; gap: var(--sp-2); }
.back-btn {
  width: var(--h-btn); height: var(--h-btn); flex-shrink: 0;
  border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); background: transparent; border: 1px solid transparent;
}
.back-btn:hover { background: var(--surface-2); }
.back-btn svg { width: 16px; height: 16px; }
.page-title { font-size: var(--fs-head-lg); font-weight: 600; line-height: var(--lh-head-lg); }
.page-sub { font-size: var(--fs-body); color: var(--text-2); margin-top: 2px; }
.page-head-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

.page-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: var(--sp-4); margin-top: var(--sp-2);
}
.page-actions-right { display: flex; gap: var(--sp-2); margin-left: auto; }

.layout { display: grid; grid-template-columns: 2fr 1fr; gap: var(--sp-4); align-items: start; }
.layout-main { min-width: 0; }
.layout-side { min-width: 0; }

/* Grid de cards de largura igual — hubs de link-card, painéis recentes */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4); align-items: start; }
.grid-3 > .card { margin-bottom: 0; }

/* Estado vazio */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2); padding: var(--sp-8) var(--sp-4); text-align: center;
}
.empty-state svg { width: 32px; height: 32px; color: var(--text-3); }
.empty-state p { font-size: var(--fs-body); color: var(--text-2); }
.empty-state .btn { margin-top: var(--sp-2); }

/* Alertas */
.alert {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  margin-bottom: var(--sp-4);
}
.alert.is-info     { background: var(--tone-info-bg);     color: var(--tone-info-fg); }
.alert.is-success  { background: var(--tone-success-bg);  color: var(--tone-success-fg); }
.alert.is-warning  { background: var(--tone-warning-bg);  color: var(--tone-warning-fg); }
.alert.is-critical { background: var(--tone-critical-bg); color: var(--tone-critical-fg); }

/* Modal de confirmação */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(26, 26, 26, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t);
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-pop);
  max-width: 480px; width: 100%; max-height: 86vh;
  display: flex; flex-direction: column;
}
.modal-head { padding: var(--sp-4); border-bottom: 1px solid var(--border-2); }
.modal-head h3 { font-size: var(--fs-head-md); font-weight: 600; margin-bottom: 4px; }
.modal-head p { font-size: var(--fs-body); color: var(--text-2); }
.modal-body { padding: var(--sp-4); overflow-y: auto; }
.modal-body table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
.modal-body th, .modal-body td { text-align: left; padding: var(--sp-1) 0; }
.modal-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-2); display: flex; justify-content: flex-end; gap: var(--sp-2); }
.modal-summary { display: flex; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.modal-summary-item { flex: 1; text-align: center; padding: var(--sp-3); background: var(--surface-2); border-radius: var(--r-md); }
.modal-summary-item strong { display: block; font-size: var(--fs-head-md); }
.modal-summary-item span { font-size: var(--fs-body-sm); color: var(--text-2); }
.modal-confirm-check { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-body); margin-top: var(--sp-3); }

/* Dialog nativo (cadastro rápido) */
.dialog-modal { border: 0; border-radius: var(--r-lg); box-shadow: var(--sh-pop); padding: 0; max-width: 420px; width: 92vw; }
.dialog-modal::backdrop { background: rgba(26, 26, 26, 0.5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border-2); }
.dialog-head h3 { font-size: var(--fs-head-md); font-weight: 600; }
.dialog-close {
  width: var(--h-btn); height: var(--h-btn);
  border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); background: none; border: 0; cursor: pointer; font-size: 18px;
}
.dialog-close:hover { background: var(--surface-2); }
.dialog-body { padding: var(--sp-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-2); }

/* Toasts */
#toasts { position: fixed; top: var(--sp-4); right: var(--sp-4); z-index: 250; display: flex; flex-direction: column; gap: var(--sp-2); max-width: 360px; list-style: none; margin: 0; padding: 0; }
#toasts li {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--sh-pop);
  font-size: var(--fs-body);
  transition: opacity var(--t), transform var(--t);
}
#toasts li.success { background: var(--tone-success-bg); border-color: var(--tone-success-fg); color: var(--tone-success-fg); }
#toasts li.error   { background: var(--tone-critical-bg); border-color: var(--tone-critical-fg); color: var(--tone-critical-fg); }
#toasts li.warning { background: var(--tone-warning-bg); border-color: var(--tone-warning-fg); color: var(--tone-warning-fg); }
#toasts li.info, #toasts li.debug { background: var(--tone-info-bg); border-color: var(--tone-info-fg); color: var(--tone-info-fg); }
#toasts .toast-body { flex: 1; }
#toasts .msg-close { background: none; border: 0; cursor: pointer; font-size: 16px; line-height: 1; color: inherit; opacity: 0.6; padding: 0; }
#toasts .msg-close:hover { opacity: 1; }
#toasts li.is-leaving { opacity: 0; transform: translateX(8px); }

/* Card de link (hubs) */
.link-card { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); }
.link-card:hover { background: var(--surface-2); text-decoration: none; }
.link-card-icon {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
}
.link-card-icon svg { width: 18px; height: 18px; }
.link-card-body { flex: 1; min-width: 0; }
.link-card-title { font-size: var(--fs-body); font-weight: 600; color: var(--text); display: block; }
.link-card-desc { font-size: var(--fs-body-sm); color: var(--text-2); margin-top: 2px; display: block; }
.link-card-chevron { color: var(--text-3); flex-shrink: 0; width: 16px; height: 16px; }
.link-card.is-featured { border-color: var(--brand); }
.link-card.is-featured .link-card-icon { background: var(--tone-info-bg); color: var(--brand); }

/* Paginação */
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-2); }
.page-link { font-size: var(--fs-body); color: var(--link); padding: 4px var(--sp-2); border-radius: var(--r-sm); }
.page-link:hover { background: var(--surface-2); text-decoration: none; }
.page-link.is-disabled { color: var(--text-3); pointer-events: none; }
.page-info { font-size: var(--fs-body-sm); color: var(--text-2); }

/* Lista de definição */
.def-list { width: 100%; border-collapse: collapse; }
.def-list tr { border-bottom: 1px solid var(--border-2); }
.def-list tr:last-child { border-bottom: 0; }
.def-list th { text-align: left; font-size: var(--fs-body-sm); font-weight: 500; color: var(--text-2); padding: var(--sp-2) var(--sp-4) var(--sp-2) 0; width: 40%; vertical-align: top; }
.def-list td { font-size: var(--fs-body); color: var(--text); padding: var(--sp-2) 0; vertical-align: top; }
.def-list td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Gráfico */
.chart-box { position: relative; height: 280px; }
.chart-box.is-sm { height: 200px; }

/* Spinner */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.15); border-top-color: var(--text);
  border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}
.btn-primary .spinner { border-color: rgba(255, 255, 255, 0.35); border-top-color: #FFFFFF; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabela de itens de formset (Nova Saída, NF manual) — linhas dinâmicas
   dentro de .index-table, controladas por window.AtlasFormset (app.js). */
.item-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border-2);
  font-size: var(--fs-body-sm); color: var(--text-2);
}
.btn-remove-row {
  width: 24px; height: 24px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-remove-row:hover { background: var(--tone-critical-bg); color: var(--tone-critical-fg); border-color: var(--tone-critical-bg); }
.saldo-badge {
  display: inline-flex; align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-body-sm); font-weight: 500;
  background: var(--surface-2); color: var(--text-2);
  white-space: nowrap;
}
/* Nova Saída — linha de item compacta: nunca estoura a largura do card */
.is-saida-itens table { table-layout: fixed; }
.is-saida-itens col.col-num { width: 40px; }
.is-saida-itens col.col-saldo { width: 130px; }
.is-saida-itens col.col-qtd { width: 120px; }
.is-saida-itens col.col-del { width: 44px; }
.is-saida-itens td, .is-saida-itens th { padding-left: var(--sp-2); padding-right: var(--sp-2); }
.is-saida-itens select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.is-saida-itens input[type="number"] { width: 100%; text-align: right; font-variant-numeric: tabular-nums; }
.is-saida-itens .saldo-badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.is-saida-itens input.is-over { border-color: var(--tone-critical-fg); }
@media screen and (max-width: 640px) {
  .is-saida-itens colgroup, .is-saida-itens thead { display: none; }
  .is-saida-itens table, .is-saida-itens tbody { display: block; }
  .is-saida-itens tr.item-row {
    display: grid; grid-template-columns: 28px 1fr 110px 32px; align-items: center;
    height: auto; padding: var(--sp-2); gap: var(--sp-1) var(--sp-2);
  }
  .is-saida-itens tr.item-row[style*="display: none"] { display: none; }
  .is-saida-itens tr.item-row td { padding: 0; }
  .is-saida-itens tr.item-row td:nth-child(2) { grid-column: 2 / -1; }
  .is-saida-itens tr.item-row td:nth-child(3) { grid-column: 2; }
}

.linha-total { font-size: var(--fs-body); font-variant-numeric: tabular-nums; white-space: nowrap; }
.produto-field-row { display: flex; gap: var(--sp-2); align-items: center; }
.produto-field-row select { flex: 1; min-width: 140px; }
.btn-novo-produto {
  width: 24px; height: 24px; border-radius: var(--r-sm);
  border: 1px solid var(--input-border); background: var(--surface);
  color: var(--text-2); cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-novo-produto:hover { background: var(--surface-2); color: var(--link); border-color: var(--link); }

/* Utilitários — só o essencial; layout vem do componente, não de utilitário */
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-2 { color: var(--text-2); }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mt-4 { margin-top: var(--sp-4); }
.is-centered { align-items: center; }
.w-30pct { width: 30%; }

/* Card com aviso lateral — alerta de preço em alta, etc. */
.card-alert { border-left: 4px solid var(--tone-critical-fg); }
.card-alert .card-body { display: flex; align-items: center; gap: var(--sp-3); }

/* Linha "barra de % + rótulo" — tabelas de gasto por fornecedor/categoria */
.pct-row { display: flex; align-items: center; gap: var(--sp-2); }
.pct-row .barra-pct { flex: 1; height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.pct-row .barra-pct-fill { display: block; height: 100%; width: var(--pct, 0%); background: var(--barra-cor, var(--brand)); border-radius: var(--r-pill); }
.pct-row .pct-label { font-size: var(--fs-body-sm); color: var(--text-2); width: 40px; text-align: right; flex-shrink: 0; }
.row-total td { font-weight: 600; border-top: 2px solid var(--border); }

/* Relatórios — tabela com total, referência de período, matriz e cabeçalho
   de documento (estoque/relatorios/). Uma só anatomia para tela/impressão/
   PDF/Excel: ver templates/app/relatorios/_report_*.html. */
.index-table tfoot td {
  font-weight: 600;
  border-top: 2px solid var(--border);
  background: var(--surface-2);
}
.index-table tr.subtotal-row td { background: var(--surface-2); font-weight: 500; }
.index-table tr.grupo-row td { padding-top: var(--sp-3); font-weight: 600; color: var(--text-2); font-size: var(--fs-body-sm); text-transform: uppercase; letter-spacing: 0.02em; border-bottom: 0; }

.metric-ref { font-size: var(--fs-body-sm); color: var(--text-2); margin-top: var(--sp-1); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.metric-ref .delta { font-weight: 600; }
.delta.is-better { color: var(--tone-success-fg); }
.delta.is-worse { color: var(--tone-critical-fg); }
.delta.is-neutral { color: var(--text-2); }
.index-table td .delta { font-weight: 500; }

.report-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
summary.card-head.is-clickable { cursor: pointer; list-style: none; }
summary.card-head.is-clickable::-webkit-details-marker { display: none; }

.report-doc {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-size: var(--fs-body-sm);
}
.report-doc-empresa strong { display: block; font-size: var(--fs-body); color: var(--text); }
.report-doc-empresa span { color: var(--text-2); }
.report-doc dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px var(--sp-2); }
.report-doc dt { color: var(--text-2); }
.report-doc dd { margin: 0; color: var(--text); }
.report-doc-pergunta { color: var(--text-2); font-style: italic; margin-top: 2px; }

.matrix-table { overflow-x: auto; }
.matrix-table table { border-collapse: collapse; }
.matrix-table th, .matrix-table td { white-space: nowrap; }
.matrix-table th:first-child, .matrix-table td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}
.matrix-table thead th:first-child { background: var(--surface-2); z-index: 2; }
.matrix-table td.heat { background: color-mix(in srgb, var(--cat-1) calc(var(--heat, 0) * 45%), transparent); }
.matrix-table .heat-1 { background: color-mix(in srgb, var(--cat-1) 12%, transparent); }
.matrix-table .heat-2 { background: color-mix(in srgb, var(--cat-1) 24%, transparent); }
.matrix-table .heat-3 { background: color-mix(in srgb, var(--cat-1) 36%, transparent); }
.matrix-table .heat-4 { background: color-mix(in srgb, var(--cat-1) 48%, transparent); }
.matrix-table .heat-5 { background: color-mix(in srgb, var(--cat-1) 60%, transparent); }

/* Lista de alertas — dashboard gerencial */
.alerta-lista { display: flex; flex-direction: column; gap: var(--sp-2); }
.alerta-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2);
}
.alerta-item.is-critico { background: var(--tone-critical-bg); }
.alerta-item.is-atencao { background: var(--tone-attention-bg); }
.alerta-item-title { font-weight: 600; font-size: var(--fs-body); margin-bottom: 2px; }
.alerta-item-msg { font-size: var(--fs-body-sm); color: var(--text-2); }
.alerta-item.is-critico .alerta-item-title, .alerta-item.is-critico .alerta-item-msg { color: var(--tone-critical-fg); }
.alerta-item.is-atencao .alerta-item-title, .alerta-item.is-atencao .alerta-item-msg { color: var(--tone-attention-fg); }
.alerta-item-acao { font-size: var(--fs-body-sm); font-weight: 600; color: var(--link); white-space: nowrap; }

/* 5. Responsivo ============================================================= */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page { padding: var(--sp-4) var(--sp-3) var(--sp-6); }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .report-doc { grid-template-columns: 1fr; }
}

@media screen and (max-width: 640px) {
  .metric-row { grid-template-columns: 1fr; }
  .index-filters { align-items: stretch; }
  .index-search { flex: 1 1 auto; }
  .page-head { flex-wrap: wrap; }
  .page-head-actions { width: 100%; }
  .topbar-search { max-width: none; }
  .user-name { display: none; }
  /* Listagens empilham em cards; as tabelas de formset (Nova Saída, NF
     manual) e a matriz posto x mês mantêm linha+cabeçalho normais com
     rolagem horizontal — a matriz é uma grade densa, empilhar destruiria
     a leitura de "qual mês, qual posto". */
  .index-table:not(.is-formset):not(.matrix-table) thead { display: none; }
  .index-table:not(.is-formset):not(.matrix-table) tbody tr { height: auto; display: flex; flex-direction: column; padding: var(--sp-3) var(--sp-4); gap: 2px; }
  .index-table:not(.is-formset):not(.matrix-table) td { padding: 0; }
  .index-table:not(.is-formset):not(.matrix-table) td.num { text-align: left; }
}

/* Impressão — cada relatório é o mesmo documento em tela e em papel: some
   navegação/filtro/ação, mantém .report-doc como cabeçalho da folha,
   repete thead a cada página, não quebra linha no meio. */
@page { size: A4; margin: 12mm; }
@media print {
  .topbar, .nav, .nav-backdrop, .index-filters, .page-head-actions,
  .report-actions, .back-btn, #toasts, .link-card, .pagination,
  .nav-toggle { display: none !important; }
  .shell { display: block; }
  .main { background: #fff; }
  .page, .page.is-wide { max-width: none; padding: 0; margin: 0; }
  .card, .metric { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  .report-doc { border: 0; border-bottom: 1px solid #bbb; border-radius: 0; page-break-after: avoid; }
  .index-table { overflow: visible; }
  .index-table table { font-size: 11px; }
  .index-table thead { display: table-header-group; }
  .index-table tfoot { display: table-row-group; }
  .index-table tbody tr, .matrix-table tbody tr { break-inside: avoid; }
  .matrix-table th:first-child, .matrix-table td:first-child { position: static; box-shadow: none; }
  .chart-box { height: 220px; }
  a[href]::after { content: ""; }
}

/* 6. Login =================================================================== */
.login-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: var(--sp-4);
}
.login-card {
  width: 360px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-card);
  padding: var(--sp-7);
}
.login-brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.login-brand .app-brand-mark { width: 32px; height: 32px; flex-shrink: 0; display: block; }
.login-brand strong { font-size: var(--fs-head-md); font-weight: 700; color: var(--text); display: block; }
.login-brand span:last-child { font-size: var(--fs-body-sm); color: var(--text-2); }
.login-card h1 { font-size: var(--fs-head-lg); font-weight: 600; margin-bottom: 4px; }
.login-card .sub { font-size: var(--fs-body); color: var(--text-2); margin-bottom: var(--sp-5); }
.login-err { background: var(--tone-critical-bg); color: var(--tone-critical-fg); padding: var(--sp-3); border-radius: var(--r-md); font-size: var(--fs-body); margin-bottom: var(--sp-4); }
.login-card .btn { width: 100%; height: var(--h-btn-lg); font-size: var(--fs-body); margin-top: var(--sp-1); }
.login-foot { margin-top: var(--sp-5); text-align: center; font-size: var(--fs-body-sm); color: var(--text-2); }
