@import url("https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500;600&family=Work+Sans:wght@400;500;600&display=swap");

:root {
  --bg: #f4f1ed;
  --surface: #ffffff;
  --surface-soft: #fbfaf9;
  --ink: #1e2022;
  --muted: #6f7680;
  --accent: #1f4f5a;
  --accent-2: #b0703d;
  --accent-3: #e0c097;
  --line: #e6e0da;
  --shadow: 0 20px 60px rgba(23, 35, 40, 0.12);
  --panel-shadow: 0 10px 40px rgba(23, 35, 40, 0.08);
  --field-bg: #fbfaf9;
  --field-focus-bg: #ffffff;
  --bg-gradient: radial-gradient(circle at 10% 10%, #fdfaf7, #f4f1ed 60%, #ece6df);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Work Sans", sans-serif;
  color: var(--ink);
  background: var(--bg-gradient);
}

body[data-theme="dark"] {
  --bg: #10161b;
  --surface: #161f26;
  --surface-soft: #1b2730;
  --ink: #e8edf0;
  --muted: #a4b0b9;
  --accent: #84bec8;
  --accent-2: #ce9a67;
  --accent-3: #426477;
  --line: #2b3a45;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --panel-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --field-bg: #1b2730;
  --field-focus-bg: #22313c;
  --bg-gradient: radial-gradient(circle at 10% 10%, #1a242d, #11181e 60%, #0c1116);
}

.app {
  min-height: 100vh;
  padding: 48px 6vw 80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar small {
  display: block;
  color: var(--muted);
}

.topbar__user {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.sync-status.pending {
  color: var(--accent-2);
  border-color: rgba(176, 112, 61, 0.45);
  background: rgba(176, 112, 61, 0.12);
}

.sync-status.syncing {
  color: var(--accent);
  border-color: rgba(31, 79, 90, 0.45);
}

.sync-status button {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 5vw;
}

.login__card {
  width: min(420px, 92vw);
  background: var(--surface);
  padding: 32px;
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login__card form {
  display: grid;
  gap: 16px;
}

.error {
  color: #b42318;
  font-weight: 600;
}

.hero {
  display: grid;
  gap: 32px;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  align-items: center;
  margin-bottom: 56px;
  position: relative;
}

.hero::after {
  content: "";
  position: absolute;
  inset: -30px 12% auto auto;
  width: 240px;
  height: 240px;
  background: linear-gradient(135deg, rgba(31, 79, 90, 0.15), rgba(176, 112, 61, 0.15));
  border-radius: 50%;
  filter: blur(1px);
  z-index: 0;
}

.hero__content,
.hero__card {
  position: relative;
  z-index: 1;
}

.hero__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--accent);
  margin-bottom: 12px;
}

h1,
h2,
h3 {
  font-family: "Playfair Display", serif;
  margin: 0 0 12px;
}

h1 {
  font-size: clamp(2rem, 3vw, 3rem);
}

.hero__lead {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 36ch;
}

.hero__stats {
  display: flex;
  gap: 24px;
  margin-top: 24px;
}

.hero__stats span {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--accent);
  display: block;
}

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

.hero__card {
  background: var(--surface);
  padding: 28px 28px 24px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.form__grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.hint {
  font-size: 0.72rem;
  color: var(--muted);
}

input,
select,
textarea {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--ink);
}

.hidden {
  display: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(31, 79, 90, 0.35);
  border-color: transparent;
  background: var(--field-focus-bg);
}

.span-2 {
  grid-column: span 2;
}

.form__actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

button {
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 24px rgba(31, 79, 90, 0.2);
}

button:hover {
  transform: translateY(-1px);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: none;
}

button:disabled,
.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.filters {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.filters__controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.list {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
}

.preview {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  margin-bottom: 24px;
}

.preview__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.preview__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.preview__table {
  display: grid;
  gap: 12px;
}

.users {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  margin-bottom: 24px;
}

.user-form {
  margin-top: 20px;
  padding: 20px;
  border-radius: 16px;
  border: 1px dashed var(--line);
  background: var(--surface-soft);
  display: grid;
  gap: 16px;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 2fr;
  gap: 24px;
  align-items: start;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  margin-bottom: 24px;
}

.dashboard__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.card {
  padding: 16px;
  border-radius: 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 8px;
}

.card__value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.card__value small {
  font-weight: 600;
  color: var(--muted);
}

.spark {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: rgba(31, 79, 90, 0.15);
  overflow: hidden;
}

.spark__fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(31, 79, 90, 0.9), rgba(176, 112, 61, 0.9));
  width: 0%;
  transition: width 0.4s ease;
}

.spark--warning .spark__fill {
  background: linear-gradient(90deg, rgba(176, 112, 61, 0.9), rgba(224, 192, 151, 0.9));
}

.spark--success .spark__fill {
  background: linear-gradient(90deg, rgba(47, 107, 82, 0.9), rgba(140, 188, 158, 0.9));
}

.spark--muted .spark__fill {
  background: linear-gradient(90deg, rgba(111, 118, 128, 0.9), rgba(164, 170, 179, 0.9));
}

.card strong {
  font-size: 1.6rem;
  color: var(--accent);
}

.card__label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--muted);
}

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

.card--primary {
  background: linear-gradient(135deg, rgba(31, 79, 90, 0.15), rgba(224, 192, 151, 0.25));
  border-color: rgba(31, 79, 90, 0.2);
}

.card--warning strong {
  color: #7a4a1e;
}

.card--success strong {
  color: #2f6b52;
}

.card--muted strong {
  color: #4f5660;
}

.report {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 2fr;
  gap: 24px;
  align-items: start;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  margin-bottom: 24px;
}

.report__list {
  display: grid;
  gap: 12px;
}

.report__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.map {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  margin-bottom: 24px;
  display: grid;
  gap: 16px;
}

body.map-screen-lock {
  overflow: hidden;
}

.map--maximized {
  position: fixed;
  inset: 12px;
  z-index: 1500;
  margin: 0;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 16px;
}

.map__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.map__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.map__toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.map__toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  align-self: stretch;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 500;
}

.map__toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.map__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.map__stat {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.map__stat small {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 0.68rem;
}

.map__stat strong {
  color: var(--accent);
  font-size: 1.5rem;
}

.map__canvas {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, #d9e6eb, #ece6de);
}

.map--maximized .map__canvas {
  min-height: clamp(360px, 62vh, 78vh);
}

.map__meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.map__meta-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.map__meta-block h4 {
  margin: 0;
  font-size: 0.92rem;
  font-family: "Work Sans", sans-serif;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.map__list {
  display: grid;
  gap: 8px;
}

#mapAddrPreviewSummary {
  color: var(--muted);
  font-size: 0.82rem;
}

.map__item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.86rem;
}

.map__item strong {
  color: var(--ink);
  font-size: 0.9rem;
}

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

.map__item--stack {
  display: grid;
  gap: 4px;
}

.map-popup {
  min-width: 190px;
  display: grid;
  gap: 4px;
  font-family: "Work Sans", sans-serif;
}

.map-popup strong {
  color: var(--accent);
  font-size: 0.95rem;
}

.map-popup small {
  color: var(--muted);
}

.map-popup button {
  margin-top: 6px;
  box-shadow: none;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.78rem;
}

.list__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.list__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.table {
  display: grid;
  gap: 12px;
}

.table__head,
.table__row {
  display: grid;
  grid-template-columns: 0.8fr 1fr 0.8fr 2fr 1.2fr 1.2fr 1.2fr 1fr 1fr 1fr 0.8fr;
  gap: 12px;
  align-items: center;
}

.table__head {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.table__row {
  padding: 12px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.92rem;
}

.table__empty {
  grid-column: 1 / -1;
  color: var(--muted);
}

.table__row:last-child {
  border-bottom: none;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 79, 90, 0.15);
  color: var(--accent);
}

.badge.status-aberta {
  background: rgba(31, 79, 90, 0.32);
  color: #16404a;
}

.badge.status-andamento {
  background: rgba(176, 112, 61, 0.36);
  color: #6e3a15;
}

.badge.status-concluida {
  background: rgba(47, 107, 82, 0.36);
  color: #1f5a43;
}

.badge.status-cancelada {
  background: rgba(111, 118, 128, 0.36);
  color: #3f464f;
}

.badge.exec-nao-iniciada {
  background: rgba(72, 99, 126, 0.34);
  color: #234056;
}

.badge.exec-andamento {
  background: rgba(201, 99, 66, 0.36);
  color: #6f2e1b;
}

.badge.exec-concluida {
  background: rgba(56, 142, 108, 0.36);
  color: #1f5a43;
}

.badge.exec-suspensa {
  background: rgba(131, 107, 167, 0.36);
  color: #4b3b63;
}

.meta-date {
  margin-left: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.badge.warning {
  background: rgba(176, 112, 61, 0.2);
  color: #7a4a1e;
}

.badge.success {
  background: rgba(58, 128, 97, 0.2);
  color: #2f6b52;
}

.badge.muted {
  background: rgba(111, 118, 128, 0.2);
  color: #4f5660;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  padding: 6px 10px;
  font-size: 0.75rem;
  border-radius: 10px;
  box-shadow: none;
}

.actions button.secondary {
  background: var(--accent-2);
}

#themeToggle {
  min-width: 122px;
}

body[data-theme="dark"] button {
  color: #0f1519;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

body[data-theme="dark"] button.ghost {
  color: var(--accent);
}

body[data-theme="dark"] .hero::after {
  background: linear-gradient(135deg, rgba(132, 190, 200, 0.18), rgba(206, 154, 103, 0.18));
}

body[data-theme="dark"] .card--primary {
  background: linear-gradient(135deg, rgba(132, 190, 200, 0.2), rgba(206, 154, 103, 0.16));
  border-color: rgba(132, 190, 200, 0.25);
}

body[data-theme="dark"] .card--warning strong {
  color: #ffcc9e;
}

body[data-theme="dark"] .card--success strong {
  color: #98dbbe;
}

body[data-theme="dark"] .card--muted strong {
  color: #d4dbe3;
}

body[data-theme="dark"] .badge.status-aberta {
  background: rgba(132, 190, 200, 0.26);
  color: #d0ecf2;
}

body[data-theme="dark"] .badge.status-andamento {
  background: rgba(206, 154, 103, 0.3);
  color: #ffd8b5;
}

body[data-theme="dark"] .badge.status-concluida {
  background: rgba(120, 189, 156, 0.3);
  color: #cbf0dd;
}

body[data-theme="dark"] .badge.status-cancelada {
  background: rgba(144, 155, 169, 0.32);
  color: #e0e7ee;
}

body[data-theme="dark"] .badge.exec-nao-iniciada {
  background: rgba(130, 163, 202, 0.3);
  color: #d7e9ff;
}

body[data-theme="dark"] .badge.exec-andamento {
  background: rgba(216, 133, 102, 0.32);
  color: #ffd6c7;
}

body[data-theme="dark"] .badge.exec-concluida {
  background: rgba(111, 190, 153, 0.32);
  color: #cdf5e3;
}

body[data-theme="dark"] .badge.exec-suspensa {
  background: rgba(163, 138, 198, 0.34);
  color: #e7d7ff;
}

body[data-theme="dark"] .badge.warning {
  background: rgba(206, 154, 103, 0.28);
  color: #ffd8b5;
}

body[data-theme="dark"] .badge.success {
  background: rgba(111, 190, 153, 0.28);
  color: #cdf5e3;
}

body[data-theme="dark"] .badge.muted {
  background: rgba(144, 155, 169, 0.3);
  color: #dde4eb;
}

body[data-theme="dark"] .map__canvas {
  background: linear-gradient(135deg, #1f3442, #18232c);
}

body[data-theme="dark"] .map__canvas .leaflet-popup-content-wrapper,
body[data-theme="dark"] .map__canvas .leaflet-popup-tip {
  background: #1a2630;
  color: #dbe6ee;
}

body[data-theme="dark"] .map__canvas .leaflet-control-zoom a {
  background: #22313c;
  color: #dbe6ee;
  border-color: #355062;
}

@media (max-width: 1080px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .filters {
    flex-direction: column;
    align-items: flex-start;
  }

  .report {
    grid-template-columns: 1fr;
  }

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

  .map__meta {
    grid-template-columns: 1fr;
  }

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

  .table__row span:nth-child(3),
  .table__row span:nth-child(4),
  .table__row span:nth-child(5),
  .table__row span:nth-child(6),
  .table__row span:nth-child(7),
  .table__row span:nth-child(8),
  .table__row span:nth-child(9),
  .table__row span:nth-child(10),
  .table__row span:nth-child(11) {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 32px 5vw 64px;
  }

  .form__grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .form__actions {
    flex-direction: column;
  }

  .hero__stats {
    flex-direction: column;
  }

  .map__canvas {
    min-height: 320px;
  }

  .map--maximized {
    inset: 0;
    border-radius: 0;
    max-height: 100vh;
    padding: 12px;
  }

  .map--maximized .map__canvas {
    min-height: 56vh;
    border-radius: 14px;
  }
}
