:root {
  --ink: #172b24;
  --muted: #66766f;
  --cream: #f5f3eb;
  --paper: #fffefa;
  --line: #dfe4df;
  --green: #1f7252;
  --green-dark: #15543c;
  --new: #667085;
  --started: #e9a23b;
  --incomplete: #d95d54;
  --finished: #3988db;
  --verified: #2f9d68;
  --shadow: 0 18px 50px rgba(24, 44, 37, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: "DM Sans", sans-serif; color: var(--ink); background: var(--cream); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.topbar { height: 76px; padding: 0 34px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px; position: relative; z-index: 1000; background: rgba(255, 254, 250, 0.96); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font: 800 16px/1 "Manrope", sans-serif; letter-spacing: .13em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: var(--ink); color: white; border-radius: 10px 10px 10px 3px; font-size: 18px; letter-spacing: 0; }
.mode-switch { display: flex; background: #ecefe9; padding: 4px; border-radius: 12px; }
.mode-button { border: 0; background: transparent; color: var(--muted); padding: 9px 18px; border-radius: 9px; font-weight: 700; }
.mode-button.active { background: var(--paper); color: var(--ink); box-shadow: 0 2px 8px rgba(23, 43, 36, .09); }
.user-chip { justify-self: end; display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 50%; background: #dfece3; color: var(--green-dark); font-weight: 800; font-size: 12px; }
.user-copy { display: grid; line-height: 1.15; }
.user-copy strong { font-size: 13px; }
.user-copy small { margin-top: 4px; color: var(--muted); }
.view { display: none; }
.view.active { display: block; }
#field-view { height: calc(100vh - 76px); position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; background: #d9dfd8; }
.leaflet-control-attribution { font-size: 9px; }
.map-title-card { position: absolute; z-index: 500; top: 28px; left: 34px; min-width: 235px; padding: 20px 22px; background: rgba(255, 254, 250, .94); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,.75); border-radius: 18px; box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 7px; text-transform: uppercase; letter-spacing: .13em; color: var(--green); font-size: 10px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: "Manrope", sans-serif; }
.map-title-card h1 { margin-bottom: 5px; font-size: 30px; letter-spacing: -.04em; }
.map-title-card > p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.legend { position: absolute; z-index: 500; left: 34px; bottom: 28px; display: flex; gap: 14px; flex-wrap: wrap; max-width: calc(100% - 280px); padding: 11px 15px; background: rgba(255, 254, 250, .94); border-radius: 13px; box-shadow: 0 8px 28px rgba(24,44,37,.12); }
.legend-item { display: flex; align-items: center; gap: 6px; color: #4f5f58; font-size: 11px; font-weight: 700; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.new-job-button { position: absolute; right: 34px; bottom: 28px; z-index: 500; border: 0; border-radius: 14px; padding: 15px 21px; background: var(--ink); color: white; box-shadow: var(--shadow); font-weight: 800; }
.new-job-button span { display: inline-block; margin-right: 8px; font-size: 21px; line-height: 0; vertical-align: -2px; }
.new-job-button:hover, .primary-button:hover { background: var(--green-dark); transform: translateY(-1px); }
.map-control-button { position: absolute; z-index: 500; right: 34px; top: 28px; width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--paper); box-shadow: 0 8px 28px rgba(24,44,37,.13); }
.map-control-button svg { width: 20px; fill: var(--ink); }
.job-marker { position: relative; width: 34px; height: 42px; filter: drop-shadow(0 5px 5px rgba(0,0,0,.24)); }
.job-marker-pin { width: 34px; height: 34px; border: 3px solid white; border-radius: 50% 50% 50% 5px; transform: rotate(-45deg); }
.job-marker-pin::after { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: white; top: 10px; left: 10px; }
.leaflet-popup-content-wrapper { border-radius: 14px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 15px 17px; }
.popup-title { font-family: "Manrope", sans-serif; font-weight: 800; margin-bottom: 7px; }
.popup-status { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; }
.popup-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--status-color); }
.popup-button { width: 100%; margin-top: 13px; border: 0; border-radius: 8px; padding: 8px; background: var(--ink); color: white; font-weight: 700; }

.dashboard-view { min-height: calc(100vh - 76px); padding: 46px 5vw 70px; }
.dashboard-heading { max-width: 1240px; margin: 0 auto 28px; display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.dashboard-heading h1 { margin-bottom: 7px; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.05em; }
.dashboard-heading > div > p:last-child { color: var(--muted); margin: 0; }
.secondary-button { border: 1px solid #ccd4ce; border-radius: 10px; padding: 10px 15px; background: var(--paper); color: var(--ink); font-weight: 800; }
.metric-grid { max-width: 1240px; margin: 0 auto 20px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.metric-card { padding: 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); }
.metric-card-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin-top: 14px; font: 800 28px/1 "Manrope", sans-serif; }
.metric-dot { width: 9px; height: 9px; border-radius: 50%; }
.dashboard-grid { max-width: 1240px; margin: 0 auto 20px; display: grid; grid-template-columns: 1.05fr .95fr; gap: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 23px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-heading h2 { margin: 0; font-size: 20px; letter-spacing: -.03em; }
.panel-heading > strong { font: 800 28px/1 "Manrope", sans-serif; color: var(--green); }
.progress-track { height: 11px; border-radius: 20px; background: #e8ece8; overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .4s ease; }
.status-breakdown { display: grid; gap: 11px; margin-top: 24px; }
.status-row { display: grid; grid-template-columns: 110px 1fr 24px; align-items: center; gap: 12px; font-size: 12px; font-weight: 700; }
.mini-track { height: 6px; border-radius: 10px; background: #e9ece9; overflow: hidden; }
.mini-track span { display: block; height: 100%; border-radius: inherit; }
.activity-list { display: grid; gap: 3px; max-height: 285px; overflow: auto; }
.activity-item { display: grid; grid-template-columns: 10px 1fr auto; gap: 11px; align-items: start; padding: 10px 4px; border-bottom: 1px solid #edf0ed; }
.activity-item:last-child { border-bottom: 0; }
.activity-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; }
.activity-copy { font-size: 12px; }
.activity-copy strong { display: block; margin-bottom: 2px; font-size: 13px; }
.activity-item time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.locations-panel { max-width: 1240px; margin: 0 auto; }
.quiet-label { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 12px; text-align: left; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
td { padding: 14px 12px; border-top: 1px solid #e8ece8; }
td:first-child { font-weight: 800; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 20px; color: white; font-size: 10px; font-weight: 800; }
.empty-state { padding: 24px 8px; color: var(--muted); font-size: 13px; }

.modal { display: none; position: fixed; inset: 0; z-index: 2000; }
.modal.open { display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(14, 30, 24, .54); backdrop-filter: blur(3px); }
.modal-card { position: relative; z-index: 1; width: min(480px, 100%); max-height: 90vh; overflow: auto; padding: 30px; border-radius: 20px; background: var(--paper); box-shadow: 0 30px 90px rgba(0,0,0,.25); }
.modal-card h2 { margin-bottom: 24px; font-size: 27px; letter-spacing: -.04em; }
.modal-close { position: absolute; top: 17px; right: 18px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #edf0ec; color: var(--ink); font-size: 22px; }
label { display: grid; gap: 7px; margin-bottom: 16px; font-size: 12px; font-weight: 800; }
input, textarea, select { width: 100%; border: 1px solid #ccd5ce; border-radius: 10px; padding: 12px 13px; outline: none; background: white; color: var(--ink); }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31,114,82,.1); }
textarea { min-height: 90px; resize: vertical; }
.location-readout, .coordinates { margin: 4px 0 18px; padding: 11px 13px; border-radius: 10px; background: #edf2ee; color: var(--muted); font-size: 11px; }
.primary-button { width: 100%; border: 0; border-radius: 11px; padding: 13px 17px; background: var(--ink); color: white; font-weight: 800; transition: .15s ease; }
.primary-button:disabled { cursor: wait; opacity: .48; transform: none; }
.job-detail-notes { color: var(--muted); font-size: 13px; line-height: 1.55; }
.history-heading { display: flex; justify-content: space-between; align-items: center; margin: 25px 0 12px; }
.history-heading h3 { margin: 0; font-size: 16px; }
.history-heading span { color: var(--muted); font-size: 10px; }
.job-history { display: grid; }
.history-item { position: relative; display: grid; grid-template-columns: 12px 1fr; gap: 11px; padding: 0 0 17px; }
.history-item:not(:last-child)::after { content: ""; position: absolute; left: 5px; top: 12px; bottom: 0; width: 1px; background: #d8ded9; }
.history-dot { z-index: 1; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--paper); box-shadow: 0 0 0 1px currentColor; }
.history-copy strong { display: block; font-size: 12px; }
.history-copy time { color: var(--muted); font-size: 10px; }
.toast { position: fixed; z-index: 3000; left: 50%; bottom: 25px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 11px 16px; border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 12px; font-weight: 700; transition: .22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 850px) {
  .topbar { height: 67px; padding: 0 16px; grid-template-columns: auto 1fr; }
  .brand > span:last-child, .user-chip { display: none; }
  .mode-switch { justify-self: end; }
  .mode-button { padding: 8px 12px; font-size: 12px; }
  #field-view { height: calc(100vh - 67px); }
  .map-title-card { top: 16px; left: 16px; min-width: 190px; padding: 16px; }
  .map-title-card h1 { font-size: 24px; }
  .map-control-button { top: 16px; right: 16px; }
  .legend { left: 16px; bottom: 80px; max-width: calc(100% - 32px); gap: 9px; }
  .new-job-button { right: 16px; bottom: 18px; }
  .dashboard-view { padding: 32px 16px 50px; }
  .dashboard-heading { align-items: start; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .dashboard-heading { display: grid; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { padding: 15px; }
  .metric-card strong { font-size: 24px; }
  .modal-card { padding: 24px 20px; }
}

/* Mobile field-agent flow */
.popup-meta { color: var(--muted); font-size: 11px; font-weight: 800; margin: -2px 0 8px; }
.popup-photo { display: block; margin-top: 10px; color: var(--green); font-size: 12px; font-weight: 800; }
.typed-marker .job-marker-pin { display: grid; place-items: center; width: 40px; height: 40px; }
.typed-marker .job-marker-pin span { transform: rotate(45deg); color: white; font-family: "Manrope", sans-serif; font-size: 16px; font-weight: 900; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.typed-marker .job-marker-pin::after { display: none; }
.current-location-dot { position: relative; width: 34px; height: 34px; border-radius: 50%; background: rgba(33, 118, 255, .18); animation: pulse-location 1.8s ease-out infinite; }
.current-location-dot span { position: absolute; inset: 9px; border: 3px solid white; border-radius: 50%; background: #2176ff; box-shadow: 0 2px 10px rgba(33,118,255,.5); }
@keyframes pulse-location { 0% { box-shadow: 0 0 0 0 rgba(33,118,255,.28); } 100% { box-shadow: 0 0 0 18px rgba(33,118,255,0); } }
.modal-step { display: none; }
.modal-step.active { display: block; }
.step-copy { margin-bottom: 18px; color: var(--muted); line-height: 1.45; }
.type-grid { display: grid; gap: 12px; }
.type-card { display: flex; align-items: center; gap: 13px; width: 100%; border: 1px solid #d9dfda; border-radius: 17px; padding: 16px; background: white; color: var(--ink); text-align: left; box-shadow: 0 8px 20px rgba(24,44,37,.06); }
.type-card.selected, .type-card:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(31,114,82,.11); outline: none; }
.type-icon, .type-mini { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; background: var(--ink); color: white; font-family: "Manrope", sans-serif; font-weight: 900; }
.type-card strong { font: 800 18px/1 "Manrope", sans-serif; }
.text-button { margin: -6px 0 16px; border: 0; background: transparent; color: var(--green); font-weight: 800; padding: 0; }
.photo-preview { height: 150px; margin: -4px 0 16px; border-radius: 14px; background-size: cover; background-position: center; border: 1px solid #d8ded9; }
.job-type-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; padding: 12px; border-radius: 14px; background: #edf2ee; }
.job-type-summary strong { margin-right: auto; }
.job-type-summary span:last-child { color: var(--muted); font-size: 12px; font-weight: 800; }
.job-photo-link { display: block; margin: -4px 0 16px; color: var(--green); font-weight: 800; }
.search-label { margin: -6px 0 18px; }
input[readonly] { background: #f2f5f1; color: var(--ink); font-weight: 800; }

@media (max-width: 850px) {
  .topbar { grid-template-columns: 1fr; justify-items: center; padding: 8px 12px; height: 76px; }
  .brand { display: none; }
  .mode-switch { width: 100%; justify-content: center; }
  .mode-button { flex: 1; }
  #field-view { height: calc(100vh - 76px); }
  .map-title-card { top: 12px; left: 12px; min-width: 0; width: calc(100% - 78px); padding: 13px 15px; border-radius: 16px; }
  .map-title-card h1 { font-size: 22px; }
  .map-control-button { top: 14px; right: 14px; width: 50px; height: 50px; border-radius: 18px; }
  .legend { display: none; }
  .new-job-button { left: 18px; right: 18px; bottom: 22px; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 58px; border-radius: 999px; font-size: 17px; background: #2176ff; }
  .new-job-button:hover { background: #155dcc; }
  .modal.open { align-items: end; padding: 0; }
  .modal-card { width: 100%; max-height: 88vh; border-radius: 24px 24px 0 0; padding: 26px 20px 22px; }
  .modal-card h2 { font-size: 25px; }
  .type-card { min-height: 72px; }
}

/* Auth, roles, and PWA polish */
html, body { overscroll-behavior: none; }
.login-screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #e2efe8, var(--cream)); }
.login-screen[hidden], .app-shell[hidden], [hidden] { display: none !important; }
.login-card { width: min(420px, 100%); padding: 28px; border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { margin-bottom: 22px; font-size: 34px; }
.login-card .brand-mark { margin-bottom: 18px; }
.login-help { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.small-button { border: 1px solid #ccd4ce; border-radius: 9px; padding: 7px 10px; background: white; color: var(--ink); font-size: 12px; font-weight: 800; }
.danger-button { border: 0; border-radius: 10px; padding: 10px 15px; background: #d95d54; color: white; font-weight: 800; }
.button-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user-form { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; align-items: end; }
.user-form label { margin-bottom: 0; }
.users-list { display: grid; gap: 8px; margin-top: 20px; }
.user-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid #e3e8e3; border-radius: 12px; background: #fbfcf8; }
.user-row span { color: var(--muted); font-size: 12px; font-weight: 700; }
.pm-edit label, .admin-edit label { margin-bottom: 16px; }

@media (max-width: 850px) {
  .user-chip { display: none; }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
  .new-job-button { bottom: max(22px, env(safe-area-inset-bottom)); }
  .user-form { grid-template-columns: 1fr; }
  .dashboard-heading .button-row { width: 100%; }
  .dashboard-heading .button-row button { flex: 1; }
}
