:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #64748b;
  --border: #d9e0e7;
  --accent: #1f5f99;
  --accent-dark: #174b79;
  --accent-soft: #e8f1f8;
  --danger: #a83a3a;
  --success: #237a4b;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.helper {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card h1 { margin: 18px 0 8px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.stack { display: grid; gap: 15px; margin: 26px 0 14px; }

.app-shell {
  width: min(1640px, 100%);
  margin: 0 auto;
  padding: 20px;
}

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

.topbar h1 { margin: 2px 0 0; font-size: clamp(1.55rem, 2.5vw, 2.25rem); }
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.user-controls, .map-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.9rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card, .panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.metric-card {
  padding: 17px 18px;
}
.metric-card span { color: var(--muted); font-size: 0.86rem; }
.metric-card strong { display: block; margin-top: 5px; font-size: 1.75rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.main-column { display: grid; gap: 16px; min-width: 0; }
.panel { padding: 18px; }
.form-panel { position: sticky; top: 12px; }

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 15px;
}
.section-heading h2 { margin: 2px 0 0; font-size: 1.2rem; }

.form-grid { display: grid; gap: 13px; }
label {
  display: grid;
  gap: 6px;
  color: #344253;
  font-size: 0.88rem;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5df;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 95, 153, 0.14);
}

textarea { resize: vertical; }
.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.three-column {
  display: grid;
  grid-template-columns: minmax(95px, 0.75fr) repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.conditional-fields {
  display: grid;
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #f8fafc;
}

.conditional-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.conditional-heading h3 {
  margin: 2px 0 0;
  font-size: 1rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px;
  border: 1px solid #cbd5df;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

.checkbox-row input {
  width: auto;
  margin: 2px 0 0;
  flex: 0 0 auto;
}

.checkbox-row span {
  display: grid;
  gap: 3px;
}

.checkbox-row small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.35;
}

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

.detail-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.detail-link:hover {
  text-decoration: underline;
}

.scan-badge,
.download-badge {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.scan-badge {
  background: #eee8f7;
  color: #5d4089;
}

.download-badge {
  background: #e6f0f8;
  color: #174b79;
}
.coordinate-group, .address-lookup-group { display: grid; gap: 8px; }
.address-lookup-group .button { width: 100%; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 700;
  text-decoration: none;
}
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: #fff; border-color: var(--border); color: var(--text); }
.button.secondary:hover { background: #f8fafc; }
.button.compact { padding: 8px 11px; font-size: 0.85rem; }
.button.danger { color: var(--danger); border-color: #e7caca; background: #fff; }

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 3px;
}

.inline-message {
  margin-bottom: 13px;
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.88rem;
}

#map {
  width: 100%;
  height: 530px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #e8edf2;
}
.map-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 13px;
  margin: 12px 0 8px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}
.legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.2);
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(150px, 1fr));
  gap: 11px;
  margin-bottom: 14px;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1160px; }
th, td {
  padding: 11px 9px;
  border-bottom: 1px solid #e6ebf0;
  text-align: left;
  vertical-align: top;
  font-size: 0.84rem;
}
th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #4b5968;
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sort-header {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 700;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
}

.sort-header:hover,
.sort-header.active {
  color: var(--accent);
}

.sort-header span {
  font-size: 0.9rem;
  line-height: 1;
}
.row-actions { display: flex; gap: 6px; }
.row-actions button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  padding: 6px 8px;
  font-size: 0.78rem;
}
.row-actions .delete-action { color: var(--danger); }

.zone-badge, .status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.zone-badge { background: var(--accent-soft); color: var(--accent-dark); }
.status-badge { background: #eef1f4; color: #344253; }
.status-badge.completed { background: #e5f4eb; color: #1d6a40; }
.status-badge.cancelled { background: #f7e8e8; color: #8f3030; }

.empty-state { padding: 28px; text-align: center; color: var(--muted); }
.toast {
  position: fixed;
  z-index: 3000;
  right: 18px;
  top: 18px;
  max-width: 360px;
  border-radius: 10px;
  background: #17212b;
  color: white;
  padding: 11px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: .2s ease;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8a2e2e; }


.office-marker-shell {
  background: transparent;
  border: 0;
}
.office-marker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #17212b;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.35);
}

.leaflet-popup-content { line-height: 1.5; }
.popup-title { font-weight: 700; margin-bottom: 4px; }
.popup-line { color: #39495a; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .form-panel { position: static; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { padding: 12px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters, .two-column, .three-column { grid-template-columns: 1fr; }
  .conditional-heading { flex-direction: column; }
  #map { height: 430px; }
  .map-heading, .list-heading { align-items: flex-start; flex-direction: column; }
  .panel { padding: 14px; }
}

@media (max-width: 430px) {
  .metrics { grid-template-columns: 1fr; }
  .auth-card { padding: 24px; }
}
