:root {
  --fundo: #f5f6f8;
  --superficie: #ffffff;
  --superficie-2: #f0f2f5;
  --borda: #e2e5ea;
  --texto: #1b1f24;
  --texto-2: #5c6470;
  --primaria: #2563eb;
  --primaria-texto: #ffffff;
  --perigo: #dc2626;
  --ok: #15803d;
  --aviso: #b45309;
  --serie-1: #2563eb;
  --serie-2: #f97316;
  --serie-3: #16a34a;
  --serie-4: #9333ea;
  --serie-5: #0891b2;
  --serie-6: #db2777;
  --serie-7: #ca8a04;
  --serie-8: #64748b;
  --raio: 12px;
  --sombra: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0f1115;
    --superficie: #181b21;
    --superficie-2: #20242c;
    --borda: #2c313a;
    --texto: #e8eaed;
    --texto-2: #9aa3af;
    --primaria: #3b82f6;
    --perigo: #f87171;
    --ok: #4ade80;
    --aviso: #fbbf24;
    --serie-1: #60a5fa;
    --serie-2: #fb923c;
    --serie-3: #4ade80;
    --serie-4: #c084fc;
    --serie-5: #22d3ee;
    --serie-6: #f472b6;
    --serie-7: #facc15;
    --serie-8: #94a3b8;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1rem; }
.muted { color: var(--texto-2); }
.pequeno { font-size: 0.82rem; }
.centro { text-align: center; }
[hidden] { display: none !important; }

/* ---------- Formulários e botões ---------- */
input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaria); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--texto-2); }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--texto); }
label.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 500; font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--borda);
  background: var(--superficie);
  color: var(--texto);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--superficie-2); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--primaria); border-color: var(--primaria); color: var(--primaria-texto); }
.btn-primary:hover { background: var(--primaria); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-perigo { color: var(--perigo); border-color: color-mix(in srgb, var(--perigo) 40%, var(--borda)); }
.btn-block { width: 100%; }
.btn-pequeno { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-icone { background: none; border: 0; cursor: pointer; padding: 0.25rem; border-radius: 6px; font-size: 0.95rem; }
.btn-icone:hover { background: var(--superficie-2); }
.chip {
  border: 1px solid var(--borda); background: var(--superficie-2); color: var(--texto);
  border-radius: 999px; padding: 0.1rem 0.55rem; font: inherit; font-size: 0.8rem; cursor: pointer;
}
.tag {
  display: inline-block; font-size: 0.72rem; padding: 0.05rem 0.45rem; border-radius: 999px;
  background: var(--superficie-2); color: var(--texto-2); border: 1px solid var(--borda);
}
.erro { color: var(--perigo); font-size: 0.88rem; margin: 0; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--superficie); border: 1px solid var(--borda); border-radius: 16px;
  padding: 2rem; box-shadow: var(--sombra);
}
.login-card form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1.5rem; }
.login-card form label { margin-bottom: -0.3rem; }
.login-card button { margin-top: 0.6rem; }
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand h1 { margin: 0; font-size: 1.5rem; }
.brand-icon { font-size: 1.5rem; }

/* ---------- Layout do painel ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 1.25rem;
  background: var(--superficie); border-bottom: 1px solid var(--borda);
}
.tabs { display: flex; gap: 0.25rem; overflow-x: auto; }
.tab {
  font: inherit; font-size: 0.9rem; background: none; border: 0; color: var(--texto-2);
  padding: 0.45rem 0.8rem; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--superficie-2); }
.tab.ativo { background: var(--superficie-2); color: var(--texto); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.topbar-right select { width: auto; padding: 0.4rem 0.6rem; }

.container { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.tab-pane { display: none; }
.tab-pane.ativo { display: block; }

.card {
  background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio);
  padding: 1rem 1.1rem; box-shadow: var(--sombra); min-width: 0;
}
.card h3 { color: var(--texto-2); font-weight: 600; font-size: 0.9rem; }

.vazio { text-align: center; padding: 3rem 1rem; }
.acoes { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; align-items: center; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.kpi {
  background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio);
  padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; box-shadow: var(--sombra);
}
.kpi-rotulo { font-size: 0.8rem; color: var(--texto-2); }
.kpi-valor { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.78rem; color: var(--texto-2); }

/* Alertas */
.alertas { margin-bottom: 1rem; }
.alertas h3 { font-size: 0.9rem; color: var(--texto-2); }
.alertas-lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.6rem; }
.alerta {
  display: flex; flex-direction: column; gap: 0.1rem;
  background: var(--superficie); border: 1px solid var(--borda); border-left: 4px solid var(--ok);
  border-radius: 10px; padding: 0.6rem 0.8rem;
}
.alerta.proxima { border-left-color: var(--aviso); }
.alerta.vencida { border-left-color: var(--perigo); }
.alerta-status { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ok); }
.alerta.proxima .alerta-status { color: var(--aviso); }
.alerta.vencida .alerta-status { color: var(--perigo); }

/* Gráficos */
.grid-graficos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.card-largo { grid-column: 1 / -1; }
.grafico { position: relative; height: 260px; }
.card-largo .grafico { height: 300px; }

/* Tabelas */
.secao-topo { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.secao-topo h2 { margin: 0; }
.secao-topo input[type="search"] { width: 260px; max-width: 100%; }
.tabela-wrap { overflow-x: auto; background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); }
.tabela { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tabela th, .tabela td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--borda); white-space: nowrap; }
.tabela td:nth-child(4) { white-space: normal; }
.tabela th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--texto-2); font-weight: 600; background: var(--superficie-2); }
.tabela tbody tr:last-child td { border-bottom: 0; }
.tabela tbody tr:hover { background: var(--superficie-2); }
.tabela .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela.compacta th, .tabela.compacta td { padding: 0.45rem 0.4rem; background: none; }
.acoes-linha { text-align: right; }

/* Aba dados */
.cards-dados { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.75rem; margin-top: 1rem; }
.pilha { display: flex; flex-direction: column; gap: 0.5rem; }
.linha { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.perigo h3 { color: var(--perigo); }

/* Modais */
.modal {
  border: 1px solid var(--borda); border-radius: 16px; padding: 1.4rem;
  background: var(--superficie); color: var(--texto);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
.modal::backdrop { background: rgba(10, 12, 16, 0.55); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.span2 { grid-column: 1 / -1; }
.form-acoes { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

/* Anexos */
.anexos { border: 1px dashed var(--borda); border-radius: 10px; padding: 0.7rem; }
.anexos-topo { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--texto-2); margin-bottom: 0.5rem; }
.anexos-topo label { flex-direction: row; color: var(--texto); }
.miniaturas { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.miniaturas p { margin: 0; }
.miniatura {
  position: relative; width: 76px; height: 76px; padding: 0; border: 1px solid var(--borda);
  border-radius: 8px; overflow: hidden; cursor: zoom-in; background: var(--superficie-2);
}
.miniatura img { width: 100%; height: 100%; object-fit: cover; display: block; }
.miniatura .selo {
  position: absolute; right: 3px; bottom: 3px; background: var(--primaria); color: #fff;
  font-size: 0.65rem; font-weight: 700; border-radius: 4px; padding: 0 4px;
}

.modal-foto { width: min(1100px, calc(100vw - 32px)); padding: 1rem; }
.foto-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; }
.foto-img { background: var(--superficie-2); border-radius: 10px; display: grid; place-items: center; overflow: auto; max-height: calc(100vh - 80px); }
.foto-img img { max-width: 100%; max-height: calc(100vh - 80px); display: block; }
.foto-lado { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.foto-lado h3 { word-break: break-all; }
.foto-lado label { margin-bottom: -0.3rem; }
.progresso { height: 6px; background: var(--superficie-2); border-radius: 99px; overflow: hidden; }
.progresso div { height: 100%; width: 0; background: var(--primaria); transition: width 0.2s; }
.campos-achados { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100;
  background: var(--texto); color: var(--fundo); padding: 0.6rem 1rem; border-radius: 10px;
  font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  .topbar { padding: 0.6rem 16px; gap: 0.5rem; }
  .tabs { order: 3; width: 100%; }
  .container { padding: 1rem 16px; }
  .grid-graficos { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-valor { font-size: 1.2rem; }
  .form-grid { grid-template-columns: 1fr; }
  .foto-layout { grid-template-columns: 1fr; }
  .foto-img, .foto-img img { max-height: 50vh; }
  .secao-topo input[type="search"] { width: 100%; }
  .secao-topo .acoes { width: 100%; flex-wrap: nowrap; }
  #nomeUsuario { display: none; }
}

.rolagem-x { overflow-x: auto; }
.tabs { min-width: 0; max-width: 100%; }
.card-veiculo { grid-column: 1 / -1; }
.form-veiculo { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
#veiculoResumo { margin-left: 0.3rem; }
@media (max-width: 760px) { #veiculoResumo { display: none; } }
