:root {
  color-scheme: dark;
  --bg: #030b16;
  --bg-soft: #061426;
  --surface: rgba(10, 27, 49, .92);
  --surface-strong: #0b1d34;
  --surface-hover: #102b4a;
  --text: #f5f8fc;
  --muted: #9dafc5;
  --border: rgba(100, 151, 207, .24);
  --border-strong: rgba(88, 156, 255, .55);
  --blue: #1769ff;
  --blue-soft: #66a2ff;
  --orange: #ff7417;
  --green: #27d691;
  --danger: #ff766d;
  --heat-rgb: 255, 116, 23;
  --cold: #0d2948;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 86% -8%, rgba(23, 105, 255, .22), transparent 33%),
    radial-gradient(circle at 5% 42%, rgba(20, 75, 128, .16), transparent 27%),
    linear-gradient(145deg, #061426 0%, #030b16 70%);
  color: var(--text);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: .22;
  background-image:
    linear-gradient(rgba(83, 143, 203, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(83, 143, 203, .08) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, #000, transparent 74%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(3, 12, 24, .86);
  box-shadow: 0 12px 35px rgba(0, 0, 0, .2);
  backdrop-filter: blur(18px);
}
.topbar-inner, main { width: min(1280px, calc(100% - 40px)); margin-inline: auto; }
.topbar-inner { min-height: 104px; display: flex; justify-content: space-between; align-items: center; gap: 28px; padding: 17px 0; }
.brand-cluster, .topbar-actions, .module-title, .module-status, .live-indicator { display: flex; align-items: center; }
.brand-cluster { gap: 16px; }
.brand-mark {
  position: relative;
  width: 48px;
  height: 58px;
  flex: 0 0 auto;
  filter: drop-shadow(0 0 16px rgba(23, 105, 255, .35));
}
.brand-mark::before, .brand-mark::after, .brand-mark i {
  content: "";
  position: absolute;
  border-radius: 75% 12% 72% 38%;
  transform: rotate(36deg);
}
.brand-mark::before { inset: 5px 11px 13px 10px; background: linear-gradient(145deg, #ff8b2b, #ff5b10); }
.brand-mark::after { inset: 18px 4px 4px 17px; background: linear-gradient(145deg, #3887ff, #0847cb); }
.brand-mark i { inset: 31px 14px 5px 20px; background: #07182d; }
.brand-name { margin: 0 0 2px; color: #fff; font-size: .72rem; font-weight: 900; letter-spacing: .18em; }
.module-title { gap: 12px; }
h1, h2, p { margin-top: 0; }
h1 { margin: 0; font-size: clamp(1.65rem, 3vw, 2.35rem); font-weight: 780; letter-spacing: -.045em; }
.module-title span { padding: 5px 9px; border: 1px solid rgba(255, 116, 23, .38); border-radius: 999px; background: rgba(255, 116, 23, .1); color: #ff9a55; font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.topbar-actions { gap: 14px; }
.module-status, .live-indicator { gap: 8px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.module-status i, .live-indicator i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 13px var(--green); }

main { padding: 40px 0 72px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }
.page-intro h2 { margin: 0; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1.05; letter-spacing: -.045em; }
.page-intro p:not(.eyebrow) { max-width: 720px; margin: 12px 0 0; color: var(--muted); line-height: 1.55; }
.live-indicator { padding: 10px 14px; border: 1px solid var(--border); border-radius: 999px; background: rgba(8, 25, 46, .7); }
.eyebrow { margin-bottom: 7px; color: var(--blue-soft); font-size: .7rem; font-weight: 850; letter-spacing: .17em; text-transform: uppercase; }

.button, input, select { min-height: 44px; border: 1px solid var(--border); border-radius: 11px; font: inherit; }
.button { display: inline-flex; align-items: center; justify-content: center; padding: 0 17px; font-size: .84rem; font-weight: 750; text-decoration: none; cursor: pointer; transition: .2s ease; }
.button.primary { border-color: #438cff; background: linear-gradient(135deg, #0e51d7, #1769ff); color: #fff; box-shadow: 0 11px 28px rgba(23, 105, 255, .23); }
.button.secondary { background: rgba(14, 37, 65, .76); color: #dce7f5; }
.button:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.button:focus-visible, input:focus-visible, select:focus-visible, .heat-cell:focus-visible { outline: 3px solid rgba(65, 137, 255, .35); outline-offset: 2px; }
.button:disabled { opacity: .58; cursor: wait; transform: none; }

.controls, .login-panel, .visual-section {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(13, 37, 66, .93), rgba(6, 21, 39, .95));
  box-shadow: 0 22px 55px rgba(0, 0, 0, .2);
}
.controls { display: flex; align-items: end; flex-wrap: wrap; gap: 13px; padding: 19px 20px; }
.controls-heading { display: grid; gap: 3px; min-width: 205px; margin-right: auto; }
.controls-heading span { font-size: .95rem; font-weight: 780; }
.controls-heading small { color: var(--muted); font-size: .72rem; }
.controls label, .login-panel label { display: grid; gap: 6px; min-width: 145px; color: var(--muted); font-size: .76rem; font-weight: 680; }
.login-panel { display: grid; grid-template-columns: 1.5fr repeat(3, minmax(140px, 1fr)) auto; align-items: end; gap: 15px; margin: 20px 0; padding: 24px; }
.login-panel[hidden] { display: none; }
.login-panel h2 { margin-bottom: 4px; font-size: 1.5rem; }
.login-panel p { margin-bottom: 0; color: var(--muted); font-size: .9rem; }
input, select { width: 100%; padding: 0 12px; background: rgba(3, 14, 27, .72); color: var(--text); }
select option { background: #0b1d34; }
.status { min-height: 26px; margin: 14px 2px 6px; color: var(--muted); font-size: .85rem; }
.status.error { color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 20px 0 28px; }
.stats article { position: relative; overflow: hidden; min-height: 116px; padding: 20px; border: 1px solid var(--border); border-radius: 17px; background: linear-gradient(145deg, rgba(15, 43, 77, .96), rgba(7, 23, 42, .96)); box-shadow: 0 16px 38px rgba(0, 0, 0, .18); }
.stats article::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: linear-gradient(90deg, var(--blue), var(--orange)); }
.stats article::after { content: ""; position: absolute; right: -34px; bottom: -55px; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, rgba(23, 105, 255, .2), transparent 68%); }
.stats span { display: block; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stats strong { position: relative; z-index: 1; display: block; margin-top: 14px; font-size: clamp(1.35rem, 2.5vw, 2rem); font-variant-numeric: tabular-nums; letter-spacing: -.035em; }

.visual-section { margin: 24px 0; padding: 24px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid rgba(122, 166, 215, .15); }
.section-heading h2 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.selection-detail { max-width: 52%; margin-bottom: 0; color: var(--muted); text-align: right; font-size: .8rem; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(42px, 1fr)); gap: 8px; }
.calendar-label, .matrix-label { color: var(--muted); font-size: .7rem; font-weight: 750; text-align: center; padding: 5px; }
.heat-cell { min-height: 67px; border: 1px solid rgba(89, 139, 194, .25); border-radius: 10px; background: linear-gradient(145deg, rgba(var(--heat-rgb), var(--heat, .06)), rgba(8, 30, 53, .86)); color: var(--text); cursor: pointer; padding: 9px; text-align: left; font: inherit; transition: .18s ease; }
.heat-cell:hover { transform: translateY(-2px); border-color: rgba(255, 143, 67, .72); box-shadow: 0 10px 22px rgba(0, 0, 0, .24); }
.heat-cell strong, .heat-cell span { display: block; }
.heat-cell strong { font-size: .82rem; }
.heat-cell span { margin-top: 11px; color: #f5d1b9; font-size: .7rem; font-variant-numeric: tabular-nums; }
.calendar-empty { min-height: 67px; }
.matrix-wrap { overflow-x: auto; padding: 2px 0 7px; scrollbar-color: #315a88 #08192c; }
.hour-matrix { display: grid; grid-template-columns: 72px repeat(24, minmax(31px, 1fr)); gap: 4px; min-width: 970px; }
.hour-matrix .heat-cell { min-height: 36px; padding: 0; border-radius: 6px; text-align: center; }
.territories { display: grid; gap: 4px; }
.territory-row { display: grid; grid-template-columns: minmax(160px, 1.2fr) minmax(140px, 3fr) minmax(100px, auto); gap: 15px; align-items: center; padding: 12px 7px; border-bottom: 1px solid rgba(122, 166, 215, .13); border-radius: 9px; }
.territory-row:hover { background: rgba(35, 88, 142, .12); }
.territory-name strong { font-size: .9rem; }
.territory-name small { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.territory-bar { height: 13px; overflow: hidden; border-radius: 999px; background: linear-gradient(90deg, var(--orange) var(--bar), var(--cold) var(--bar)); box-shadow: inset 0 0 0 1px rgba(117, 162, 211, .15); }
.territory-value { color: #dce8f7; text-align: right; font-size: .86rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.empty-message { padding: 24px 0; color: var(--muted); }
.ranking-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ranking-card { padding: 18px; border: 1px solid rgba(122, 166, 215, .16); border-radius: 14px; background: rgba(5, 20, 37, .56); }
.ranking-card-wide { grid-column: 1 / -1; }
.ranking-card h3 { margin: 0 0 12px; font-size: .92rem; }
.ranking-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid rgba(122, 166, 215, .11); }
.ranking-position { color: var(--blue-soft); font-size: .68rem; font-weight: 850; }
.ranking-row strong, .ranking-row small { display: block; }
.ranking-row strong { overflow: hidden; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row small, .privacy-note { margin-top: 3px; color: var(--muted); font-size: .68rem; line-height: 1.4; }
.ranking-row b { color: #dce8f7; font-size: .8rem; font-variant-numeric: tabular-nums; }
.empty-message.compact { margin: 0; padding: 12px 0; }
.privacy-note { display: block; margin-top: 12px; }
.route-controls { display: flex; align-items: end; gap: 10px; }
.report-controls { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto; gap: 12px; align-items: end; }
.report-controls label { display: grid; gap: 6px; color: var(--muted); font-size: .76rem; font-weight: 680; }
.report-table-wrap { overflow-x: auto; margin-top: 14px; }
.report-table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: .8rem; }
.report-table th, .report-table td { padding: 12px 10px; border-bottom: 1px solid rgba(122, 166, 215, .14); text-align: right; font-variant-numeric: tabular-nums; }
.report-table th { color: var(--muted); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; }
.report-table th:first-child, .report-table th:nth-child(2), .report-table td:first-child, .report-table td:nth-child(2) { text-align: left; }
.report-table tbody tr:hover { background: rgba(35, 88, 142, .12); }
.highlights-actions { display: flex; align-items: center; gap: 12px; }
.highlights-actions label { display: grid; gap: 5px; min-width: 145px; color: var(--muted); font-size: .72rem; font-weight: 680; }
.highlights-actions label[hidden] { display: none; }
.highlights-explanation { margin: -4px 0 16px; color: var(--muted); font-size: .78rem; }
.weekly-highlights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.highlight-card { display: grid; grid-template-columns: 125px 1fr; gap: 17px; align-items: center; padding: 14px; border: 1px solid rgba(122,166,215,.18); border-radius: 14px; background: rgba(5,20,37,.56); }
.highlight-card img { width: 125px; border-radius: 9px; }
.highlight-card h3 { margin: 0 0 9px; }
.highlight-card ul { margin: 0 0 14px; padding-left: 18px; color: var(--muted); font-size: .76rem; line-height: 1.55; }
.route-controls label { display: grid; gap: 6px; color: var(--muted); font-size: .76rem; font-weight: 680; }
.route-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.route-summary article { padding: 13px 15px; border: 1px solid rgba(122, 166, 215, .16); border-radius: 12px; background: rgba(5, 20, 37, .56); }
.route-summary span { display: block; color: var(--muted); font-size: .68rem; text-transform: uppercase; }
.route-summary strong { display: block; margin-top: 6px; font-size: 1rem; }
.route-map-shell { position: relative; overflow: hidden; border-radius: 14px; background: #08192c; }
.route-map { min-height: 510px; overflow: hidden; border: 1px solid rgba(122, 166, 215, .24); border-radius: 14px; background: #08192c; }
.route-fullscreen-button { position: absolute; top: 12px; right: 12px; z-index: 1100; min-height: 38px; border-color: rgba(255,255,255,.34); background: rgba(3,14,27,.88); color: #fff; box-shadow: 0 7px 20px rgba(0,0,0,.3); }
.route-map-shell:fullscreen { width: 100vw; height: 100vh; border-radius: 0; }
.route-map-shell:fullscreen .route-map { width: 100%; height: 100%; min-height: 100vh; border: 0; border-radius: 0; }
.route-status { margin: 12px 2px 0; color: var(--muted); font-size: .78rem; }
.route-status.error { color: var(--danger); }
.route-map .leaflet-control-attribution { font-size: 10px; }
/* Base local do Leaflet: mantém os mosaicos posicionados mesmo se o CSS do CDN falhar. */
.leaflet-container { position: relative; overflow: hidden; outline-offset: 1px; }
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow,
.leaflet-tile-container, .leaflet-pane > svg, .leaflet-pane > canvas,
.leaflet-zoom-box { position: absolute; left: 0; top: 0; }
.leaflet-container img.leaflet-tile { max-width: none !important; max-height: none !important; width: 256px; height: 256px; padding: 0; }
.leaflet-tile { visibility: hidden; user-select: none; -webkit-user-drag: none; }
.leaflet-tile-loaded { visibility: inherit; }
.leaflet-zoom-animated { transform-origin: 0 0; }
.leaflet-zoom-anim .leaflet-zoom-animated { transition: transform .25s cubic-bezier(0, 0, .25, 1); }
.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg { z-index: 200; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-top .leaflet-control { margin-top: 10px; }
.leaflet-left .leaflet-control { margin-left: 10px; }
.leaflet-right .leaflet-control { margin-right: 10px; }
.leaflet-bottom .leaflet-control { margin-bottom: 10px; }
.leaflet-control-zoom a { display: block; width: 30px; height: 30px; background: #fff; color: #111; font: bold 18px/30px Arial; text-align: center; text-decoration: none; }
.leaflet-control-attribution { padding: 2px 5px; background: rgba(255, 255, 255, .82); color: #222; }
.leaflet-control-attribution a { color: #1769aa; }
.leaflet-interactive { cursor: pointer; }

@media (max-width: 940px) {
  .topbar-inner { align-items: flex-start; }
  .topbar-actions { align-items: flex-end; flex-direction: column; }
  .login-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-panel > div { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .route-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .weekly-highlights { grid-template-columns: 1fr; }
  .ranking-grid { grid-template-columns: 1fr; }
  .ranking-card-wide { grid-column: auto; }
  .report-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar-inner, main { width: min(100% - 24px, 1280px); }
  .topbar-inner, .page-intro, .section-heading { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; align-items: stretch; }
  .module-status { display: none; }
  main { padding-top: 28px; }
  .page-intro h2 { font-size: 2rem; }
  .live-indicator { align-self: flex-start; }
  .controls, .login-panel { display: grid; grid-template-columns: 1fr; }
  .controls-heading, .controls label, .login-panel label { min-width: 0; }
  .stats { gap: 10px; }
  .stats article { min-height: 102px; padding: 15px; }
  .visual-section { padding: 17px 13px; }
  .selection-detail { max-width: none; text-align: left; }
  .calendar { gap: 4px; }
  .heat-cell { min-height: 58px; padding: 6px; }
  .heat-cell strong { font-size: .7rem; }
  .heat-cell span { font-size: .61rem; }
  .territory-row { grid-template-columns: 1fr auto; }
  .territory-bar { grid-column: 1 / -1; grid-row: 2; }
  .ranking-card { padding: 14px; }
  .ranking-row { grid-template-columns: 24px minmax(0, 1fr); }
  .ranking-row b { grid-column: 2; }
  .route-controls { width: 100%; align-items: stretch; flex-direction: column; }
  .report-controls { grid-template-columns: 1fr; }
  .highlights-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .highlight-card { grid-template-columns: 95px 1fr; }
  .highlight-card img { width: 95px; }
  .route-map { min-height: 390px; }
  .route-fullscreen-button { top: 8px; right: 8px; min-height: 36px; padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; }
}
