/* ═══ RESET & BASE ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #242836;
  --border: #2e3347;
  --text: #e4e6ed;
  --text2: #9499ad;
  --accent: #c0392b;
  --accent-hover: #e74c3c;
  --green: #27ae60;
  --blue: #2980b9;
  --orange: #e67e22;
  --purple: #8e44ad;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
}

html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ═══ HEADER ═══ */
#app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(15,17,23,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 60px;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.logo strong { color: var(--accent); }
.brand-tag { font-size: .75rem; color: var(--text2); background: var(--bg3); padding: 4px 10px; border-radius: 20px; }

#step-nav { display: flex; gap: 4px; }
.step-btn {
  background: none; border: none; color: var(--text2); font: inherit;
  font-size: .82rem; padding: 8px 16px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: .2s;
}
.step-btn .num {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); font-size: .75rem; font-weight: 600;
}
.step-btn.active { color: var(--text); background: var(--bg3); }
.step-btn.active .num { background: var(--accent); color: #fff; }
.step-btn.done .num { background: var(--green); color: #fff; }

/* ═══ STEPS ═══ */
.step { display: none; }
.step.active { display: block; }

/* ═══ STEP 1: HERO ═══ */
.hero {
  max-width: 800px; margin: 0 auto; padding: 80px 24px 60px;
  text-align: center;
}
.hero h1 { font-size: 2.8rem; font-weight: 800; line-height: 1.15; margin-bottom: 16px; }
.hero .accent { color: var(--accent); }
.hero .subtitle { color: var(--text2); font-size: 1.1rem; margin-bottom: 40px; }

.search-box {
  display: flex; gap: 8px; max-width: 560px; margin: 0 auto 16px;
}
.search-box input {
  flex: 1; padding: 14px 18px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg2); color: var(--text);
  transition: border-color .2s;
}
.search-box input:focus { outline: none; border-color: var(--accent); }
.error-msg { color: var(--accent); font-size: .85rem; margin-top: 8px; }

.features-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;
  margin-top: 60px;
}
.feature-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 20px; text-align: center;
}
.feature-icon { font-size: 2rem; margin-bottom: 12px; }
.feature-card h3 { font-size: 1rem; margin-bottom: 8px; }
.feature-card p { color: var(--text2); font-size: .85rem; }

/* ═══ BUTTONS ═══ */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 24px; border-radius: var(--radius); font: inherit;
  font-weight: 600; cursor: pointer; display: inline-flex;
  align-items: center; gap: 8px; transition: .2s; white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-outline {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  padding: 12px 24px; border-radius: var(--radius); font: inherit;
  font-weight: 500; cursor: pointer; transition: .2s; white-space: nowrap;
}
.btn-outline:hover { border-color: var(--text2); background: var(--bg3); }
.btn-sm { padding: 8px 14px; font-size: .82rem; }

/* ═══ STEP 2: MEASURE ═══ */
.measure-layout {
  display: flex; height: calc(100vh - 60px);
}
.map-container {
  flex: 1; position: relative;
}
#map { width: 100%; height: 100%; background: var(--bg2); }

#map-toolbar {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  display: flex; gap: 4px; background: rgba(15,17,23,.9);
  backdrop-filter: blur(8px); padding: 6px;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--text2); padding: 8px 12px;
  border-radius: 8px; cursor: pointer; font-size: .7rem; font-family: inherit;
  transition: .15s;
}
.tool-btn:hover { background: var(--bg3); color: var(--text); }
.tool-btn.active { background: var(--accent); color: #fff; }
.tool-sep { width: 1px; background: var(--border); margin: 4px 4px; }

#map-status {
  position: absolute; bottom: 12px; left: 12px; right: 12px; z-index: 10;
  background: rgba(15,17,23,.88); backdrop-filter: blur(8px);
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border);
  font-size: .82rem; color: var(--text2); text-align: center;
}

.measure-panel {
  width: 380px; background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 12px; border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: 1.1rem; }

#facets-list { flex: 1; overflow-y: auto; padding: 12px; }
.empty-state { text-align: center; color: var(--text2); padding: 40px 20px; font-size: .9rem; }

/* Facet Card */
.facet-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 8px;
  transition: border-color .2s; cursor: pointer;
}
.facet-card.selected { border-color: var(--accent); }
.facet-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.facet-label {
  display: flex; align-items: center; gap: 8px;
}
.facet-color {
  width: 14px; height: 14px; border-radius: 4px;
}
.facet-name {
  font-weight: 600; font-size: .9rem;
}
.facet-delete {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 1.1rem; padding: 2px 6px; border-radius: 4px;
}
.facet-delete:hover { color: var(--accent); background: rgba(192,57,43,.15); }

.facet-props { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.facet-prop label { font-size: .72rem; color: var(--text2); display: block; margin-bottom: 2px; }
.facet-prop span { font-weight: 600; font-size: .9rem; }
.facet-prop input, .facet-prop select {
  width: 100%; padding: 6px 8px; font: inherit; font-size: .85rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
}
.facet-prop input:focus, .facet-prop select:focus { outline: none; border-color: var(--accent); }

/* Edge Card */
.edge-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 6px;
  display: flex; align-items: center; gap: 10px; font-size: .85rem;
}
.edge-type-select {
  padding: 4px 6px; font-size: .8rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}

/* Summary */
#measurement-summary {
  border-top: 1px solid var(--border); padding: 16px 20px;
}
#measurement-summary h3 { font-size: .95rem; margin-bottom: 12px; }
.summary-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.summary-item {
  background: var(--bg); padding: 10px; border-radius: 8px; text-align: center;
}
.summary-item label { font-size: .68rem; color: var(--text2); display: block; }
.summary-item span { font-weight: 700; font-size: 1rem; }

.panel-actions {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: space-between;
}

/* ═══ STEP 3: MATERIALS ═══ */
.materials-layout {
  max-width: 960px; margin: 0 auto; padding: 40px 24px;
}
.materials-config {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; margin-bottom: 24px;
}
.materials-config h2 { font-size: 1.2rem; margin-bottom: 20px; }
.config-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px;
  margin-bottom: 20px;
}
.config-group label {
  display: block; font-size: .78rem; color: var(--text2);
  margin-bottom: 6px; font-weight: 500;
}
.config-group select, .config-group input {
  width: 100%; padding: 10px 12px; font: inherit; font-size: .9rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
}
.config-group select:focus, .config-group input:focus {
  outline: none; border-color: var(--accent);
}

#materials-result {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; margin-bottom: 24px;
}
#materials-result h2 { font-size: 1.2rem; margin-bottom: 16px; }
#materials-table {
  width: 100%; border-collapse: collapse;
}
#materials-table th {
  text-align: left; padding: 10px 12px; font-size: .78rem;
  color: var(--text2); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border); font-weight: 600;
}
#materials-table td {
  padding: 12px; border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
#materials-table tr:last-child td { border-bottom: none; }
#materials-table tr:hover td { background: rgba(255,255,255,.02); }

/* ═══ STEP 4: REPORT ═══ */
.report-layout {
  max-width: 960px; margin: 0 auto; padding: 40px 24px;
}
.report-actions-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.customer-info { display: flex; gap: 8px; flex: 1; }
.customer-info input {
  flex: 1; padding: 10px 14px; font: inherit; font-size: .9rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); min-width: 140px;
}
.customer-info input:focus { outline: none; border-color: var(--accent); }
.report-btns { display: flex; gap: 8px; }

#report-container {
  background: #fff; color: #222; border-radius: var(--radius);
  padding: 48px; min-height: 600px; box-shadow: var(--shadow);
}

/* Report inner styles */
.rpt-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px; border-bottom: 3px solid #c0392b; padding-bottom: 20px; }
.rpt-logo { font-size: 1.4rem; font-weight: 800; color: #c0392b; }
.rpt-logo small { display: block; font-size: .75rem; color: #888; font-weight: 400; }
.rpt-date { text-align: right; font-size: .85rem; color: #666; }
.rpt-address { font-size: 1.2rem; font-weight: 700; margin-bottom: 24px; }
.rpt-section { margin-bottom: 28px; }
.rpt-section h3 { font-size: 1rem; font-weight: 700; color: #c0392b; margin-bottom: 12px; border-bottom: 1px solid #eee; padding-bottom: 6px; }
.rpt-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.rpt-table th { text-align: left; padding: 8px 10px; background: #f5f5f5; font-weight: 600; border-bottom: 1px solid #ddd; }
.rpt-table td { padding: 8px 10px; border-bottom: 1px solid #eee; }
.rpt-summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.rpt-stat { background: #f8f8f8; padding: 16px; border-radius: 8px; text-align: center; }
.rpt-stat .val { font-size: 1.4rem; font-weight: 800; color: #c0392b; }
.rpt-stat .lbl { font-size: .75rem; color: #888; }
.rpt-footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid #eee; font-size: .78rem; color: #999; text-align: center; }

/* ═══ MODAL ═══ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; max-width: 480px;
  width: 90%; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 16px; }
.modal p { color: var(--text2); margin-bottom: 16px; font-size: .9rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 900px) {
  .measure-layout { flex-direction: column; }
  .measure-panel { width: 100%; height: 40vh; border-left: none; border-top: 1px solid var(--border); }
  .map-container { height: 60vh; }
  .features-grid { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr 1fr; }
  .header-inner { gap: 8px; }
  #step-nav { display: none; }
  .hero h1 { font-size: 2rem; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .rpt-summary-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .config-grid { grid-template-columns: 1fr; }
  .customer-info { flex-direction: column; }
  #report-container { padding: 24px; }
}

/* ═══ PRINT ═══ */
@media print {
  body { background: #fff; }
  #app-header, .panel-actions, .report-actions-bar, #step-nav { display: none !important; }
  .step { display: none !important; }
  #step-4 { display: block !important; }
  #report-container { box-shadow: none; border-radius: 0; padding: 0; }
}

/* ═══ IMAGERY SWITCHER ═══ */
#imagery-switcher {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  background: rgba(15,17,23,.92);
  backdrop-filter: blur(8px);
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
#imagery-switcher label {
  font-size: .72rem; color: var(--text2);
  font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; white-space: nowrap;
}
.imagery-options {
  display: flex; gap: 3px;
}
.imagery-btn {
  display: flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent;
  color: var(--text2); padding: 6px 10px;
  border-radius: 6px; cursor: pointer;
  font-size: .75rem; font-family: inherit;
  font-weight: 500; transition: .15s;
  white-space: nowrap;
}
.imagery-btn:hover {
  background: var(--bg3); color: var(--text);
  border-color: var(--border);
}
.imagery-btn.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}
.imagery-btn.disabled {
  opacity: .35; cursor: not-allowed;
  pointer-events: none;
}
.imagery-btn svg { flex-shrink: 0; }

/* Attribution bar for non-Google imagery */
#imagery-attribution {
  position: absolute; bottom: 44px; left: 12px; z-index: 10;
  background: rgba(0,0,0,.55);
  padding: 3px 8px; border-radius: 4px;
  font-size: .65rem; color: rgba(255,255,255,.7);
  display: none;
}
#imagery-attribution a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
}
#imagery-attribution a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  #imagery-switcher {
    top: auto; bottom: 52px; right: 8px; left: 8px;
    justify-content: center; flex-wrap: wrap;
  }
  #imagery-switcher label { display: none; }
}

/* ═══ GOOGLE PLACES AUTOCOMPLETE ═══ */
.pac-container {
  background: var(--bg2, #1a1d27);
  border: 1px solid var(--border, #2e3347);
  border-top: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-family: 'Inter', -apple-system, sans-serif;
  z-index: 10000;
}
.pac-item {
  border-top: 1px solid var(--border, #2e3347);
  padding: 10px 14px;
  color: var(--text, #e4e6ed);
  cursor: pointer;
  font-size: .9rem;
  line-height: 1.4;
}
.pac-item:first-child { border-top: none; }
.pac-item:hover,
.pac-item-selected {
  background: var(--bg3, #242836);
}
.pac-item-query {
  color: var(--text, #e4e6ed);
  font-weight: 600;
  font-size: .9rem;
}
.pac-matched { font-weight: 700; }
.pac-icon { display: none; }
.pac-item span:not(.pac-item-query) {
  color: var(--text2, #9499ad);
  font-size: .82rem;
}
/* Hide Google logo in dropdown */
.pac-logo::after { display: none; }
