:root {
  color-scheme: light;
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --text: #17201c;
  --muted: #62706a;
  --line: #d7ded9;
  --accent: #1f7a64;
  --accent-2: #e1a73a;
  --danger: #b24444;
  --shadow: 0 18px 45px rgba(31, 45, 38, 0.12);
  --touch-min: 48px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111817;
  --surface: #19221f;
  --surface-2: #202b27;
  --text: #eef5ef;
  --muted: #a9b8b1;
  --line: #33413c;
  --accent: #57c4a1;
  --accent-2: #f3bd5a;
  --danger: #f17777;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 12%, transparent), transparent 32%),
    linear-gradient(315deg, color-mix(in srgb, var(--accent-2) 14%, transparent), transparent 38%),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: var(--touch-min);
  padding: 0 14px;
  font-weight: 700;
  touch-action: manipulation;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

button:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(31, 122, 100, 0.12);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.api-status-bar {
  padding: 10px 18px;
  text-align: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.api-status {
  display: inline-block;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 6px 14px;
}

.api-status.ok {
  background: #d4edda;
  color: #155724;
}

.api-status.fail {
  background: #f8d7da;
  color: #721c24;
}

.api-status.pending {
  background: var(--surface-2);
  color: var(--muted);
}

[data-theme="dark"] .api-status.ok {
  background: color-mix(in srgb, #57c4a1 22%, transparent);
  color: #57c4a1;
}

[data-theme="dark"] .api-status.fail {
  background: color-mix(in srgb, var(--danger) 22%, transparent);
  color: var(--danger);
}

.app-shell {
  width: 100%;
  min-height: calc(100vh - 49px);
  padding: 12px;
}

.workspace {
  display: grid;
  gap: 14px;
  max-width: 960px;
  margin: 0 auto;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(8px);
}

.page-header {
  padding: 0 2px;
}

.directions {
  display: grid;
  gap: 12px;
}

.directions h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.directions ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.45;
}

.brand-row,
.section-title,
.output-header,
.search-row,
.map-toolbar,
.actions,
.map-workspace-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row,
.section-title,
.output-header,
.map-workspace-header {
  justify-content: space-between;
}

.brand-row h1,
.output-header h2,
.section-title h2,
.map-workspace-header h2,
.map-wrap-header h2 {
  margin: 0;
}

.brand-row h1 {
  font-size: clamp(1.2rem, 4vw, 1.45rem);
  line-height: 1.1;
}

.map-workspace-header h2,
.map-wrap-header h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.icon-button {
  width: var(--touch-min);
  padding: 0;
  flex: 0 0 var(--touch-min);
}

.status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.address-search label,
.input-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.search-row {
  margin-top: 8px;
}

.search-row input {
  flex: 1;
  min-width: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  min-height: var(--touch-min);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 98px;
}

#addressHelp {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.suggestions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.suggestion-item {
  text-align: left;
  justify-content: flex-start;
  min-height: var(--touch-min);
  font-weight: 600;
}

.panel-section {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.panel-section-first {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.section-title h2,
.output-header h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.status-pill {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 6px 9px;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.unit-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  margin: 12px 0;
}

.segmented {
  min-height: var(--touch-min);
  border: 0;
  background: transparent;
}

.segmented.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.08);
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.wide-field {
  grid-column: 1 / -1;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.map-action-bar {
  margin-top: 12px;
}

.map-action-bar button:first-child {
  grid-column: 1 / -1;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 90%, #ffffff), var(--accent));
  border-color: var(--accent);
  color: #ffffff;
}

.map-action-bar button.active {
  background: #116a94;
  border-color: #26b7ff;
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(38, 183, 255, 0.2);
}

.map-settings {
  margin-top: 12px;
}

.map-adjust-bar {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 40%, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent),
    var(--surface-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-2) 16%, transparent);
}

.adjust-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

.nudge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
}

.nudge-spacer {
  display: block;
}

#doneAdjusting {
  grid-column: 1 / -1;
  background:
    linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent-2) 45%, var(--accent)));
  border-color: var(--accent);
  color: #ffffff;
}

.nudge-grid button:not(#doneAdjusting) {
  min-height: var(--touch-min);
  font-size: 1.2rem;
  padding: 0;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--accent);
}

.custom-eaves {
  display: none;
}

.custom-eaves.visible {
  display: block;
}

.segment-row {
  display: grid;
  grid-template-columns: 1fr 92px 42px;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.segment-row button {
  padding: 0;
}

.control-panel {
  padding: 16px;
}

.map-workspace {
  padding: 16px;
}

.roof-photo-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(45deg, color-mix(in srgb, var(--line) 45%, transparent) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--line) 45%, transparent) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, color-mix(in srgb, var(--line) 45%, transparent) 75%),
    linear-gradient(-45deg, transparent 75%, color-mix(in srgb, var(--line) 45%, transparent) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, #ffffff 30%, transparent),
    0 18px 36px rgba(31, 45, 38, 0.1);
}

.roof-photo-stage img,
.roof-photo-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.roof-photo-stage img {
  object-fit: cover;
  transition: transform 120ms ease;
}

.roof-photo-stage canvas {
  cursor: crosshair;
  touch-action: none;
}

.roof-photo-stage.adjust-mode {
  cursor: grab;
  touch-action: none;
  border-color: var(--accent-2);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent-2) 24%, transparent),
    0 18px 36px rgba(31, 45, 38, 0.16);
}

.roof-photo-stage.adjust-mode:active {
  cursor: grabbing;
}

.roof-photo-stage.adjust-mode canvas {
  pointer-events: none;
}

.roof-photo-stage.eave-select-mode {
  border-color: #26b7ff;
  box-shadow:
    0 0 0 4px rgba(38, 183, 255, 0.2),
    0 18px 36px rgba(31, 45, 38, 0.16);
}

.roof-photo-stage.eave-select-mode canvas {
  cursor: copy;
}

.roof-photo-stage:not(.has-photo) canvas {
  pointer-events: none;
}

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  font-size: 0.92rem;
}

.roof-photo-stage.has-photo .photo-placeholder {
  display: none;
}

.map-wrap {
  position: relative;
  overflow: hidden;
  padding: 16px;
}

.map-wrap-reference iframe {
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  margin-top: 12px;
}

.map-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.metric-card {
  min-height: 110px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric-card.primary {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.metric-card strong {
  color: var(--text);
  font-size: clamp(1.2rem, 5vw, 1.75rem);
  line-height: 1;
}

.estimate-output,
.saved-panel {
  padding: 16px;
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button:first-child {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.detail-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 16px;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row span:first-child {
  color: var(--muted);
  font-weight: 700;
}

.saved-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.saved-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.saved-item h3,
.saved-item p {
  margin: 0;
}

.saved-item h3 {
  font-size: 0.95rem;
}

.saved-item p {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.question-dialog,
.cut-sheet-dialog {
  width: min(560px, calc(100vw - 24px));
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line));
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 28px 72px rgba(20, 30, 26, 0.32);
}

.cut-sheet-dialog {
  width: min(820px, calc(100vw - 24px));
}

.question-dialog::backdrop,
.cut-sheet-dialog::backdrop {
  background: rgba(11, 17, 15, 0.58);
  backdrop-filter: blur(4px);
}

.question-form,
.cut-sheet-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.question-header h2,
.question-header p {
  margin: 0;
}

.question-header h2 {
  font-size: 1.2rem;
  line-height: 1.15;
}

.question-header p:last-child {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.question-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.question-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.question-grid label[data-question="eaves"] {
  grid-column: 1 / -1;
}

.question-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.question-actions button[type="submit"] {
  background:
    linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent-2) 45%, var(--accent)));
  border-color: var(--accent);
  color: #ffffff;
}

.cut-sheet-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.cut-sheet-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.85fr) minmax(120px, 0.7fr) minmax(180px, 1.45fr);
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.cut-sheet-row:nth-child(odd):not(.cut-sheet-heading) {
  background: var(--surface-2);
}

.cut-sheet-row:last-child {
  border-bottom: 0;
}

.cut-sheet-heading {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cut-sheet-row strong {
  color: var(--text);
}

.cut-sheet-row span:last-child,
.cut-sheet-notes {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

@media (min-width: 720px) {
  .app-shell {
    padding: 18px;
  }

  .workspace {
    gap: 18px;
    max-width: 1200px;
  }

  .map-action-bar {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .map-action-bar button:first-child {
    grid-column: auto;
  }

  .results-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 16px;
  }

  .map-wrap-reference iframe {
    height: 320px;
  }
}

@media (min-width: 1024px) {
  .workspace {
    max-width: 1480px;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
    grid-template-areas:
      "header header"
      "address address"
      "map controls"
      "results controls"
      "street controls"
      "estimate estimate"
      "saved saved";
  }

  .page-header {
    grid-area: header;
  }

  .address-search {
    grid-area: address;
  }

  .map-workspace {
    grid-area: map;
  }

  .control-panel {
    grid-area: controls;
    position: sticky;
    top: 18px;
    align-self: start;
    max-height: calc(100vh - 36px);
    overflow: auto;
  }

  .results-grid {
    grid-area: results;
  }

  .map-wrap-reference {
    grid-area: street;
  }

  .estimate-output {
    grid-area: estimate;
  }

  .saved-panel {
    grid-area: saved;
  }

  .roof-photo-stage {
    max-width: 760px;
    margin: 0 auto;
  }
}

@media (max-width: 719px) {
  .map-workspace-header {
    flex-direction: column;
    align-items: stretch;
  }

  .status-group {
    justify-content: flex-start;
  }

  .section-title,
  .output-header,
  .search-row,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .input-grid {
    grid-template-columns: 1fr;
  }

  .detail-row,
  .saved-item,
  .segment-row {
    grid-template-columns: 1fr;
  }

  .question-grid {
    grid-template-columns: 1fr;
  }

  .cut-sheet-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .question-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .segment-row button {
    width: 100%;
  }

  .brand-row h1 {
    font-size: 1.15rem;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .api-status-bar,
  .page-header,
  .address-search,
  .map-workspace,
  .control-panel,
  .map-wrap-reference,
  .saved-panel,
  .actions {
    display: none;
  }

  .workspace {
    display: block;
    max-width: none;
  }

  .estimate-output,
  .metric-card {
    box-shadow: none;
  }
}
