:root {
  --brand: #1b7340;
  --brand-dark: #114726;
  --brand-soft: #eaf6ef;
  --brand-mid: #c7e5d2;
  --ink: #0f172a;
  --muted: #475569;
  --subtle: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --purple: #7c3aed;
  --radius: 14px;
  --nav-w: 236px;
  --tab-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.48;
  min-height: 100dvh;
}

/* Shell Layout: Desktop Left Sidebar + Fluid Main; iPhone Sticky Bottom Tab Bar */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: var(--nav-w);
  background: linear-gradient(180deg, #0d3b20, #14532d);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
}

.brand-lockup {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.16);
  margin-bottom: 8px;
}
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: #fff; overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-title { font-size: 14.5px; font-weight: 800; letter-spacing: 0.3px; }
.brand-sub { font-size: 11px; opacity: 0.8; }

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: none; background: transparent; color: rgba(255,255,255,0.84);
  padding: 11px 12px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-btn.active { background: #ffffff; color: var(--brand-dark); font-weight: 800; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.nav-icon { font-size: 17px; width: 22px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 11.2px;
  color: rgba(255,255,255,0.82);
}
.conn-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,0.14); color: #fff;
}
.conn-pill.ok { background: rgba(34,197,94,0.28); color: #bbf7d0; }

/* Mobile Top Header & Bottom Tab Bar (Hidden on Desktop >= 960px) */
.mobile-header, .bottom-tabs { display: none; }

/* Main Workspace */
.main-area {
  margin-left: var(--nav-w);
  flex: 1;
  min-width: 0;
  padding: 20px 24px 48px;
}

.page-header {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 18px;
}
.page-header h1 { margin: 0; font-size: 22px; font-weight: 800; color: var(--brand-dark); }
.page-header p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

/* Live Sticky Total Strip */
.live-strip {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 18px;
  box-shadow: 0 8px 22px rgba(17, 71, 38, 0.2);
}
.live-price { font-size: 34px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.live-metrics { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.metric-chip {
  background: rgba(255,255,255,0.16); padding: 6px 11px; border-radius: 10px;
  font-size: 12.2px; font-weight: 700;
}
.metric-chip.warn { background: #dc2626; color: #fff; }
.metric-chip.ok { background: rgba(74, 222, 128, 0.24); color: #dcfce7; }

/* Cards & Responsive Grids */
.view-section { display: none; }
.view-section.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.card h2 {
  margin: 0 0 12px; font-size: 15.8px; color: var(--brand-dark);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding-bottom: 8px; border-bottom: 1.5px solid var(--brand-soft);
}
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--ink); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: 16px; align-items: start; }
.grid-eq-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 10px; }
.grid-2 > *, .grid-eq-2 > *, .grid-3 > *, .grid-form > * { min-width: 0; }

/* Form Elements (Touch-friendly >=42px height) */
label.fl { display: block; font-size: 11.8px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="number"], input[type="password"], input[type="tel"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1.2px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(27, 115, 64, 0.14);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 9px 15px; border-radius: 10px;
  font-size: 13.5px; font-weight: 700; cursor: pointer; border: none;
  transition: filter 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--brand), #15803d); color: #fff; box-shadow: 0 4px 12px rgba(21,128,61,0.22); }
.btn-blue { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; }
.btn-purple { background: linear-gradient(135deg, #6d28d9, #7c3aed); color: #fff; }
.btn-outline { background: #fff; color: var(--brand-dark); border: 1.5px solid var(--brand); }
.btn-ghost { background: #f1f5f9; color: var(--ink); border: 1px solid #cbd5e1; }
.btn-danger { background: var(--red-soft); color: var(--red); border: 1px solid #fca5a5; }
.btn-sm { min-height: 34px; padding: 5px 10px; font-size: 12.2px; border-radius: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Action Hero Tiles (Dashboard) */
.hero-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 18px; }
.action-tile {
  display: flex; align-items: center; gap: 13px;
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; cursor: pointer; text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.action-tile:hover { border-color: var(--brand); box-shadow: 0 6px 18px rgba(27,115,64,0.1); }
.tile-ico {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff;
}
.tile-title { font-size: 14.5px; font-weight: 800; color: var(--ink); }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Job List Rows */
.job-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 9px; background: #fff; cursor: pointer;
}
.job-row:hover { border-color: var(--brand); background: #fafdfb; }
.job-row.current { border: 2px solid var(--brand); background: var(--brand-soft); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; vertical-align: middle;
}
.b-green { background: #dcfce7; color: #166534; }
.b-blue { background: #dbeafe; color: #1d4ed8; }
.b-amber { background: #fef3c7; color: #92400e; }
.b-purple { background: #f3e8ff; color: #6b21a8; }
.b-gray { background: #e2e8f0; color: #334155; }

/* Interactive Satellite Map Container */
.map-shell {
  position: relative; width: 100%; max-width: 100%; height: 430px;
  border-radius: 12px; overflow: hidden; border: 1.5px solid #cbd5e1;
  background: #0f172a;
}
.map-shell canvas { width: 100%; height: 100%; display: block; }
.map-zoom-fab {
  position: absolute; top: 10px; right: 10px; z-index: 10;
  display: flex; flex-direction: column; gap: 6px;
}
.map-zoom-fab button {
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.25);
  background: rgba(15,23,42,0.82); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer;
}
.target-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.t-chip {
  padding: 6px 11px; border-radius: 999px; border: 1.5px solid #cbd5e1;
  background: #fff; font-size: 12.2px; font-weight: 700; cursor: pointer;
}
.t-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Upload Dropzones & Photo Grids */
.dropzone {
  border: 2px dashed #94a3b8; border-radius: 12px; padding: 22px 16px;
  text-align: center; background: #f8fafc; cursor: pointer; transition: 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }

.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px; margin-top: 12px;
}
.photo-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: #0f172a;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: rgba(220,38,38,0.92);
  color: #fff; font-weight: 800; cursor: pointer; font-size: 13px;
}

/* Accordion Service Editor Blocks */
.svc-block {
  border: 1.2px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; background: #fff;
}
.svc-block.on { border-color: #86efac; background: #fbfefc; }
.svc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.svc-toggle {
  display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 14px; cursor: pointer;
}
.svc-toggle input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; }
.svc-body { margin-top: 11px; padding-top: 10px; border-top: 1px dashed var(--line); }

.hedge-row {
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 9px;
}

/* Tables & Alerts */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 9px; background: var(--brand-soft); color: var(--brand-dark); border-bottom: 2px solid var(--brand-mid); }
td { padding: 8px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.alert {
  padding: 10px 13px; border-radius: 10px; font-size: 12.6px; margin-bottom: 8px;
  border-left: 4px solid;
}
.alert.amber { background: var(--amber-soft); border-color: var(--amber); color: #78350f; }
.alert.blue { background: var(--blue-soft); border-color: var(--blue); color: #1e3a8a; }
.alert.green { background: #ecfdf5; border-color: #10b981; color: #065f46; }
.alert.red { background: var(--red-soft); border-color: var(--red); color: #991b1b; }

.msg-box {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font-size: 12.8px; white-space: pre-wrap; margin-bottom: 8px;
}

/* Sticky Right Totals Column on Desktop */
.sticky-col { position: sticky; top: 16px; }

/* Address Confirmation Box */
.addr-confirm-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-radius: 10px; margin-top: 8px;
  background: #fffbeb; border: 1.5px solid #f59e0b; font-size: 12.6px;
}
.addr-confirm-bar.confirmed {
  background: #ecfdf5; border-color: #10b981; color: #065f46;
}

/* iPad Tablet Breakpoint (768px - 1060px) */
@media (max-width: 1060px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hero-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky-col { position: static; }
  :root { --nav-w: 204px; }
}

/* iPhone & Mobile Breakpoint (< 820px) */
@media (max-width: 820px) {
  html, body, .app-shell, .main-area { max-width: 100vw; overflow-x: hidden; }
  .sidebar { display: none; }
  .mobile-header {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 45;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    color: #fff;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.16);
  }
  .mobile-hdr-title { font-size: 15px; font-weight: 800; }
  .mobile-hdr-price {
    background: rgba(255,255,255,0.2); padding: 4px 10px; border-radius: 999px;
    font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums;
  }
  .main-area {
    margin-left: 0;
    width: 100%;
    padding: 12px 12px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  }
  .card { padding: 14px; max-width: 100%; overflow-wrap: anywhere; }
  .grid-eq-2 { grid-template-columns: minmax(0, 1fr); }
  .map-shell { height: 340px; }
  .live-price { font-size: 28px; }
  .bottom-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 4px 4px max(6px, env(safe-area-inset-bottom));
  }
  .tab-btn {
    border: none; background: transparent; color: var(--subtle);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 10.5px; font-weight: 700; padding: 6px 2px; cursor: pointer;
  }
  .tab-btn .t-ico { font-size: 19px; line-height: 1.1; }
  .tab-btn.active { color: var(--brand); }
}

@media (max-width: 600px) {
  .hero-actions { grid-template-columns: minmax(0, 1fr); }
  .grid-form { grid-template-columns: minmax(0, 1fr); }
  .job-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .page-header h1 { font-size: 19px; }
}
