﻿:root {
  --page: #eef3f2;
  --surface: #ffffff;
  --surface-soft: #fff8f2;
  --ink: #231914;
  --muted: #75685f;
  --line: #ecd9c7;
  --brand: #9a3f00;
  --brand-dark: #6f2d00;
  --brand-soft: #fff0df;
  --accent: #d96b16;
  --danger: #b42318;
  --warn: #915a00;
  --ok: #147443;
  --shadow: 0 18px 45px rgba(72, 45, 26, .10);
}

:root[data-theme="dark"] {
  --page: #181b1f;
  --surface: #23272d;
  --surface-soft: #2a2e35;
  --ink: #eef1f4;
  --muted: #b7bdc5;
  --line: #3a414a;
  --brand: #c7936b;
  --brand-dark: #e0b995;
  --brand-soft: #343139;
  --accent: #cfa07a;
  --danger: #d98d87;
  --warn: #d7b474;
  --ok: #8fc7a2;
  --shadow: 0 18px 45px rgba(0, 0, 0, .24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, var(--surface) 0, var(--page) 44%, var(--page) 100%);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

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

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-brand {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.login-brand strong {
  display: block;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.2;
}

.login-brand small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px 13px;
  font: inherit;
}

.login-form button,
.logout-button {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.login-form button {
  min-height: 44px;
}

.login-error {
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  padding: 10px 12px;
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--ink);
  font-size: 30px;
  line-height: 1.15;
  font-weight: 850;
}

h2 {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
  padding: 26px;
  gap: 18px;
}

.sidebar {
  position: sticky;
  top: 26px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  border: 1px solid color-mix(in srgb, var(--brand) 18%, transparent);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  padding: 18px;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding: 4px 4px 20px;
}

.brand::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 4px;
  width: 54px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  width: auto;
  height: 30px;
  padding: 0 7px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong {
  display: block;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.2;
  max-width: 180px;
}

.brand small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
}

.brand small,
.sidebar-footer small {
  color: var(--muted);
}

.logout-form {
  width: 100%;
}

.logout-button {
  width: 100%;
  min-height: 36px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--brand) 86%, #000);
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 800;
  padding: 8px 10px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.nav-item:hover,
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.nav-item.active .nav-icon {
  background: var(--brand);
  color: #fff;
}

.sub-nav {
  display: grid;
  gap: 6px;
  margin: -2px 0 6px 42px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.sub-nav-item {
  display: flex;
  align-items: center;
  min-height: 34px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}

.sub-nav-item:hover,
.sub-nav-item.active {
  background: color-mix(in srgb, var(--brand-soft) 70%, transparent);
  color: var(--brand-dark);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 12px;
}

.theme-toggle {
  width: max-content;
  height: auto;
  justify-content: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.theme-toggle:hover {
  background: transparent;
  box-shadow: none;
  transform: none;
}

.theme-track {
  position: relative;
  width: 62px;
  height: 30px;
  border-radius: 999px;
  background: #c6c4bf;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}

.theme-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .20);
  transition: transform .20s ease, background .20s ease;
}

.theme-icon {
  position: absolute;
  inset: 5px;
  width: 12px;
  height: 12px;
  object-fit: contain;
  transition: opacity .18s ease;
  pointer-events: none;
}

.theme-icon-dark {
  opacity: 1;
}

.theme-icon-light {
  opacity: 0;
}

:root[data-theme="dark"] .theme-track {
  background: #2f3032;
}

:root[data-theme="dark"] .theme-thumb {
  transform: translateX(32px);
  background: #ffffff;
}

:root[data-theme="dark"] .theme-icon-dark {
  opacity: 0;
}

:root[data-theme="dark"] .theme-icon-light {
  opacity: 1;
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  min-height: 118px;
  border: 1px solid color-mix(in srgb, var(--brand) 18%, transparent);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  padding: 24px;
}

.dashboard-topbar {
  min-height: auto;
  padding: 20px 24px;
}

.dashboard-topbar + main {
  padding-top: 12px;
}

.brand-block {
  display: grid;
  gap: 7px;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.subtitle {
  max-width: 680px;
  color: var(--muted);
  font-size: 14px;
}

main {
  padding-top: 18px;
}

.content-shell {
  max-width: 1500px;
}

.dashboard-main .content-shell,
.distribution-main .content-shell,
.monitor-main .content-shell {
  max-width: none;
  width: 100%;
}

.run-form {
  display: grid;
  gap: 8px;
  min-width: 374px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.dashboard-filter {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  min-width: 520px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.dashboard-filter > div {
  display: grid;
  gap: 8px;
}

.filter-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--brand-dark);
  font-weight: 850;
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

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

.run-controls {
  display: flex;
  gap: 10px;
}

input,
select,
button,
.secondary {
  height: 42px;
  border-radius: 10px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 107, 22, .18);
}

.sql-query-panel {
  margin-bottom: 18px;
}

.sql-filter {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(280px, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.sql-filter.district-filter {
  grid-template-columns: minmax(130px, .7fr) minmax(220px, 1.4fr) minmax(150px, .8fr) minmax(150px, .8fr) auto;
}

.sql-filter > div {
  display: grid;
  gap: 8px;
}

.sql-filter button[type="submit"] {
  min-width: 104px;
  gap: 8px;
}

.button-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

.sql-filter button.is-loading .button-spinner {
  display: inline-block;
}

.period-value {
  font-size: 20px !important;
  line-height: 1.2 !important;
}

.district-table {
  min-width: 860px;
}

.district-table th:nth-child(2),
.district-table td:nth-child(2) {
  min-width: 520px;
}

.district-summary-table {
  min-width: 520px;
}

.district-summary-table th:nth-child(2),
.district-summary-table td:nth-child(2) {
  min-width: 180px;
}

.group-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  padding: 7px 12px;
  white-space: nowrap;
}

.group-checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand);
  cursor: pointer;
}

.missing-filter-control {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.missing-filter-control small {
  color: var(--muted);
  font-size: 12px;
}

.missing-filter-control small strong {
  color: var(--warn);
}

.missing-filter-control small[hidden] {
  display: none;
}

.district-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.district-filter-control {
  position: relative;
}

.district-filter-button {
  min-width: 170px;
  justify-content: space-between;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  padding: 0 12px;
}

.district-filter-button:hover {
  background: var(--surface-soft);
  color: var(--ink);
  box-shadow: none;
  transform: none;
}

.district-filter-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.district-filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 9px 0;
}

.district-filter-actions .filter-clear {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.district-filter-options {
  display: grid;
  gap: 3px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.district-filter-options label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 8px;
}

.district-filter-options label:hover {
  background: var(--brand-soft);
}

.district-filter-options label[hidden] {
  display: none;
}

.district-filter-options input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand);
}

.date-picker {
  position: relative;
  min-width: 170px;
}

.date-trigger {
  width: 100%;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
}

.date-trigger:hover {
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
  transform: none;
}

.date-icon {
  width: 14px;
  height: 14px;
  border: 2px solid var(--brand);
  border-radius: 3px;
  position: relative;
  opacity: .9;
}

.date-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 3px;
  height: 2px;
  background: var(--brand);
}

.calendar-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  width: 292px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 22px 48px rgba(0, 0, 0, .18);
  padding: 14px;
}

.calendar-popover[aria-hidden="true"] {
  display: none;
}

.calendar-head {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.calendar-head strong {
  text-align: center;
  text-transform: capitalize;
}

.calendar-nav {
  width: 36px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.calendar-day,
.calendar-empty {
  width: 32px;
  height: 32px;
}

.calendar-day {
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.calendar-day:hover {
  background: var(--surface-soft);
  color: var(--ink);
  box-shadow: none;
  transform: none;
}

.calendar-day.processed {
  border-color: color-mix(in srgb, var(--brand) 52%, var(--line));
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.calendar-day.selected {
  background: var(--brand);
  color: #fff;
}

.calendar-day.today:not(.selected) {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--brand) 52%, transparent);
}

.calendar-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.calendar-legend i {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 52%, var(--line));
}

.calendar-legend button {
  height: 28px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--brand-dark);
}

.calendar-popover .calendar-nav,
.calendar-popover .calendar-day,
.calendar-popover .calendar-legend button {
  box-shadow: none;
  transform: none;
}

.calendar-popover .calendar-nav:hover,
.calendar-popover .calendar-day:hover,
.calendar-popover .calendar-legend button:hover {
  box-shadow: none;
  transform: none;
}

button,
.secondary {
  border: 0;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 850;
  padding: 0 16px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

button:disabled {
  cursor: wait;
  opacity: .78;
  transform: none;
}

button:hover,
.secondary:hover {
  background: var(--brand-dark);
  box-shadow: 0 8px 20px rgba(54, 28, 8, .16);
  transform: translateY(-1px);
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 13px 15px;
  box-shadow: 0 8px 26px rgba(82, 43, 12, .06);
}

.message.success {
  border-color: color-mix(in srgb, var(--ok) 48%, var(--line));
  color: var(--ok);
}

.message.error {
  border-color: color-mix(in srgb, var(--danger) 48%, var(--line));
  color: var(--danger);
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(142px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.dashboard-summary {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.metric-card,
.empty-state,
.panel,
.history-item,
.table-wrap {
  border: 1px solid color-mix(in srgb, var(--brand) 18%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.metric-card {
  position: relative;
  display: grid;
  align-content: center;
  gap: 8px;
  min-height: 108px;
  padding: 18px;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 18px auto 18px 0;
  width: 5px;
  border-radius: 999px;
  background: var(--accent);
}

.metric-card.highlight,
.metric-card.warning {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 48%, var(--line));
}

.metric-card strong {
  font-size: 26px;
  line-height: 1;
}

.metric-link {
  display: block;
  width: fit-content;
  height: auto;
  min-width: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.metric-link.ok {
  color: var(--ok-ink);
}

.metric-link.danger {
  color: var(--danger);
}

.metric-link:hover {
  background: transparent;
  color: var(--brand-dark);
  box-shadow: none;
  transform: none;
}

.metric-card small {
  color: var(--warn);
  font-size: 12px;
  font-weight: 800;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  min-height: 98px;
  color: var(--muted);
  padding: 22px;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.history,
.details {
  min-width: 0;
}

.history {
  position: sticky;
  top: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 12px;
}

.section-title p {
  margin-top: 4px;
  color: var(--muted);
}

.section-title .warning-note {
  color: var(--warn);
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: max(280px, calc(100vh - 390px));
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-color: var(--accent) color-mix(in srgb, var(--surface) 70%, var(--line));
  scrollbar-width: thin;
}

.history-list::-webkit-scrollbar {
  width: 8px;
}

.history-list::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--surface) 70%, var(--line));
  border-radius: 999px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 999px;
}

.history-item {
  display: grid;
  gap: 5px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.history-item:hover {
  border-color: color-mix(in srgb, var(--brand) 42%, var(--line));
  transform: translateY(-1px);
}

.history-item.active {
  border-color: var(--brand);
  background: var(--surface-soft);
  box-shadow: inset 4px 0 0 var(--brand), var(--shadow);
}

.history-item span {
  font-weight: 850;
}

.history-item small {
  color: var(--muted);
  line-height: 1.35;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 940px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

tbody tr {
  transition: background .12s ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--brand-soft) 52%, transparent);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td strong {
  color: var(--ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
}

.pill.ok {
  background: color-mix(in srgb, var(--ok) 20%, var(--surface));
  color: var(--ok);
}

.pill.faltando,
.pill.parcial,
.pill.excedente {
  background: color-mix(in srgb, var(--warn) 22%, var(--surface));
  color: var(--warn);
}

.pill.erro {
  background: color-mix(in srgb, var(--danger) 20%, var(--surface));
  color: var(--danger);
}

.system-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: 520px;
}

.system-breakdown span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 1px solid color-mix(in srgb, var(--brand) 20%, var(--line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-soft) 72%, var(--surface));
  color: var(--muted);
  padding: 4px 10px;
  white-space: nowrap;
}

.system-breakdown strong {
  color: var(--brand-dark);
}

.system-breakdown i {
  font-style: normal;
}

.missing-system-summary {
  margin-bottom: 14px;
}

.missing-data-table {
  min-width: 860px;
}

.missing-data-table th:nth-child(2),
.missing-data-table td:nth-child(2) {
  min-width: 520px;
}

.missing-page-npu-search {
  display: grid;
  gap: 12px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 14px;
}

.missing-page-npu-search form {
  display: grid;
  gap: 8px;
}

.missing-page-npu-search label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.missing-page-npu-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.missing-page-npu-search-result {
  display: grid;
  gap: 10px;
}

.missing-page-npu-search-result[hidden] {
  display: none;
}

.missing-page-npu-search-result p {
  color: var(--muted);
  font-size: 13px;
}

.missing-page-npu-search-result table {
  min-width: 980px;
}

.danger {
  color: var(--danger);
}

.ok {
  color: var(--ok);
}

.empty {
  color: var(--muted);
  padding: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .85fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-wide {
  grid-column: span 1;
}

.pie-panel {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  align-items: center;
  gap: 26px;
  min-height: 250px;
}

.pie-chart {
  position: relative;
  width: min(260px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 18%, transparent), var(--shadow);
}

.pie-chart::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.pie-center {
  position: absolute;
  inset: 26%;
  z-index: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  text-align: center;
}

.pie-center span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pie-center strong {
  color: var(--brand-dark);
  font-size: 26px;
  line-height: 1;
}

.pie-legend {
  display: grid;
  gap: 12px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.legend-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
}

.legend-item strong {
  display: block;
}

.legend-item small {
  color: var(--muted);
}

.status-stack {
  display: grid;
  gap: 11px;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 11px;
}

.status-line:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.rank-list {
  display: grid;
  gap: 12px;
}

.rank-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 12px;
}

.rank-item div,
.rank-item span {
  position: relative;
  z-index: 1;
}

.rank-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.rank-item span {
  color: var(--danger);
  font-weight: 900;
}

.rank-item i {
  position: absolute;
  inset: auto auto 0 0;
  height: 4px;
  border-radius: 0 999px 999px 0;
  background: var(--accent);
}

.compact-table {
  overflow: auto;
}

.compact-table table {
  min-width: 680px;
}

.processing-modal,
.confirm-modal,
.court-breakdown-modal,
.missing-npu-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(12, 10, 8, .64);
  backdrop-filter: blur(5px);
}

.processing-modal[aria-hidden="false"],
.confirm-modal[aria-hidden="false"],
.court-breakdown-modal[aria-hidden="false"],
.missing-npu-modal[aria-hidden="false"] {
  display: flex;
}

.court-breakdown-dialog {
  display: flex;
  flex-direction: column;
  width: min(1040px, calc(100vw - 44px));
  max-height: min(760px, calc(100vh - 44px));
  border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .38);
  overflow: hidden;
}

.court-breakdown-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
}

.court-breakdown-header p:last-child {
  margin-top: 5px;
  color: var(--muted);
}

.court-breakdown-body {
  padding: 16px;
  overflow: auto;
}

.court-breakdown-body table {
  min-width: 0;
  width: 100%;
}

.court-breakdown-body th:last-child,
.court-breakdown-body td:last-child {
  width: 220px;
  text-align: right;
}

.numeric-cell {
  font-weight: 900;
  color: var(--brand-dark);
}

.missing-npu-modal {
  z-index: 30;
}

.missing-npu-dialog {
  display: flex;
  flex-direction: column;
  width: min(1420px, 100%);
  height: min(820px, calc(100vh - 44px));
  min-height: 520px;
  border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .38);
  overflow: hidden;
}

.missing-npu-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
}

.missing-npu-header p:last-child {
  margin-top: 5px;
  color: var(--muted);
}

.modal-close {
  width: 38px;
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 25px;
  line-height: 1;
  padding: 0;
}

.missing-npu-content {
  display: grid;
  grid-template-columns: minmax(430px, .85fr) minmax(520px, 1.15fr);
  flex: 1;
  min-height: 0;
}

.missing-npu-list-pane,
.missing-html-pane {
  min-width: 0;
  min-height: 0;
  padding: 16px;
}

.missing-npu-list-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.missing-npu-status {
  color: var(--muted);
  margin-bottom: 10px;
}

.npu-search-field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.npu-search-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.npu-search-field input {
  width: 100%;
}

.npu-search-field small {
  min-height: 15px;
  color: var(--muted);
  font-size: 12px;
}

.missing-npu-table-wrap {
  flex: 1;
  min-height: 0;
}

.missing-npu-table {
  min-width: 580px;
}

.npu-detail-button {
  height: auto;
  justify-content: flex-start;
  background: transparent;
  color: var(--brand-dark);
  font-weight: 800;
  padding: 0;
  text-align: left;
}

.missing-npu-pagination {
  display: grid;
  grid-template-columns: 110px 1fr 110px;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  text-align: center;
}

.missing-html-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--page);
}

.missing-html-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.missing-html-title h3 {
  margin: 0;
}

.missing-html-title span {
  color: var(--muted);
  font-size: 12px;
}

.html-view-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 4px;
}

.html-view-tab {
  height: 30px;
  min-width: 72px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 12px;
}

.html-view-tab.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  box-shadow: none;
}

.html-view-panel {
  flex: 1;
  min-height: 0;
  display: flex;
}

.html-view-panel[hidden] {
  display: none;
}

.raw-panel {
  flex-direction: column;
  gap: 10px;
}

.raw-search-field {
  display: grid;
  gap: 6px;
}

.raw-search-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.raw-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 34px 34px;
  align-items: center;
  gap: 8px;
}

.raw-search-field input {
  width: 100%;
}

.raw-search-count {
  min-width: 92px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.raw-search-nav {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--brand-dark);
  padding: 0;
  font-size: 16px;
  font-weight: 900;
}

.raw-search-nav:disabled {
  cursor: default;
  opacity: .45;
}

.raw-panel mark {
  border-radius: 3px;
  background: color-mix(in srgb, var(--brand) 40%, #fff);
  color: var(--ink);
  padding: 0 2px;
}

.raw-panel mark.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 35%, transparent);
}

.missing-html-pane iframe,
.raw-panel pre {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.missing-html-pane iframe {
  background: #fff;
}

.missing-html-pane iframe[hidden] {
  display: none;
}

.html-empty-state {
  display: grid;
  place-content: center;
  gap: 8px;
  flex: 1;
  min-height: 0;
  border: 1px dashed color-mix(in srgb, var(--brand) 35%, var(--line));
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.html-empty-state[hidden] {
  display: none;
}

.html-empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.html-empty-state span {
  max-width: 360px;
  font-size: 13px;
}

.raw-panel pre {
  overflow: auto;
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 14px;
}

button.quantity-link {
  height: auto;
  background: transparent;
  color: var(--brand-dark);
  font-weight: 900;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.quantity-link:hover {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
  transform: none;
}

.processing-panel,
.confirm-panel {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 20px;
  width: min(560px, 100%);
  border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(33, 25, 20, .34);
  padding: 26px;
}

.confirm-panel {
  grid-template-columns: 46px minmax(0, 1fr);
  width: min(620px, 100%);
}

.confirm-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 22px;
  font-weight: 900;
}

.confirm-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(110px, .75fr) minmax(150px, 1fr) minmax(190px, 1.2fr);
  gap: 10px;
}

.ghost-button,
.soft-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--brand-dark);
}

.ghost-button:hover,
.soft-button:hover {
  background: var(--surface-soft);
}

.soft-button {
  background: var(--brand-soft);
}

.modal-eyebrow {
  color: var(--brand);
  margin-bottom: 8px;
}

.processing-panel h2 {
  color: var(--ink);
  font-size: 22px;
}

.processing-copy {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.processing-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.loader-ring {
  width: 58px;
  height: 58px;
  border: 6px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}

.is-processing {
  cursor: wait;
}

.has-modal {
  overflow: hidden;
}

:root[data-theme="dark"] button,
:root[data-theme="dark"] .secondary {
  background: #b88968;
  color: #fff4ea;
}

:root[data-theme="dark"] button:hover,
:root[data-theme="dark"] .secondary:hover {
  background: #c7936b;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .20);
}

:root[data-theme="dark"] button.quantity-link,
:root[data-theme="dark"] button.npu-detail-button,
:root[data-theme="dark"] button.metric-link {
  background: transparent;
  color: var(--brand-dark);
  box-shadow: none;
}

:root[data-theme="dark"] button.quantity-link:hover,
:root[data-theme="dark"] button.npu-detail-button:hover,
:root[data-theme="dark"] button.metric-link:hover {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}

:root[data-theme="dark"] button.metric-link.ok {
  color: var(--ok-ink);
}

:root[data-theme="dark"] button.metric-link.danger {
  color: var(--danger);
}

:root[data-theme="dark"] button.modal-close {
  background: var(--surface-soft);
  color: var(--ink);
}

:root[data-theme="dark"] .metric-card.highlight,
:root[data-theme="dark"] .metric-card.warning {
  background: #2d3037;
  border-color: #514a4b;
}

:root[data-theme="dark"] .metric-card::before {
  background: #c7936b;
}

:root[data-theme="dark"] th {
  background: #2d3037;
  color: #dcc2ac;
}

:root[data-theme="dark"] tbody tr:hover {
  background: #262a30;
}

:root[data-theme="dark"] .history-item.active {
  background: #2a2e35;
}

:root[data-theme="dark"] .pill.ok {
  background: rgba(143, 199, 162, .18);
  color: #a9d9b8;
}

:root[data-theme="dark"] .pill.faltando,
:root[data-theme="dark"] .pill.parcial,
:root[data-theme="dark"] .pill.excedente {
  background: rgba(215, 180, 116, .18);
  color: #e2c993;
}

:root[data-theme="dark"] .pill.erro {
  background: rgba(217, 141, 135, .18);
  color: #e4aaa5;
}

:root[data-theme="dark"] .danger {
  color: #e4aaa5;
}

:root[data-theme="dark"] .ok {
  color: #a9d9b8;
}

:root[data-theme="dark"] .theme-toggle {
  background: #2a2e35;
  color: #f1e8df;
}

:root[data-theme="dark"] .soft-button {
  background: #343139;
  color: #e2b891;
}

:root[data-theme="dark"] input {
  background: #1b1f24;
  border-color: #514a4b;
  color-scheme: dark;
}

:root[data-theme="dark"] .date-trigger {
  background: #1b1f24;
  border-color: #514a4b;
  color: var(--ink);
}

:root[data-theme="dark"] .date-trigger:hover {
  background: #1b1f24;
  color: var(--ink);
}

:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(57%) sepia(20%) saturate(1062%) hue-rotate(337deg) brightness(91%) contrast(86%);
  opacity: 1;
}

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

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .sidebar-footer {
    grid-template-columns: minmax(180px, 240px) 1fr;
    align-items: center;
  }

  .topbar,
  .run-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .run-form,
  .dashboard-filter {
    min-width: 0;
    width: 100%;
  }

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

  .sql-filter {
    grid-template-columns: 1fr 1fr auto;
  }

  .sql-filter.district-filter {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .history {
    position: static;
  }

  .missing-npu-dialog {
    height: calc(100vh - 32px);
  }

  .missing-npu-content {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .missing-npu-list-pane {
    min-height: 460px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .missing-html-pane {
    min-height: 520px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  h1 {
    font-size: 24px;
  }

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

  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary {
    width: 100%;
  }

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

  .sql-filter {
    grid-template-columns: 1fr;
  }

  .sql-filter.district-filter {
    grid-template-columns: 1fr;
  }

  .district-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .district-filter-button,
  .group-checkbox {
    width: 100%;
  }

  .district-filter-panel {
    right: auto;
    left: 0;
    width: min(300px, calc(100vw - 40px));
  }

  .missing-filter-control {
    justify-items: start;
    width: 100%;
  }

  .missing-npu-modal {
    padding: 8px;
  }

  .missing-npu-dialog {
    height: calc(100vh - 16px);
  }

  .missing-npu-header {
    padding: 14px;
  }

  .missing-npu-list-pane,
  .missing-html-pane {
    padding: 12px;
  }

  .missing-npu-pagination {
    grid-template-columns: 1fr 1fr;
  }

  .missing-npu-pagination span {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .pie-panel {
    grid-template-columns: 1fr;
  }

  .pie-chart {
    justify-self: center;
  }

  .processing-panel,
  .confirm-panel {
    grid-template-columns: 1fr;
  }

  .confirm-actions {
    grid-template-columns: 1fr;
  }
}

.calendar-popover .calendar-day {
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
}

.calendar-popover .calendar-day:hover {
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  color: var(--ink);
}

.calendar-popover .calendar-day.processed {
  background: color-mix(in srgb, var(--brand) 24%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 54%, var(--line));
  color: var(--brand-dark);
}

.calendar-popover .calendar-day.selected {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

:root[data-theme="dark"] .calendar-popover .calendar-day {
  background: transparent;
  color: var(--ink);
}

:root[data-theme="dark"] .calendar-popover .calendar-day:hover {
  background: #2a2e35;
}

:root[data-theme="dark"] .calendar-popover .calendar-day.processed {
  background: rgba(199, 147, 107, .20);
  border-color: rgba(199, 147, 107, .58);
  color: #e0b995;
}

:root[data-theme="dark"] .calendar-popover .calendar-day.selected {
  background: #b88968;
  border-color: #b88968;
  color: #fff4ea;
}
