:root {
  --navy-950: #071728;
  --navy-900: #0b2239;
  --navy-800: #123552;
  --navy-700: #1c496d;
  --orange: #f47b20;
  --orange-dark: #d95d08;
  --orange-soft: #fff1e7;
  --ink: #142333;
  --muted: #657383;
  --line: #dce3e8;
  --panel: #ffffff;
  --surface: #f5f7f8;
  --green: #2d9b70;
  --red: #cf4444;
  --shadow: 0 12px 34px rgba(7, 23, 40, .14);
  --sidebar-width: 390px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--surface); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 22px;
  color: white;
  background: var(--navy-900);
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative;
  z-index: 1002;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1; }
.brand strong { font-size: 20px; letter-spacing: -.6px; }
.brand small { font-size: 8px; letter-spacing: 3px; color: #a7bac9; margin-top: 6px; }
.brand-mark { width: 35px; height: 35px; position: relative; transform: rotate(-8deg); }
.brand-mark i { position: absolute; display: block; background: var(--orange); border-radius: 2px; transform: skewY(-28deg); }
.brand-mark i:nth-child(1) { width: 10px; height: 18px; left: 3px; top: 14px; }
.brand-mark i:nth-child(2) { width: 10px; height: 28px; left: 14px; top: 6px; }
.brand-mark i:nth-child(3) { width: 10px; height: 18px; right: 0; top: 2px; }

.project-title-wrap { display: flex; flex-direction: column; border-left: 1px solid rgba(255,255,255,.14); padding-left: 24px; min-width: 0; }
.project-title-wrap strong { max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.eyebrow { color: var(--orange); font-size: 9px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; }
.save-state { color: #8da3b4; font-size: 10px; margin-top: 2px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.button, .icon-button, .text-button, .report-action, .map-toolbar button, .tab { border: 0; cursor: pointer; transition: .18s ease; }
.button { border-radius: 7px; min-height: 38px; padding: 0 16px; font-size: 12px; font-weight: 750; letter-spacing: .1px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button-primary { background: var(--orange); color: white; box-shadow: 0 4px 14px rgba(244,123,32,.2); }
.button-primary:hover { background: var(--orange-dark); transform: translateY(-1px); }
.button-secondary { background: var(--navy-900); color: white; }
.button-secondary:hover { background: var(--navy-700); }
.button-ghost { background: rgba(255,255,255,.08); color: inherit; border: 1px solid rgba(255,255,255,.14); }
.button-ghost:hover { background: rgba(255,255,255,.14); }
.button-danger { color: var(--red); background: #fff2f2; }
.button-danger.ghost { margin-right: auto; }
.wide { width: 100%; }
.icon-button { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.08); color: white; font-weight: 800; }
.icon-button:hover { background: rgba(255,255,255,.16); }
.mobile-only { display: none; }

.metrics {
  height: 74px;
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  background: white;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1001;
}
.metrics article { display: flex; align-items: center; gap: 13px; padding: 10px 22px; border-right: 1px solid var(--line); min-width: 0; }
.metrics article:last-child { border-right: 0; }
.metrics article div { min-width: 0; display: flex; flex-direction: column; }
.metrics small { color: var(--muted); font-size: 9px; font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.metrics strong { font-size: 17px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-icon { width: 31px; height: 31px; flex: 0 0 31px; border-radius: 9px; background: var(--orange-soft); position: relative; }
.metric-icon::before, .metric-icon::after { content: ""; position: absolute; }
.line-icon::before { width: 19px; height: 2px; background: var(--orange); transform: rotate(-26deg); left: 6px; top: 15px; }
.line-icon::after { width: 5px; height: 5px; background: var(--orange); border-radius: 50%; left: 4px; top: 19px; box-shadow: 17px -9px 0 var(--orange); }
.area-icon::before { inset: 7px; border: 2px dashed var(--orange); transform: skew(-8deg); }
.cut-icon::before { left: 6px; right: 6px; bottom: 7px; height: 11px; background: var(--orange); clip-path: polygon(0 0, 50% 100%, 100% 0); }
.fill-icon::before { left: 6px; right: 6px; bottom: 7px; height: 11px; border: 2px solid var(--orange); clip-path: polygon(0 100%, 50% 0, 100% 100%); }
.rock-icon::before { width: 17px; height: 15px; background: #6d7b89; left: 7px; top: 8px; clip-path: polygon(18% 0, 80% 10%, 100% 70%, 70% 100%, 8% 83%, 0 30%); }

.workspace { display: flex; height: calc(100% - 146px); min-height: 0; }
.sidebar { width: var(--sidebar-width); flex: 0 0 var(--sidebar-width); background: white; border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 1000; box-shadow: 5px 0 22px rgba(7,23,40,.05); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); background: #fafbfc; }
.tab { background: transparent; height: 48px; color: var(--muted); font-size: 11px; font-weight: 760; position: relative; }
.tab.active { color: var(--navy-900); background: white; }
.tab.active::after { content: ""; position: absolute; left: 26%; right: 26%; bottom: 0; height: 3px; background: var(--orange); border-radius: 3px 3px 0 0; }
.panel { display: none; flex-direction: column; overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: #cbd5dc transparent; }
.panel.active { display: flex; }
.sidebar-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sidebar-section.compact { padding-top: 13px; padding-bottom: 13px; }
.sidebar-section.grow { min-height: 240px; }
.sidebar-section > label:first-child, .field > span { display: block; color: var(--muted); font-size: 9px; font-weight: 720; margin-bottom: 5px; letter-spacing: .2px; }
.input { width: 100%; height: 36px; border: 1px solid #d7e0e6; border-radius: 6px; background: white; color: var(--ink); padding: 0 10px; font-size: 12px; outline: none; }
textarea.input { height: auto; min-height: 88px; resize: vertical; padding-top: 9px; line-height: 1.5; }
.input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(244,123,32,.1); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; }
.field.full { display: block; margin-bottom: 13px; }

.import-card { margin: 13px 18px 0; padding: 13px; border: 1px dashed #f4a36b; border-radius: 9px; background: var(--orange-soft); display: flex; align-items: center; gap: 12px; cursor: pointer; }
.import-card.dragover { background: #ffe0c9; border-color: var(--orange); transform: scale(.99); }
.import-symbol { width: 31px; height: 31px; border-radius: 50%; display: grid; place-items: center; color: white; background: var(--orange); font-weight: 900; }
.import-card div:last-child { display: flex; flex-direction: column; }
.import-card strong { font-size: 11px; }
.import-card small { color: var(--muted); font-size: 9px; margin-top: 2px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.section-heading h2, .intro-block h2, .quantity-card h2, .demo-card h2 { margin: 2px 0 0; font-size: 13px; }
.text-button { background: transparent; color: var(--orange-dark); font-size: 9px; font-weight: 750; padding: 5px; }
.count-badge { min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; background: #edf2f5; border-radius: 99px; font-size: 10px; font-weight: 800; color: var(--navy-700); }

.legend-list { display: grid; gap: 6px; }
.legend-item { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.legend-item:hover { background: var(--surface); }
.legend-item.hidden-layer { opacity: .38; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.legend-label { font-size: 10px; font-weight: 670; }
.legend-count { font-size: 9px; color: var(--muted); }
.search-box { height: 34px; border: 1px solid var(--line); background: #fafbfc; border-radius: 6px; display: flex; align-items: center; padding: 0 9px; gap: 7px; margin-bottom: 9px; }
.search-box span { color: var(--muted); font-size: 18px; transform: rotate(-15deg); }
.search-box input { border: 0; outline: 0; background: transparent; width: 100%; font-size: 10px; color: var(--ink); }
.feature-list { display: grid; gap: 5px; }
.feature-row { display: grid; grid-template-columns: 9px minmax(0,1fr) auto; align-items: center; gap: 9px; padding: 9px 8px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.feature-row:hover { background: var(--surface); border-color: var(--line); }
.feature-row .dot { width: 8px; height: 8px; border-radius: 50%; }
.feature-row div { min-width: 0; display: flex; flex-direction: column; }
.feature-row strong { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feature-row small { color: var(--muted); font-size: 8px; margin-top: 2px; }
.feature-row .measure { font-size: 9px; font-weight: 750; color: var(--navy-700); }
.empty-state { text-align: center; color: var(--muted); padding: 25px 8px; }
.empty-state p { margin: 0 0 4px; font-size: 11px; }
.empty-state small { font-size: 9px; }

.intro-block { background: linear-gradient(135deg, var(--navy-950), var(--navy-700)); color: white; }
.intro-block h2 { font-size: 16px; margin-top: 4px; }
.intro-block p, .demo-card p { color: #b8c7d2; font-size: 10px; line-height: 1.55; margin: 7px 0 0; }
.form-card { background: #f9fafb; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 9px; }
.data-table th { color: var(--muted); text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid #edf1f3; }
.data-table button { border: 0; background: transparent; color: var(--red); cursor: pointer; font-size: 13px; }
.table-empty { text-align: center !important; color: var(--muted); padding: 18px !important; }
.quantity-card { background: #fffaf6; }
.calc-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.calc-preview > div { background: white; border: 1px solid #f0dacb; border-radius: 7px; padding: 9px; display: flex; flex-direction: column; }
.calc-preview small { color: var(--muted); font-size: 8px; }
.calc-preview strong { color: var(--orange-dark); font-size: 13px; margin-top: 2px; }
.quantity-list { display: grid; gap: 7px; }
.quantity-row { border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 7px; padding: 9px 8px; display: grid; grid-template-columns: 1fr auto; align-items: center; }
.quantity-row strong { display: block; font-size: 10px; }
.quantity-row small { color: var(--muted); font-size: 8px; }
.quantity-row button { border: 0; background: transparent; color: var(--red); cursor: pointer; }

.report-grid { display: grid; gap: 8px; }
.report-action { width: 100%; display: flex; align-items: center; gap: 11px; text-align: left; border: 1px solid var(--line); background: white; border-radius: 8px; padding: 11px; }
.report-action:hover { border-color: var(--orange); box-shadow: 0 5px 16px rgba(7,23,40,.07); transform: translateY(-1px); }
.report-action > span:last-child { display: flex; flex-direction: column; }
.report-action strong { font-size: 10px; }
.report-action small { color: var(--muted); font-size: 8px; margin-top: 2px; }
.report-icon { width: 37px; height: 32px; display: grid; place-items: center; background: var(--orange-soft); color: var(--orange-dark); border-radius: 6px; font-size: 8px; font-weight: 900; }
.summary-card { background: #f9fafb; }
.summary-card dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.summary-card dt { color: var(--muted); font-size: 9px; }
.summary-card dd { margin: 0; font-size: 9px; font-weight: 800; text-align: right; }
.demo-card { margin: 14px 18px 20px; border: 0; border-radius: 9px; color: white; background: var(--navy-900); display: flex; align-items: center; gap: 12px; }
.demo-card > div { flex: 1; }

.map-shell { position: relative; flex: 1; min-width: 0; background: #dbe5e9; }
#map { width: 100%; height: 100%; z-index: 1; }
.leaflet-control-attribution { font-size: 8px !important; }
.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { border: 0 !important; color: var(--navy-900) !important; }
.engineering-marker { border: 3px solid white; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.38); }
.engineering-tooltip { background: rgba(7,23,40,.9); color: white; border: 0; border-radius: 4px; box-shadow: 0 3px 11px rgba(0,0,0,.18); font-size: 9px; font-weight: 650; padding: 4px 7px; }
.engineering-tooltip::before { border-top-color: rgba(7,23,40,.9) !important; }
.map-toolbar { position: absolute; z-index: 500; top: 18px; left: 18px; display: flex; flex-direction: column; background: white; border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.map-toolbar button { width: 38px; height: 38px; background: white; font-weight: 900; font-size: 17px; color: var(--navy-900); }
.map-toolbar button:hover, .map-toolbar button.active { background: var(--orange); color: white; }
.map-toolbar span { height: 1px; background: var(--line); }
.map-hint { position: absolute; z-index: 500; top: 18px; left: 70px; background: rgba(255,255,255,.95); color: var(--muted); border-radius: 7px; padding: 9px 12px; font-size: 9px; box-shadow: 0 4px 14px rgba(7,23,40,.12); }
.map-hint strong { color: var(--navy-900); }
.coordinates { position: absolute; z-index: 500; bottom: 18px; left: 18px; background: rgba(7,23,40,.84); color: white; border-radius: 4px; padding: 6px 9px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 8px; }
.north-arrow { position: absolute; z-index: 500; top: 18px; right: 18px; width: 33px; text-align: center; color: var(--navy-900); text-shadow: 0 1px 4px white; }
.north-arrow b { display: block; font-size: 12px; }
.north-arrow i { display: block; margin: 2px auto; width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 24px solid var(--navy-900); filter: drop-shadow(0 1px 1px white); }

.dialog { width: min(560px, calc(100% - 24px)); padding: 0; border: 0; border-radius: 11px; box-shadow: 0 28px 80px rgba(7,23,40,.35); color: var(--ink); }
.dialog::backdrop { background: rgba(7,23,40,.62); backdrop-filter: blur(2px); }
.dialog-header { padding: 18px 20px 14px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); }
.dialog-header h2 { font-size: 17px; margin: 3px 0 0; }
.dialog-close { border: 0; background: #eef2f4; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1; }
.dialog-body { padding: 18px 20px; }
.dialog-footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.dialog-footer > span { flex: 1; }
.dialog-footer .button-ghost { color: var(--ink); background: white; border-color: var(--line); }
.feature-auto-measures { display: flex; gap: 7px; flex-wrap: wrap; margin: 13px 0; }
.measure-chip { border-radius: 5px; background: var(--orange-soft); color: var(--orange-dark); padding: 6px 8px; font-size: 9px; font-weight: 750; }
.help-dialog { max-width: 520px; }
.help-steps { display: grid; gap: 14px; }
.help-steps article { display: flex; align-items: flex-start; gap: 11px; }
.help-steps article > b { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 26px; display: grid; place-items: center; color: white; background: var(--orange); font-size: 10px; }
.help-steps strong { font-size: 11px; }
.help-steps p { margin: 3px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.help-note { padding: 10px; border-radius: 7px; background: #edf7f2; color: #276c51; font-size: 9px; }
.toast { position: fixed; z-index: 3000; left: 50%; bottom: 24px; transform: translate(-50%, 24px); background: var(--navy-950); color: white; padding: 10px 15px; border-radius: 7px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; font-size: 10px; font-weight: 650; transition: .25s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

@media (max-width: 1100px) {
  :root { --sidebar-width: 350px; }
  .metrics article { padding: 10px 13px; gap: 9px; }
  .metric-icon { width: 28px; height: 28px; flex-basis: 28px; }
  .metrics small { font-size: 8px; }
  .metrics strong { font-size: 14px; }
}

@media (max-width: 820px) {
  .mobile-only { display: grid; }
  .topbar { height: 62px; padding: 0 12px; gap: 9px; }
  .brand { min-width: 0; }
  .brand > span:last-child, .project-title-wrap .eyebrow, .save-state { display: none; }
  .brand-mark { width: 31px; height: 31px; }
  .project-title-wrap { border: 0; padding: 0; flex: 1; }
  .project-title-wrap strong { font-size: 12px; max-width: 180px; }
  .top-actions .button-ghost, .top-actions .icon-button { display: none; }
  .top-actions { margin-left: 0; }
  .top-actions .button-primary { padding: 0 11px; font-size: 10px; }
  .metrics { height: 61px; overflow-x: auto; display: flex; scrollbar-width: none; }
  .metrics::-webkit-scrollbar { display: none; }
  .metrics article { min-width: 144px; flex: 0 0 144px; padding: 8px 11px; }
  .metrics article:nth-child(n+4) { min-width: 134px; flex-basis: 134px; }
  .workspace { height: calc(100% - 123px); }
  .sidebar { position: absolute; top: 123px; bottom: 0; left: 0; transform: translateX(-102%); transition: .25s ease; width: min(90vw, 390px); z-index: 1100; }
  .sidebar.open { transform: translateX(0); box-shadow: 10px 0 36px rgba(7,23,40,.25); }
  .map-hint { max-width: calc(100% - 125px); }
  .north-arrow { right: 10px; }
}

@media (max-width: 470px) {
  .field-row, .field-row.three { grid-template-columns: 1fr; }
  .dialog-footer { flex-wrap: wrap; }
  .dialog-footer > span { display: none; }
  .dialog-footer .button { flex: 1; }
  .map-hint { display: none; }
  .coordinates { bottom: 25px; left: 10px; }
}

@media print {
  body { overflow: visible; }
}
