/* ====== Automa EcoRota - tema escuro (identidade Automa) ====== */
:root {
  --automa-bg: #050b2a;     /* fundo principal Automa */
  --panel: #0a1642;         /* painéis/cards Automa */
  --panel-2: #0e1c52;       /* hover / destaque */
  --accent: #ffffff;        /* branco alto brilho */
  --accent-2: #e6ecff;
  --on-accent: #0a1642;     /* texto sobre fundo accent (branco) */
  --blue: #4a90e2;
  --bg: var(--automa-bg);
  --card: var(--panel);
  --ink: #eaf0ff;
  --muted: #9aa6c8;
  --line: #1c2a59;
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 12px 30px rgba(0, 0, 0, .35);
  --radius: 16px;

  --op-E: #22c55e;
  --op-D: #38bdf8;
  --op-B: #f43f5e;
  --op-M: #f59e0b;
  --op-x: #94a3b8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand img { height: 22px; display: block; }
.brand .sep { width: 1px; height: 20px; background: rgba(255,255,255,.2); }
.brand .sub {
  color: #ffffff; font-weight: 800; font-size: 15px; letter-spacing: .8px;
  text-shadow: 0 0 10px rgba(255,255,255,.55), 0 0 22px rgba(130,175,255,.35);
}
.nav { display: flex; gap: 6px; margin-left: 8px; }
.nav a {
  color: var(--muted); text-decoration: none;
  padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: var(--on-accent); }
.topbar .spacer { flex: 1; }
.topbar .live {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  background: rgba(255, 255, 255, .05); padding: 6px 14px; border-radius: 999px;
}
.ver-chip { font-size: 11px; color: var(--muted); background: rgba(255,255,255,.06); border: 1px solid var(--line); padding: 4px 9px; border-radius: 999px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--op-E); }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---- Layout ---- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.card h2 { margin: 0 0 18px; font-size: 15px; font-weight: 700; }
.card + .card { margin-top: 22px; }

/* ---- Stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden;
}
.tile .v { font-size: 30px; font-weight: 800; line-height: 1; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 8px; font-weight: 600; }
.tile .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--accent); }
.tile.E .bar { background: var(--op-E); } .tile.E .v { color: var(--op-E); }
.tile.D .bar { background: var(--op-D); } .tile.D .v { color: var(--op-D); }
.tile.B .bar { background: var(--op-B); } .tile.B .v { color: var(--op-B); }
.tile.M .bar { background: var(--op-M); } .tile.M .v { color: var(--op-M); }

/* ---- Map ---- */
#map { height: 460px; width: 100%; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--ink); }
.veh-pin { background: transparent; border: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); }

/* ---- Empresa (grupo) ---- */
.empresa { margin-bottom: 22px; }
.empresa-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
.empresa-head .ico { width: 34px; height: 34px; border-radius: 9px; background: rgba(255,255,255,.1); color: var(--accent); display: grid; place-items: center; font-size: 16px; }
.empresa-head .nm { font-weight: 800; font-size: 15px; }
.empresa-head .cnpj { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.empresa-head .count { margin-left: auto; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 999px; }

/* ---- Vehicle grid ---- */
.veh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.veh {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 16px; cursor: pointer; transition: transform .12s, border-color .12s;
}
.veh:hover { transform: translateY(-2px); border-color: var(--accent); }
.veh .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.veh .placa { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.veh .meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.veh .meta b { color: var(--ink); font-weight: 600; }

/* ---- Badge de operacao ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #04122a;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: rgba(4,18,42,.55); }
.badge.E { background: var(--op-E); } .badge.D { background: var(--op-D); }
.badge.B { background: var(--op-B); color: #fff; } .badge.M { background: var(--op-M); }
.badge.x { background: var(--op-x); }
.badge.B::before { background: rgba(255,255,255,.6); }

/* ---- Form / config ---- */
.row { display: flex; flex-wrap: wrap; gap: 26px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=number], input[type=datetime-local], input[type=text], input[type=password] {
  background: #07103a; color: var(--ink); width: 140px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}
input::placeholder { color: #5b6a96; }
select { background: #07103a; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; cursor: pointer; }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
button {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px;
  padding: 11px 20px; font-size: 14px; font-weight: 600; cursor: pointer; transition: filter .15s;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button:disabled { opacity: .5; cursor: default; }

/* ---- Switch ---- */
.switch { position: relative; display: inline-block; width: 56px; height: 30px; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #243156; border-radius: 30px; transition: .2s; }
.slider:before { content: ""; position: absolute; height: 24px; width: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
input:checked + .slider { background: var(--op-E); }
input:checked + .slider:before { transform: translateX(26px); }

.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.on { background: rgba(34,197,94,.18); color: #4ade80; }
.pill.off { background: rgba(244,63,94,.18); color: #fb7185; }

.alert { padding: 12px 16px; border-radius: 12px; font-size: 13px; margin-top: 16px; }
.alert.warn { background: rgba(245,158,11,.12); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }
.alert.info { background: rgba(74,144,226,.12); color: #93c5fd; border: 1px solid rgba(74,144,226,.3); }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: rgba(255,255,255,.03); }
.tag { font-size: 11px; padding: 3px 10px; border-radius: 999px; font-weight: 700; }
.tag.sent { background: rgba(34,197,94,.18); color: #4ade80; }
.tag.dry-run { background: rgba(245,158,11,.18); color: #fcd34d; }
.tag.skipped { background: rgba(148,163,184,.18); color: #cbd5e1; }
.tag.error { background: rgba(244,63,94,.18); color: #fb7185; }

.muted { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 14px; }

#toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--accent); color: var(--on-accent);
  padding: 12px 18px; border-radius: 12px; opacity: 0; transform: translateY(8px);
  transition: .25s; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 2000;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ---- Sinotico do caminhao ---- */
.synoptic { width: 100%; height: auto; display: block; background: #07103a; border: 1px solid var(--line); border-radius: 12px; padding: 6px; margin: 4px 0 12px; }
.syn-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 11px; color: var(--muted); margin: -4px 0 10px; }
.syn-legend span { display: inline-flex; align-items: center; gap: 5px; }
.syn-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---- Rodape do card: manutencao forcada ---- */
.veh-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.veh-foot .lbl { font-size: 12px; font-weight: 700; color: var(--muted); }
.veh-foot .lbl.on { color: var(--op-M); }
.switch.sm { width: 44px; height: 24px; }
.switch.sm .slider:before { height: 18px; width: 18px; }
.switch.sm input:checked + .slider:before { transform: translateX(20px); }
.switch.sm input:checked + .slider { background: var(--op-M); }

/* ---- Modal de aviso ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(2, 6, 23, .7); display: none; align-items: center; justify-content: center; z-index: 3000; padding: 20px; }
.modal-overlay.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; max-width: 540px; width: 100%; padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal h3 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 10px; color: var(--op-M); }
.modal p { margin: 0 0 12px; font-size: 14px; line-height: 1.6; color: var(--ink); }
.modal .disclaimer { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); border-radius: 12px; padding: 14px 16px; color: #fcd34d; font-size: 13.5px; }
.modal .placa-ref { font-weight: 800; color: #fff; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal .actions button.warn { background: var(--op-M); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 460px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px; }
.login-card .field label { font-size: 15px; }
.login-card input { font-size: 17px; padding: 13px 14px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-brand img { height: 22px; }
.login-brand .sub { color: #ffffff; font-weight: 800; letter-spacing: .8px; text-shadow: 0 0 10px rgba(255,255,255,.5); }
.login-card h1 { font-size: 20px; margin: 0 0 20px; }
/* inputs brancos no login para leitura fácil da senha */
.login-card input { background: #ffffff; color: #0f172a; border-color: #cbd5e1; }
.login-card input::placeholder { color: #94a3b8; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: transparent; border: 0; padding: 6px 8px; font-size: 16px; cursor: pointer; color: #475569; }
.pw-toggle:hover { filter: none; color: #1d4ed8; background: transparent; }
.login-links { display: flex; justify-content: center; margin-top: 14px; }
.login-links a { color: var(--accent); font-size: 13px; text-decoration: none; }
.login-links a:hover { text-decoration: underline; }

/* ---- Lista de CNPJs ---- */
.cnpj-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; max-height: 240px; overflow: auto; padding: 4px; }
.cnpj-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; cursor: pointer; }
.cnpj-item input { width: auto; }

/* ====== Dashboard tela cheia / fluido ====== */
body.dash-page { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.dash-shell { flex: 1; min-height: 0; padding: clamp(12px, 1.4vw, 28px); display: flex; flex-direction: column; gap: clamp(10px, 1vw, 18px); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .seg { display: inline-flex; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.toolbar .seg button {
  background: transparent; color: var(--muted); border: 0; border-radius: 9px;
  padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.toolbar .seg button.active { background: var(--accent); color: var(--on-accent); }
.toolbar .seg button:hover:not(.active) { background: var(--panel-2); color: var(--ink); }
.toolbar .custom { display: none; align-items: center; gap: 8px; }
.toolbar .custom.show { display: inline-flex; }
.toolbar .spacer { flex: 1; }
.toolbar .range-info { color: var(--muted); font-size: 13px; }

.dash-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr clamp(320px, 26vw, 460px); gap: clamp(10px, 1vw, 18px); }
.dash-main { min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: clamp(10px, 1vw, 18px); }
.dash-main .stats { margin: 0; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: clamp(10px, 1vw, 18px); }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; }
.chart-card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.chart-box { position: relative; flex: 1; min-height: 220px; }
.chart-box.tall { min-height: 260px; }

.json-col { min-height: 0; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.json-col .json-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.json-col .json-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.json-col .json-body { flex: 1; overflow: auto; padding: 12px; }
.json-item { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.json-item .ji-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #07103a; font-size: 12px; font-weight: 700; }
.json-item pre { margin: 0; padding: 12px; font-size: 12px; line-height: 1.5; overflow-x: auto; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; color: #c8d4f5; white-space: pre-wrap; word-break: break-word; }

@media (max-width: 980px) {
  body.dash-page { height: auto; overflow: auto; }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-main { overflow: visible; }
  .json-col { height: 520px; }
}
