:root {
  --black: #0b1526;
  --dark: #142744;
  --navy: #0a1628;
  --navy-mid: #122845;
  --navy-light: #1a3a63;
  --panel: #ffffff;
  --gold: #1d9d5c;
  --gold-dark: #157a46;
  --bg: #f3f4f6;
  --text: #23252b;
  --muted: #7a7f8a;
  --green: #1d9d5c;
  --red: #c94040;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--navy); }
html.light { background: #f5f7fb; }
body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-mid) 55%, var(--navy-light) 100%) fixed;
  min-height: 100vh;
  color: var(--text);
}
.hidden { display: none !important; }

/* buttons */
.btn { border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; background: var(--dark); color: #fff; transition: 0.15s; }
.btn:hover { opacity: 0.88; }
.btn.gold { background: var(--gold); color: #fff; }
.btn.ghost { background: transparent; color: #cfd2d8; border: 1px solid #3a3d45; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { background: var(--red); }
.w100 { width: 100%; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-mid) 60%, #23345c 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 40px 36px; width: 360px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
.login-logo { width: 170px; margin-bottom: 6px; }
.login-card h2 { font-size: 18px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin-bottom: 22px; }
.login-card input { width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1px solid #d8dbe0; border-radius: 8px; font-size: 15px; }
.login-card input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* shell — fixed sidebar on desktop, drawer + top bar on mobile */
.app { display: flex; min-height: 100vh; }
.topbar { display: none; }
.nav-back { display: none; }
/* theme-aware logos */
html:not(.light) .logo-light { display: none; }
html.light .logo-dark { display: none; }
.sidebar { width: 230px; background: rgba(6,13,26,0.72); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-right: 1px solid rgba(29,157,92,0.25); display: flex; flex-direction: column; padding: 0 16px 22px; position: fixed; top: 0; bottom: 0; z-index: 1000; }
.side-logo { display: block; width: calc(100% + 32px); margin: 0 -16px 18px; background: #fff; padding: 18px 40px 20px; }
html:not(.light) .side-logo { background: transparent; width: 165px; margin: 26px auto 20px; padding: 0; }
.sidebar nav a { display: block; color: #cfd2d8; text-decoration: none; padding: 11px 14px; border-radius: 8px; margin-bottom: 4px; font-size: 14.5px; font-weight: 500; }
.sidebar nav a { transition: background 0.2s, transform 0.2s; }
.sidebar nav a:hover { background: rgba(255,255,255,0.08); transform: translateX(3px); }
.sidebar nav a.active { background: var(--gold); color: #fff; }
.side-bottom { margin-top: auto; }
.whoami { color: #8a8f9a; font-size: 12.5px; margin-bottom: 10px; text-align: center; }
.main { margin-left: 230px; flex: 1; padding: 28px 32px; }

/* headers / cards */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { font-size: 22px; color: #fff; letter-spacing: 0.3px; text-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.main > .muted { color: #9fb0c8; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--panel); border-radius: var(--radius); padding: 18px 20px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(0,0,0,0.35); }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-top: 3px; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,0.25); padding: 20px; margin-bottom: 20px; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.panel:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,0.35); }
.panel h3 { font-size: 15px; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }

/* critical Leaflet layout rules — fallback in case the CDN stylesheet fails to load */
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow, .leaflet-tile-container,
.leaflet-pane > svg, .leaflet-pane > canvas, .leaflet-zoom-box, .leaflet-image-layer, .leaflet-layer { position: absolute; left: 0; top: 0; }
.leaflet-container { overflow: hidden; }
.leaflet-container .leaflet-tile { max-width: none !important; max-height: none !important; width: auto; padding: 0; }

/* home map */
.map-card { position: relative; cursor: pointer; }
#homemap { height: 380px; border-radius: 8px; z-index: 1; }
.map-hint { position: absolute; top: 30px; right: 30px; z-index: 500; background: rgba(23,24,28,0.85); color: #fff; font-size: 12.5px; padding: 6px 12px; border-radius: 6px; pointer-events: none; }
.map-full { position: fixed; inset: 0; z-index: 2000; background: #000; }
#bigmap { height: 100%; width: 100%; }
.map-close { position: absolute; top: 16px; right: 16px; z-index: 2100; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.map-popup a { font-weight: 700; color: var(--gold-dark); }

/* job cards */
.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.job-card { background: #fff; border-radius: var(--radius); padding: 18px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.job-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0,0,0,0.38); }
.job-card h4 { font-size: 16px; margin-bottom: 6px; }
.job-card .addr { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.job-meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.job-meta b { color: var(--text); }
.badge { display: inline-block; background: #dcf0e5; color: var(--gold-dark); font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid #eceef1; }
td { padding: 10px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
tr.ordered td { color: #9aa0ab; }
tr.ordered td .mat-name { text-decoration: line-through; }
td a { color: var(--gold-dark); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.right { text-align: right; }
.totals-row td { font-weight: 700; border-top: 2px solid #e3e5e9; font-size: 15px; }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input.f, select.f { width: 100%; padding: 10px 12px; border: 1px solid #d8dbe0; border-radius: 8px; font-size: 14px; background: #fff; }
input.f:focus, select.f:focus { outline: 2px solid var(--gold); border-color: transparent; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(10,10,12,0.55); z-index: 1500; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; padding: 26px; width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-card h2 { font-size: 18px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* notes */
.note-row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid #f0f1f4; }
.note-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--gold); }
.note-row.done .note-text { text-decoration: line-through; color: #9aa0ab; }
.note-text { flex: 1; font-size: 14px; }
.note-add { display: flex; gap: 10px; margin-top: 12px; }
.note-add input { flex: 1; }
.del { background: none; border: none; color: #c2c6cd; cursor: pointer; font-size: 15px; }
.del:hover { color: var(--red); }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-item { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: pointer; background: #edf0f3; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s ease; }
.photo-item:hover img { transform: scale(1.04); }
.photo-del { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,0.55); color: #fff; border: none; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: 13px; line-height: 1; }
.photo-del:hover { background: var(--red); }
.photo-tag { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,0.72)); color: #fff; font-size: 12px; font-weight: 600; padding: 14px 8px 6px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-tag:hover { text-decoration: underline; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(4,8,15,0.94); z-index: 3000; display: flex; align-items: center; justify-content: center; }
.lb-img { max-width: 92vw; max-height: 84vh; border-radius: 8px; box-shadow: 0 12px 44px rgba(0,0,0,0.6); }
.lb-btn { position: fixed; background: rgba(255,255,255,0.14); color: #fff; border: none; border-radius: 50%; width: 46px; height: 46px; font-size: 26px; line-height: 1; cursor: pointer; z-index: 3100; transition: background 0.15s; }
.lb-btn:hover { background: rgba(255,255,255,0.3); }
.lb-close { top: 16px; right: 16px; font-size: 18px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-count { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); color: #d6dce6; font-size: 13.5px; letter-spacing: 1px; }

/* file chips */
.file-chip { display: inline-flex; align-items: center; gap: 8px; background: #eaf6ef; border: 1px solid #c6e5d3; color: var(--gold-dark); font-weight: 600; font-size: 13.5px; padding: 8px 14px; border-radius: 8px; text-decoration: none; margin-right: 10px; margin-bottom: 8px; }
.file-chip:hover { background: #ddf0e6; }
.muted { color: var(--muted); font-size: 13.5px; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.info-grid .k { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.info-grid .v { font-size: 15px; font-weight: 600; margin-top: 3px; }

/* ---------- dark mode: dark cards instead of white ---------- */
html:not(.light) .stat, html:not(.light) .panel, html:not(.light) .job-card {
  background: #16243d; border: 1px solid rgba(255,255,255,0.07); color: #e9eef6;
}
html:not(.light) .panel h3, html:not(.light) .stat .lbl,
html:not(.light) .job-card .addr, html:not(.light) .job-meta,
html:not(.light) .info-grid .k, html:not(.light) .panel .muted,
html:not(.light) .panel.muted, html:not(.light) .panel label.f { color: #93a3ba; }
html:not(.light) .job-meta b { color: #e9eef6; }
html:not(.light) th { color: #93a3ba; border-bottom-color: rgba(255,255,255,0.14); }
html:not(.light) td { border-bottom-color: rgba(255,255,255,0.08); }
html:not(.light) .totals-row td { border-top-color: rgba(255,255,255,0.16); }
html:not(.light) tr.ordered td { color: #6d7c92; }
html:not(.light) td a { color: #3fc07f; }
html:not(.light) .note-row { border-bottom-color: rgba(255,255,255,0.08); }
html:not(.light) .note-row.done .note-text { color: #6d7c92; }
html:not(.light) .del { color: #6d7c92; }
html:not(.light) .panel input.f, html:not(.light) .panel select.f {
  background: #0f1a2e; border-color: rgba(255,255,255,0.16); color: #e9eef6;
}
html:not(.light) .badge { background: rgba(29,157,92,0.22); color: #48c684; }
html:not(.light) .file-chip { background: rgba(29,157,92,0.12); border-color: rgba(29,157,92,0.35); color: #48c684; }
html:not(.light) .file-chip:hover { background: rgba(29,157,92,0.22); }
html:not(.light) .photo-item { background: #0f1a2e; }

/* ---------- light mode ---------- */
html.light body { background: linear-gradient(160deg, #f5f7fb 0%, #eaeef6 55%, #dfe6f2 100%) fixed; }
html.light .page-head h1 { color: var(--text); text-shadow: none; }
html.light .main > .muted { color: var(--muted); }
html.light .stat, html.light .panel, html.light .job-card { box-shadow: 0 1px 4px rgba(0,0,0,0.07); }
html.light .stat:hover, html.light .panel:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.13); }
html.light .job-card:hover { box-shadow: 0 10px 24px rgba(0,0,0,0.15); }
html.light .sidebar { background: #fff; backdrop-filter: none; border-right: 1px solid #e3e7ee; }
html.light .sidebar nav a { color: #3c4250; }
html.light .sidebar nav a:hover { background: #eef1f6; }
html.light .sidebar nav a.active { background: var(--gold); color: #fff; }
html.light .side-bottom .btn.ghost { color: #4a4f5a; border-color: #c9cdd5; }
html.light .whoami { color: #7a7f8a; }

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  .app { display: block; }

  /* top bar with hamburger — blurry dark, white in light mode */
  .topbar { display: flex; align-items: center; position: fixed; top: 0; left: 0; right: 0; height: calc(72px + env(safe-area-inset-top)); background: rgba(6,13,26,0.72); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 1100; padding: env(safe-area-inset-top) 12px 0; box-shadow: 0 1px 6px rgba(0,0,0,0.25); }
  html.light .topbar { background: rgba(255,255,255,0.88); }
  .menu-btn { background: none; border: none; color: #fff; font-size: 26px; padding: 8px 10px; cursor: pointer; line-height: 1; }
  html.light .menu-btn { color: #17181c; }
  .top-logo { height: 64px; position: absolute; left: 50%; top: calc(4px + env(safe-area-inset-top)); transform: translateX(-50%); }

  /* sidebar becomes a slide-in drawer */
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; width: 250px; padding-top: calc(86px + env(safe-area-inset-top)); box-shadow: 4px 0 20px rgba(0,0,0,0.35); }
  .sidebar.open { transform: translateX(0); }
  .nav-back.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 900; }
  .side-logo { display: none; } /* top bar already shows the logo on mobile */
  .sidebar nav a { padding: 14px; font-size: 16px; }

  .main { margin-left: 0; padding: calc(94px + env(safe-area-inset-top)) 14px 24px; }

  /* headers & cards */
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head h1 { font-size: 19px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat .num { font-size: 20px; }
  .panel { padding: 14px; }

  /* maps */
  #homemap { height: 300px; width: 100%; }
  .map-card { overflow: hidden; }
  .map-hint { top: 24px; right: 24px; }
  .map-close { top: auto; bottom: 24px; right: 50%; transform: translateX(50%); }

  /* tables scroll sideways instead of squishing (but never the map panel) */
  .panel:not(.map-card) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }

  /* forms & modal */
  .form-grid { grid-template-columns: 1fr; }
  input.f, select.f, .login-card input { font-size: 16px; } /* stops iOS auto-zoom */
  .btn { padding: 12px 16px; }
  .btn.small { padding: 8px 12px; font-size: 13px; }
  .modal-back { padding: 10px; align-items: flex-end; }
  .modal-card { width: 100%; border-radius: 14px 14px 0 0; max-height: 92vh; padding: 20px 16px; }

  /* login */
  .login-card { width: 100%; max-width: 360px; padding: 30px 22px; margin: 0 14px; }

  /* job cards single column */
  .job-grid { grid-template-columns: 1fr; }
  .file-chip { display: flex; margin-right: 0; }
}
