/* ============================================================
   Dashboard 3V — Grupo 3V / Cantucci
   Sistema visual alinhado a /quadro/ e /admin/: base clara,
   topbar azul, oliva como cor de ação e leitura operacional.
   ============================================================ */

:root {
  --bg: #f4f1ea;
  --surface: #fffefa;
  --surface-2: #f8f5ee;
  --surface-3: #eee7d9;
  --line: rgba(22, 58, 66, .14);
  --line-strong: rgba(22, 58, 66, .28);
  --text: #173a43;
  --muted: #637a7c;
  --faint: #8d9b9a;
  --brand-blue: #0e3a45;
  --brand-blue-2: #123f4b;
  --brand: #968b66;
  --brand-strong: #7f7554;
  --ok: #2f9d72;
  --ok-bg: rgba(47, 157, 114, .12);
  --ok-border: rgba(47, 157, 114, .28);
  --warn: #c88424;
  --warn-bg: rgba(200, 132, 36, .13);
  --warn-border: rgba(200, 132, 36, .30);
  --danger: #c84f49;
  --danger-bg: rgba(200, 79, 73, .12);
  --danger-border: rgba(200, 79, 73, .30);
  --blue: #1e6f91;
  --shadow: 0 14px 34px rgba(14, 58, 69, .10);
  --r: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(150, 139, 102, .18), transparent 34rem),
    linear-gradient(180deg, #fbfaf6 0, var(--bg) 42%);
  color: var(--text);
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; text-decoration: none; }

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 66px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-2));
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  color: white;
  box-shadow: 0 12px 32px rgba(14, 58, 69, .14);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 210px;
}

.brand strong,
.brand span:not(.mark) {
  display: block;
}

.brand strong {
  font-size: 15px;
  line-height: 1.2;
}

.brand span:not(.mark) {
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
}

.mark {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--brand-blue);
  color: #f3ead3;
  font-weight: 800;
  letter-spacing: .04em;
  flex: 0 0 auto;
}

.topbar .mark {
  background: rgba(255, 255, 255, .10);
  border-color: rgba(255, 255, 255, .28);
}

.mark.small {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  color: rgba(255, 255, 255, .68);
  background: transparent;
  padding: 12px 10px;
  white-space: nowrap;
}

.tab:hover,
.tab.active {
  color: white;
}

.tab.active {
  border-bottom-color: var(--brand);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view-controls {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.page-controls {
  width: fit-content;
  max-width: 100%;
  margin: -4px 0 20px;
  padding: 12px;
  background: rgba(255, 254, 250, .82);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(14, 58, 69, .08);
}

.button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r);
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
}

.button:hover:not(:disabled) {
  border-color: var(--line-strong);
  filter: brightness(1.03);
}

.button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

.button.primary:hover:not(:disabled) {
  background: var(--brand-strong);
}

.button.ghost {
  background: transparent;
}

.button.small {
  padding: 5px 8px;
  font-size: 12px;
  min-height: 30px;
}

.topbar .button.ghost {
  color: rgba(255, 255, 255, .88);
  border-color: rgba(255, 255, 255, .22);
}

.topbar .button.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, .10);
}

.topbar .button.danger {
  color: #ffd6d3;
}

.control {
  display: grid;
  gap: 3px;
  min-width: 118px;
}

.control span,
label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(150, 139, 102, .14);
}

.context-chip,
.period-chip,
.chip,
.pill {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.context-chip {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .24);
  color: rgba(255, 255, 255, .86);
}

.page {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.view-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin: 0 0 18px;
}

.eyebrow {
  display: block;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.view-header h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1.15;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.view-header .hint {
  max-width: 780px;
  margin: 7px 0 0;
}

.period-chip,
.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stat-card,
.card,
.mini-panel,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 17px;
  min-height: 112px;
}

.stat-value {
  display: block;
  color: var(--brand-blue);
  font-size: 28px;
  line-height: 1;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 7px;
}

.stat-card small {
  display: block;
  color: var(--faint);
  font-size: 11px;
  margin-top: 7px;
}

.stat-card.warn,
.mini-panel.warn,
.action-row.warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.stat-card.critical,
.mini-panel.critical,
.action-row.critical {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.stat-card.ok,
.mini-panel.ok,
.action-row.ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.stat-card.warn .stat-value,
.mini-panel.warn strong,
.action-row.warn b {
  color: var(--warn);
}

.stat-card.critical .stat-value,
.mini-panel.critical strong,
.action-row.critical b {
  color: var(--danger);
}

.stat-card.ok .stat-value,
.mini-panel.ok strong,
.action-row.ok b {
  color: var(--ok);
}

.stat-card small.warn { color: var(--warn); }
.stat-card small.critical { color: var(--danger); }
.stat-card small.ok { color: var(--ok); }

.chart-wrap {
  position: relative;
  height: 260px;
}

.coverage-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.coverage-bar {
  display: inline-block;
  width: 84px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.coverage-fill {
  display: block;
  height: 100%;
}

.coverage-fill.ok { background: var(--ok); }
.coverage-fill.warn { background: var(--warn); }
.coverage-fill.critical { background: var(--danger); }

.coverage-label {
  color: var(--muted);
  font-size: 12px;
}

.func-link {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--brand-blue);
  font-weight: 780;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 2px;
}

.func-link:hover {
  color: var(--brand-strong);
}

.meta-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.table-search-wrap {
  margin: 10px 0;
}

.table-search-wrap input {
  max-width: 280px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: -8px 0 20px;
  padding: 0 2px;
}

.pager span {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-form input {
  flex: 1 1 260px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 58, 69, .45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(14, 58, 69, .28);
  padding: 24px;
}

.modal-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
  padding-right: 90px;
}

.modal-card .modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.modal-card h3 {
  margin: 18px 0 8px;
  font-size: 14px;
}

.modal-chart {
  height: 200px;
  margin-top: 12px;
}

.dashboard-grid,
.attention-grid {
  display: grid;
  gap: 14px;
  margin: 16px 0;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr);
}

.attention-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-panel {
  padding: 16px;
}

.mini-panel strong {
  display: block;
  color: var(--brand-blue);
  font-size: 26px;
  line-height: 1;
}

.mini-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.card {
  padding: 16px;
  margin: 16px 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card h2,
.section-title h2 {
  margin: 0;
  font-size: 16px;
}

.stack {
  display: grid;
  gap: 8px;
}

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.action-row strong,
.action-row span {
  display: block;
}

.action-row strong {
  font-size: 14px;
}

.action-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.action-row b {
  color: var(--brand-blue);
  font-size: 13px;
  text-align: right;
}

.section-title {
  margin: 22px 0 10px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  margin: 12px 0 20px;
}

table.etl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.etl-table th,
table.etl-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.etl-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

table.etl-table td {
  color: var(--text);
}

table.etl-table td strong {
  font-weight: 780;
}

table.etl-table tr:last-child td {
  border-bottom: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  font-size: 11px;
  text-transform: uppercase;
  background: var(--surface-3);
  color: var(--text);
}

.pill.ok {
  background: var(--ok-bg);
  color: #167455;
}

.pill.critical,
.pill.error {
  background: var(--danger-bg);
  color: #9f302b;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
}

.revisar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 360px;
}

.revisar-actions select {
  min-width: 190px;
  font-size: 12px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 4px;
  text-align: center;
  padding: 48px 16px;
}

.empty-state strong {
  font-size: 18px;
}

.empty-state span {
  color: var(--muted);
  font-size: 13px;
}

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 12px;
  background: rgba(216, 154, 54, .10);
  padding: 12px 14px;
}

.error,
.error-box {
  color: var(--danger);
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(390px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 24px 70px rgba(14, 58, 69, .10);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-card .subtitle {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-card input {
  margin-top: 6px;
}

.login-card button {
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: var(--r);
  padding: 10px 12px;
  background: var(--brand);
  color: white;
  font-weight: 700;
}

.login-card button:hover {
  background: var(--brand-strong);
}

.login-card .error {
  margin: 12px 0 0;
  font-size: 13px;
}

.loading-state {
  text-align: center;
  padding: 64px 16px;
}

.loading-state p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Sub-navegação dentro de uma aba (Pessoas, Operação, Config) */
.subnav-bar {
  position: sticky;
  top: 66px;
  z-index: 9;
  background: rgba(244, 241, 234, .9);
  backdrop-filter: blur(6px);
}

.subnav-bar:empty {
  display: none;
}

.subnav {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 0 0;
}

.subtab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
}

.subtab:hover {
  border-color: var(--line-strong);
}

.subtab.active {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: #f3ead3;
}

/* Barra de ação em lote (Revisar nomes) */
.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 4px 0 14px;
  padding: 12px 16px;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 14px;
}

.bulk-bar span {
  font-size: 13px;
  color: var(--text);
}

/* Banner de confiança dos dados (Hoje) */
.data-caveat {
  margin: 12px 0 4px;
}

.data-caveat strong {
  display: block;
  color: var(--warn);
  font-size: 14px;
  margin-bottom: 3px;
}

.data-caveat span {
  display: block;
  color: var(--text);
  font-size: 13px;
}

/* Frase de leitura do período (topo da Hoje) */
.resumo-frase {
  background: var(--brand-blue);
  color: #f6efdd;
  border-radius: 16px;
  padding: 16px 20px;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  box-shadow: var(--shadow);
  margin: 0 0 4px;
}

/* Feed "Precisa de atenção" */
.alert-feed {
  display: grid;
  gap: 10px;
}

.alert-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 12px;
  background: #fbfaf6;
  padding: 13px 15px;
}

.alert-card.critical { border-left-color: var(--danger); background: var(--danger-bg); }
.alert-card.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.alert-card.ok { border-left-color: var(--ok); background: var(--ok-bg); }

.alert-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-top strong {
  font-size: 14px;
  color: var(--text);
}

.alert-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.alert-card.critical .alert-dot { background: var(--danger); }
.alert-card.warn .alert-dot { background: var(--warn); }
.alert-card.ok .alert-dot { background: var(--ok); }

.alert-detail {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.alert-acao {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .55);
  border-radius: 8px;
  padding: 8px 10px;
}

.alert-acao span {
  display: block;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-size: 10px;
  font-weight: 800;
  color: var(--brand-strong);
  margin-bottom: 2px;
}

/* Placar por loja (scorecards semáforo) */
.scorecard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  margin: 12px 0 20px;
}

.scorecard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.scorecard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.scorecard-head strong {
  font-size: 15px;
  color: var(--brand-blue);
}

.score-metrics {
  display: grid;
  gap: 6px;
}

.score-metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 13px;
}

.score-metric span { color: var(--muted); }
.score-metric b { color: var(--text); font-variant-numeric: tabular-nums; }
.score-metric .muted { color: var(--faint); font-weight: 500; }

.delta {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.delta.ok { color: var(--ok); }
.delta.warn { color: var(--warn); }

.score-metric.ok { background: var(--ok-bg); }
.score-metric.warn { background: var(--warn-bg); }
.score-metric.critical { background: var(--danger-bg); }
.score-metric.ok b { color: #167455; }
.score-metric.warn b { color: var(--warn); }
.score-metric.critical b { color: var(--danger); }

/* Tooltip "?" para termos técnicos */
.tip {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  cursor: help;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
}

.tip:hover {
  background: var(--brand);
  color: white;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  background: var(--brand-blue);
  color: #f3ead3;
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.42;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  box-shadow: 0 12px 30px rgba(14, 58, 69, .3);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
  z-index: 60;
  pointer-events: none;
}

.tip:hover::after,
.tip.open::after {
  opacity: 1;
  visibility: visible;
}

/* Perto da borda direita (últimos KPIs), ancora o balão à direita para não cortar */
.stat-grid > .stat-card:last-child .tip::after,
.stat-grid > .stat-card:nth-last-child(2) .tip::after {
  left: auto;
  right: 0;
  transform: none;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .page {
    width: min(100% - 24px, 760px);
    padding-top: 18px;
  }

  .view-header {
    flex-direction: column;
  }

  .view-header h1 {
    font-size: 24px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .attention-grid {
    grid-template-columns: 1fr;
  }

  .control {
    min-width: 128px;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 12px;
  }

  .tabs {
    margin-right: -12px;
    padding-right: 12px;
  }

  .tab {
    padding: 10px 8px;
    font-size: 13px;
  }

  .view-controls {
    width: 100%;
  }

  .control {
    flex: 1 1 130px;
  }

  #export-csv {
    flex: 1 1 140px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .stat-card {
    min-height: auto;
  }

  .revisar-actions {
    min-width: 330px;
  }
}
