:root{
  --paper:#F1EDE4;
  --ink:#232323;
  --asphalt:#26241F;
  --asphalt-2:#37342C;
  --steel:#79705F;
  --route:#D9531E;
  --route-ink:#7A2B0E;
  --flag:#E8A902;
  --flag-ink:#6B4E02;
  --gravel:#2E7D4F;
  --gravel-ink:#17462A;
  --hairline: rgba(35,35,35,0.14);
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0; height:100%; overflow:hidden;}
body{
  background:var(--asphalt);
  color:var(--ink);
  font-family:-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}

.display{
  font-family: Bahnschrift, "DIN Alternate", "Arial Narrow", "Segoe UI", sans-serif;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:0.02em;
}
.mono{
  font-family:"SFMono-Regular",Consolas,"Roboto Mono",Menlo,monospace;
  font-variant-numeric: tabular-nums;
}
.eyebrow{
  font-family: Bahnschrift, "DIN Alternate", "Arial Narrow", "Segoe UI", sans-serif;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:0.14em;
  font-size:11px;
  color:var(--steel);
}

button{ font-family:inherit; }

/* ================= LOGIN ================= */
.login{
  height:100dvh;
  display:flex;
  flex-direction:column;
  justify-content:center;
  padding: 36px 26px;
  max-width:420px;
  margin:0 auto;
  background:
    repeating-linear-gradient(135deg, rgba(35,35,35,0.03) 0 2px, transparent 2px 14px),
    var(--paper);
  gap:24px;
}
.login-mark{ display:flex; align-items:center; gap:12px; }
.login-flag{ width:30px; height:30px; flex:none; }
.wordmark{ font-size:30px; line-height:0.9; letter-spacing:0.01em; }
.login-eyebrow{ margin-top:6px; }
.login-copy{ color:var(--steel); font-size:14.5px; line-height:1.5; max-width:32ch; }

#loginForm{ display:flex; flex-direction:column; gap:16px; }
.field{ display:flex; flex-direction:column; gap:6px; }
.field label{ font-size:11px; font-weight:700; letter-spacing:0.1em; text-transform:uppercase; color:var(--steel); }
.field input{
  font: inherit; font-size:16px; padding:13px 14px; border-radius:3px;
  border:1.5px solid var(--hairline); background:#fff; color:var(--ink);
}
.field input:focus-visible{ outline:2.5px solid var(--route); outline-offset:1px; border-color:var(--route); }

.login-error{
  margin:0; color:var(--route-ink); background:#FBE3D6; border-radius:4px;
  padding:9px 11px; font-size:13px; font-weight:600;
}

.btn, .btn-ghost{
  font-family:inherit; cursor:pointer; border:none; border-radius:3px;
  text-decoration:none; text-align:center;
  display:inline-flex; align-items:center; justify-content:center;
}
.btn-primary{
  background:var(--route); color:#FCF3E8; font-weight:700; letter-spacing:0.06em;
  text-transform:uppercase; font-size:14px; padding:15px; box-shadow:0 3px 0 var(--route-ink);
}
.btn-primary:active{ transform:translateY(2px); box-shadow:0 1px 0 var(--route-ink); }
.btn-primary:focus-visible{ outline:2.5px solid var(--ink); outline-offset:2px; }
.btn-primary:disabled{ opacity:0.55; cursor:default; }

.login-hint{ color:var(--steel); font-size:12px; text-align:center; }
.login-hint b{ color:var(--ink); }

/* ================= APP SHELL ================= */
.app{ position:relative; height:100dvh; display:none; flex-direction:column; overflow:hidden; }
.app.active{ display:flex; }

.topbar{
  position:relative; z-index:5;
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px 12px; padding-top:calc(14px + env(safe-area-inset-top));
  background:var(--asphalt); color:var(--paper); flex:none;
}
.topbar .wordmark-sm{ font-size:16px; display:flex; align-items:center; gap:8px; }
.topbar .wordmark-sm svg{ width:16px; height:16px; }
.chip{
  display:flex; align-items:center; gap:7px; background:var(--asphalt-2); border:none; color:inherit;
  border-radius:20px; padding:6px 11px 6px 8px; font-size:11.5px; font-weight:600; cursor:pointer;
}
.chip:focus-visible{ outline:2px solid var(--paper); outline-offset:2px; }
.chip .dot{ width:7px; height:7px; border-radius:50%; background:var(--flag); }
.layer-toggle{ display:flex; gap:2px; background:var(--asphalt-2); border-radius:20px; padding:2px; margin-left:8px; }
.layer-toggle button{
  background:transparent; border:none; color:#C9C2B2; font-size:10.5px; font-weight:700;
  letter-spacing:0.06em; padding:5px 9px; border-radius:16px; cursor:pointer;
}
.layer-toggle button.on{ background:var(--paper); color:var(--ink); }
.layer-toggle button:focus-visible{ outline:2px solid var(--paper); outline-offset:1px; }

.map-wrap{ position:relative; flex:1; min-height:0; isolation:isolate; }
.map{ position:absolute; inset:0; background:var(--asphalt-2); }

/* flag marker */
.flag-pin{ filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35)); }
.flag-pin .flagcloth{ transform-origin: 3px 4px; animation: sway 3.4s ease-in-out infinite; }
@keyframes sway{ 0%,100%{ transform:rotate(0deg); } 50%{ transform:rotate(-7deg); } }
@media (prefers-reduced-motion: reduce){ .flag-pin .flagcloth{ animation:none; } }
.flag-pin.me{ filter: drop-shadow(0 0 6px rgba(217,83,30,0.9)); }

.locate-btn{
  position:absolute; right:14px; bottom:14px; z-index:1001;
  width:42px; height:42px; border-radius:50%; background:var(--paper); border:none;
  box-shadow:0 3px 8px rgba(0,0,0,0.35); display:flex; align-items:center; justify-content:center; cursor:pointer;
}
.locate-btn:focus-visible{ outline:2.5px solid var(--route); outline-offset:2px; }

.fab{
  position:absolute; left:16px; bottom:14px; z-index:1001;
  display:flex; align-items:center; gap:8px; background:var(--route); color:#FCF3E8; border:none;
  border-radius:24px; padding:12px 18px 12px 14px; font-weight:700; font-size:12.5px;
  letter-spacing:0.06em; text-transform:uppercase;
  box-shadow: 0 3px 0 var(--route-ink), 0 8px 18px rgba(0,0,0,0.3); cursor:pointer;
}
.fab:active{ transform:translateY(2px); box-shadow:0 1px 0 var(--route-ink); }
.fab:focus-visible{ outline:2.5px solid var(--ink); outline-offset:2px; }

.tagbanner{
  position:absolute; top:12px; left:50%; transform:translateX(-50%); z-index:1001;
  background:var(--asphalt); color:var(--paper); font-size:12.5px; font-weight:600;
  padding:9px 14px; border-radius:20px; box-shadow:0 4px 12px rgba(0,0,0,0.3);
  white-space:nowrap;
}
.tagbanner button{ background:none; border:none; color:var(--flag); font-weight:700; cursor:pointer; padding:0; margin-left:4px; text-decoration:underline; }

.proximity-banner{
  position:absolute; top:12px; left:12px; right:12px; z-index:1002;
  background:var(--paper); border-radius:12px; border-left:4px solid var(--gravel);
  box-shadow:0 8px 20px rgba(0,0,0,0.35); padding:12px 14px 12px 12px;
  display:flex; align-items:center; gap:12px;
}
.proximity-text{ flex:1; min-width:0; }
.proximity-text p:last-child{ margin:0; font-size:13.5px; font-weight:600; color:var(--ink); }
.proximity-actions{ display:flex; align-items:center; gap:4px; flex:none; }
.proximity-actions .btn-primary{ padding:10px 14px; font-size:11px; box-shadow:none; white-space:nowrap; }
.proximity-actions .icon-btn{ color:var(--steel); font-size:20px; line-height:1; }

/* ---- bottom sheet ---- */
.sheet{
  position:relative; z-index:5; background:var(--paper); border-radius:16px 16px 0 0;
  box-shadow: 0 -8px 22px rgba(20,16,8,0.22); display:flex; flex-direction:column;
  max-height:64%; flex:none; transition: max-height 0.32s cubic-bezier(.3,.9,.3,1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.collapsed{ max-height:118px; }
.handle{ width:36px; height:4px; border-radius:2px; background:var(--hairline); margin:9px auto 4px; flex:none; }
.sheet-head{ display:flex; align-items:center; justify-content:space-between; padding:2px 16px 8px; flex:none; cursor:pointer; background:none; border:none; width:100%; text-align:left; }
.sheet-counts{ display:flex; gap:8px; margin-top:4px; }
.count-chip{ display:flex; align-items:center; gap:5px; font-size:11.5px; font-weight:600; color:var(--ink); }
.count-chip .sw{ width:9px; height:9px; border-radius:2px; }
.sheet-toggle-icon{ color:var(--steel); font-size:10px; }

.sheet-filters{ display:flex; gap:8px; padding:0 16px 8px; flex:none; }
.filter-chip{
  border:1.5px solid var(--hairline); background:#fff; color:var(--steel); border-radius:16px;
  padding:5px 11px; font-size:11px; font-weight:700; letter-spacing:0.03em; text-transform:uppercase; cursor:pointer;
}
.filter-chip.on{ border-color:var(--route); color:var(--route-ink); background:#FBE3D6; }

.ticket-list{ overflow-y:auto; padding:0 10px 10px; flex:1; display:flex; flex-direction:column; gap:6px; }
.ticket-empty{ text-align:center; color:var(--steel); font-size:13px; padding:24px 10px; }
.ticket{
  display:flex; gap:11px; padding:11px 10px; border-radius:8px; background:#fff;
  border:1px solid var(--hairline); text-align:left; cursor:pointer; color:var(--ink); width:100%;
}
.ticket:focus-visible{ outline:2.5px solid var(--route); outline-offset:1px; }
.stripe{ width:5px; border-radius:3px; flex:none; }
.stripe.open{ background:var(--route); }
.stripe.claimed{ background:var(--flag); }
.stripe.completed{ background:var(--gravel); }
.ticket-body{ flex:1; min-width:0; }
.ticket-note{ font-size:14px; line-height:1.35; margin:0 0 4px; }
.ticket-meta{ display:flex; flex-wrap:wrap; gap:6px 10px; font-size:11.5px; color:var(--steel); }
.ticket-meta .status-word{ font-weight:700; letter-spacing:0.04em; }
.status-word.open{ color:var(--route-ink); }
.status-word.claimed{ color:var(--flag-ink); }
.status-word.completed{ color:var(--gravel-ink); }
.ticket-dist{ font-family:"SFMono-Regular",Consolas,"Roboto Mono",monospace; }

/* ---- detail (work order) ---- */
.detail{
  position:absolute; inset:0; z-index:8; background:var(--paper); display:flex; flex-direction:column;
  transform:translateY(100%); transition: transform 0.3s cubic-bezier(.3,.9,.3,1);
}
.detail.open{ transform:translateY(0); }
.detail-head{
  display:flex; align-items:center; justify-content:space-between; padding:14px 16px;
  padding-top:calc(14px + env(safe-area-inset-top));
  background:var(--asphalt); color:var(--paper); flex:none;
}
.icon-btn{
  background:none; border:none; color:inherit; cursor:pointer; width:30px; height:30px;
  display:flex; align-items:center; justify-content:center; border-radius:50%;
}
.icon-btn:focus-visible{ outline:2px solid var(--paper); }
.ticket-no{ font-size:12px; }

.detail-body{ padding:20px 20px 24px; overflow-y:auto; flex:1; }
.status-stripe{
  display:inline-flex; align-items:center; gap:7px; padding:5px 12px 5px 9px; border-radius:20px;
  font-size:11.5px; font-weight:700; letter-spacing:0.06em; text-transform:uppercase; margin-bottom:16px;
}
.status-stripe.open{ background:#FBE3D6; color:var(--route-ink); }
.status-stripe.claimed{ background:#FBECC4; color:var(--flag-ink); }
.status-stripe.completed{ background:#D7EADB; color:var(--gravel-ink); }
.status-stripe .sdot{ width:8px; height:8px; border-radius:50%; background:currentColor; }

.detail-note{ font-size:19px; line-height:1.4; margin:0 0 22px; }
.detail-note.empty{ color:var(--steel); font-style:italic; font-size:15px; }

.field-row{ display:flex; justify-content:space-between; gap:14px; padding:11px 0; border-top:1px solid var(--hairline); font-size:13.5px; }
.field-row:last-of-type{ border-bottom:1px solid var(--hairline); }
.field-row dt{ color:var(--steel); font-weight:600; letter-spacing:0.03em; }
.field-row dd{ margin:0; font-family:"SFMono-Regular",Consolas,"Roboto Mono",monospace; text-align:right; }

.detail-actions{ display:flex; gap:10px; margin-top:24px; flex-wrap:wrap; }
.detail-actions .btn-primary, .detail-actions .btn-ghost{ flex:1; min-width:120px; }
.btn-ghost{
  background:transparent; border:1.5px solid var(--hairline); color:var(--ink); font-weight:700;
  text-transform:uppercase; letter-spacing:0.05em; font-size:12.5px; padding:13px; border-radius:3px; cursor:pointer;
}
.btn-ghost:focus-visible{ outline:2.5px solid var(--ink); outline-offset:2px; }
.btn-ghost.danger{ border-color:#DDBFB4; color:var(--route-ink); }

/* ---- tag sheet ---- */
.tagsheet{
  position:absolute; left:0; right:0; bottom:0; z-index:9; background:var(--paper);
  border-radius:16px 16px 0 0; box-shadow:0 -8px 22px rgba(20,16,8,0.28); padding:6px 20px 22px;
  padding-bottom:calc(22px + env(safe-area-inset-bottom));
  transform:translateY(100%); transition: transform 0.3s cubic-bezier(.3,.9,.3,1);
}
.tagsheet.open{ transform:translateY(0); }
.tagsheet .handle{ cursor:pointer; }
.tagsheet h2{ font-size:13px; margin:14px 0 4px; color:var(--steel); }
.tag-methods{ display:flex; gap:8px; margin:12px 0 10px; }
.method-btn{
  flex:1; padding:14px 8px; border-radius:8px; border:1.5px solid var(--hairline); background:#fff;
  font-weight:700; font-size:12px; letter-spacing:0.03em; text-transform:uppercase; cursor:pointer; color:var(--ink);
}
.method-btn.sel{ border-color:var(--route); background:#FBE3D6; color:var(--route-ink); }
.method-btn:focus-visible{ outline:2.5px solid var(--route); outline-offset:1px; }
.tag-status{ min-height:16px; font-size:12px; color:var(--steel); margin:0 0 4px; }
.tag-status.err{ color:var(--route-ink); font-weight:600; }
textarea{
  width:100%; font:inherit; font-size:14.5px; padding:12px; border-radius:6px; border:1.5px solid var(--hairline);
  resize:none; height:64px; background:#fff; color:var(--ink);
}
textarea:focus-visible{ outline:2.5px solid var(--route); outline-offset:1px; }

.settings-row{ margin:14px 0 6px; }
.settings-row label{
  display:flex; justify-content:space-between; align-items:baseline;
  font-size:13px; font-weight:600; color:var(--ink); margin-bottom:8px;
}
.settings-row input[type="range"]{ width:100%; accent-color:var(--route); }
#intervalControl.disabled{ opacity:0.4; pointer-events:none; }

.toast{
  position:fixed; left:50%; bottom:24px; transform:translateX(-50%); z-index:50;
  background:var(--asphalt); color:var(--paper); padding:11px 18px; border-radius:20px;
  font-size:13px; font-weight:600; box-shadow:0 6px 18px rgba(0,0,0,0.35);
}

.sr-only{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }

/* Leaflet chrome adjustments to match the palette */
.leaflet-control-attribution{
  background:rgba(241,237,228,0.85) !important; font-size:9.5px !important;
}
