/* ============================================================
   SOLARYZ — base.css
   Tokens, reset, tipografia, componentes compartilhados.
   Escala de espaçamento: 4 8 12 16 24 32 48 64
   ============================================================ */

:root {
  /* ---------- Identidade configurável da empresa ---------- */
  --tenant-primary: #185abd;
  --tenant-primary-hover: #124a9a;
  --tenant-primary-contrast: #ffffff;
  --tenant-primary-hover-contrast: #ffffff;
  --tenant-primary-on-shell: #9cc4ff;
  --tenant-secondary: #11468a;
  --tenant-secondary-hover: #0d376d;
  --tenant-secondary-contrast: #ffffff;
  --tenant-secondary-readable: #11468a;
  --tenant-secondary-on-shell: #9cc4ff;
  --tenant-shell: #0c2345;
  --tenant-shell-secondary: #0b1d38;
  --tenant-shell-contrast: #ffffff;
  --tenant-shell-muted: #d5e4f8;
  --tenant-shell-warn: #ffd69c;
  --tenant-shell-ok: #9eebc5;
  --tenant-shell-danger: #ffd0c8;

  /* ---------- Marca: azul SOLARYZ para ações e navegação ---------- */
  --brand-700: #11468a;
  --brand-600: #185abd;
  --brand-500: #2876d8;
  --brand-100: #edf4ff;

  /* ---------- Neutros: contraste e superfícies da interface ---------- */
  --ink-900: #152641;
  --ink-800: #223650;
  --ink-700: #3d4d64;
  --ink-600: #53647b;
  --ink-500: #65758b;
  --ink-400: #7a899c;
  --ink-300: #a7b3c4;
  --line: #e4eaf2;
  --line-strong: #ccd6e4;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #edf1f7;

  /* ---------- Semânticas ----------
     Cada uma tem cor de texto e cor de fundo próprias: a cor nunca
     é o único sinal (sempre vem com ícone ou texto junto). */
  --ok: #0e6b50;
  --ok-bg: #e4f2ec;
  --warn: #8a5a10;
  --warn-bg: #fbf1e0;
  --danger: #a32f22;
  --danger-bg: #fbeae8;
  --info: #24567f;
  --info-bg: #e8f0f7;

  /* ---------- Sombra ----------
     Muito discretas: profundidade vem da borda, não da sombra. */
  --shadow-xs: 0 1px 2px rgba(16, 24, 21, .04);
  --shadow-sm: 0 1px 3px rgba(16, 24, 21, .06), 0 1px 2px rgba(16, 24, 21, .04);
  --shadow-md: 0 4px 12px rgba(16, 24, 21, .07), 0 1px 3px rgba(16, 24, 21, .05);
  --shadow-lg: 0 16px 48px rgba(16, 24, 21, .14), 0 4px 12px rgba(16, 24, 21, .07);

  /* ---------- Raios ---------- */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;

  /* ---------- Layout ---------- */
  --sidebar-w: 252px;
  --topbar-h: 76px;
  --page-max: 1360px;

  /* ---------- Tipografia ----------
     Duas famílias: uma para interface, uma para números.
     Números tabulares evitam o “pulo” quando o valor atualiza. */
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-num: "Inter", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  /* ---------- Movimento ---------- */
  --t-fast: 130ms cubic-bezier(.4, 0, .2, 1);
  --t-base: 180ms cubic-bezier(.4, 0, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-700);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

h1, h2, h3, h4 {
  margin: 0;
  color: var(--ink-900);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.015em;
}
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }

p { margin: 0; max-width: 65ch; }

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

button, input, select, textarea { font: inherit; color: inherit; }

img, svg { display: block; max-width: 100%; }

/* Foco visível — nunca remover sem substituto */
:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Números sempre tabulares: evitam o "pulo" quando o valor atualiza */
.num, .value, .metric .v, .item .v, table.data td.num, .mono, .kpi .value {
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--brand-100); }

/* ---------- Utilitários ---------- */
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.gap-16 { gap: 16px; } .gap-24 { gap: 24px; } .gap-32 { gap: 32px; }
.grow { flex: 1; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--ink-500); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Botões ----------
   Altura 36px: denso o bastante para caber uma barra de ferramentas
   sem apertar, e ainda confortável ao toque. */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--surface); color: var(--ink-700);
  font-size: 13.5px; font-weight: 550; letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(.5px); }

.btn-primary { background: var(--tenant-primary, var(--brand-600)); color: var(--tenant-primary-contrast, var(--brand-contrast, #fff)); box-shadow: var(--shadow-xs); }
.btn-primary:hover:not(:disabled) { background: var(--tenant-primary-hover, var(--brand-700)); color: var(--tenant-primary-hover-contrast, var(--tenant-primary-contrast, var(--brand-contrast, #fff))); text-decoration: none; }

.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink-700); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-300); text-decoration: none; }

.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-500); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--ink-900); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8c281d; text-decoration: none; }

.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; gap: 6px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn-icon.btn-sm { width: 30px; height: 30px; }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label {
  font-size: 12.5px; font-weight: 550; color: var(--ink-600);
  letter-spacing: -0.005em;
}
.field .hint { font-size: 11.5px; color: var(--ink-400); line-height: 1.4; }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink-900);
  font-size: 13.5px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2366736d' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.textarea { height: auto; padding: 9px 11px; min-height: 84px; resize: vertical; line-height: 1.5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }
input[type="checkbox"] { accent-color: var(--brand-600); }
.input:disabled { background: var(--surface-3); color: var(--ink-400); }
.input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- Cartões ----------
   A borda faz o trabalho da sombra: superfícies planas e nítidas,
   que é o que se espera de ferramenta de operação. */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  min-height: 52px;
}
.card-head h3 { letter-spacing: -0.01em; }
.card-body { padding: 20px; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; letter-spacing: .005em;
  background: var(--surface-3); color: var(--ink-600);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--surface-3); color: var(--ink-600); }

/* ---------- Tabela ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-500);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface-2);
}
table.data td {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  vertical-align: middle; color: var(--ink-700);
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td .title-cell { font-weight: 550; color: var(--ink-900); }

/* ---------- Barra de progresso ---------- */
.bar { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: var(--r-full); background: var(--brand-500); transition: width var(--t-base); }
.bar.is-warn > span { background: var(--warn); }
.bar.is-danger > span { background: var(--danger); }

/* ---------- Estado vazio / carregando / erro ---------- */
.state {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 56px 24px; text-align: center; color: var(--ink-500);
}
.state h3 { color: var(--ink-800); }
.state p { font-size: 13.5px; max-width: 42ch; }
.state .state-icon {
  width: 44px; height: 44px; border-radius: var(--r-full);
  display: grid; place-items: center; background: var(--surface-3); color: var(--ink-400);
  margin-bottom: 4px;
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, #e6ebe9 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: sk 1.2s ease-in-out infinite;
  border-radius: var(--r-sm); height: 16px;
}
@keyframes sk { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(16, 24, 21, .5);
  backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 24px;
  animation: fade 200ms ease-out;
}
.modal {
  width: min(640px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg); border: 1px solid var(--line);
  animation: rise 240ms cubic-bezier(.16, 1, .3, 1);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
}
.modal-body { padding: 24px; }
.modal-foot {
  display: flex; justify-content: flex-end; align-items: center; gap: 8px;
  padding: 16px 24px; border-top: 1px solid var(--line);
  position: sticky; bottom: 0; background: var(--surface-2);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(.995) } to { opacity: 1; transform: none } }

/* ---------- Toast ---------- */
.toasts {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 380px;
  padding: 11px 15px; border-radius: var(--r-md);
  background: var(--ink-900); color: #fff; box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 500;
  animation: rise 240ms cubic-bezier(.16, 1, .3, 1);
  transition: opacity 200ms ease-in;
}
.toast svg { flex: none; opacity: .9; }
.toast.is-ok { background: var(--brand-700); }
.toast.is-error { background: #8c281d; }

/* ---------- Grids responsivos ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 21px; }
  h2 { font-size: 18px; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; min-width: 0; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .modal-head { border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .modal-foot { border-radius: 0; }
}

/* 320px — o menor alvo real */
@media (max-width: 400px) {
  .card-pad, .card-body { padding: 16px; }
  .card-head { padding: 12px 16px; }
  .btn { padding: 0 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
