:root {
  color-scheme: light;
  --bg: #edf2f7;
  --bg-accent: #dbeafe;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --accent: #0f4dbf;
  --accent-soft: #dbeafe;
  --danger: #b91c1c;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at 8% 0%, #bfdbfe 0%, transparent 45%),
    radial-gradient(circle at 94% 10%, #e2e8f0 0%, transparent 35%),
    linear-gradient(170deg, var(--bg) 0%, #f8fafc 64%, var(--bg-accent) 100%);
  color: var(--text);
  min-height: 100vh;
}

.page {
  max-width: 1220px;
  margin: 0 auto;
  padding: 14px 12px 24px;
}

.page-header {
  margin-bottom: 12px;
}

.header-top-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
}

.brand-block h1 {
  margin-bottom: 2px;
}

.brand-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}

.menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.menu-button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #b8c4d6;
  border-radius: 10px;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 600;
}

.menu-button-icon {
  width: 44px;
  padding: 7px 8px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.menu-button-icon span {
  display: block;
  width: 20px;
  height: 2.5px;
  border-radius: 999px;
  background: #0f172a;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
  display: grid;
  gap: 4px;
  pointer-events: auto;
}

.menu-panel[hidden] {
  display: none !important;
}

.menu-panel button {
  min-height: 36px;
  width: 100%;
  text-align: left;
  border-radius: 8px;
}

h1,
h2,
h3 {
  letter-spacing: 0.01em;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(1.55rem, 5.4vw, 2.35rem);
  line-height: 1.1;
}

.summary {
  margin: 0;
  max-width: 70ch;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.tenant-note {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px;
}

.step-label {
  margin: 0 0 4px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

.step-card h2,
.results-panel h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.step-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.upload-controls,
.measurement-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#sign-image-input {
  width: 100%;
  min-height: 44px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
  padding: 10px 12px;
}

.upload-label,
button,
.scale-inputs input {
  border: 1px solid #b8c4d6;
  border-radius: var(--radius-md);
  min-height: 42px;
  padding: 8px 12px;
  font-size: 0.95rem;
  line-height: 1.2;
  touch-action: manipulation;
}

.upload-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  background: var(--accent);
  color: #f8fafc;
  cursor: pointer;
}

button {
  cursor: pointer;
  background: #fff;
  color: var(--text);
  font-weight: 600;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.56;
  cursor: not-allowed;
}

.measurement-controls button {
  flex: 1 1 140px;
  min-width: 120px;
}

.measurement-controls button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #0b2f78;
}

.sticky-controls {
  background: var(--panel);
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid #e2e8f0;
}

.image-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.preview-card {
  padding: 8px;
}

.image-preview-wrap {
  margin: 0;
  border: 1px solid #bfccde;
  border-radius: var(--radius-md);
  background: var(--panel-soft);
  position: relative;
  min-height: 52vh;
  max-height: 70vh;
  overflow: hidden;
}

.canvas-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: auto;
  touch-action: none;
}

#image-preview,
.measurement-overlay {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#image-preview {
  width: 1px;
  height: 1px;
  object-fit: fill;
  border-radius: 0;
}

.measurement-overlay {
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#reference-line {
  stroke: #ff2d2d;
  stroke-width: 4;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 1px #ffffff) drop-shadow(0 0 3px #ffffff);
  display: none;
}

#sign-box {
  fill: rgba(255, 240, 82, 0.2);
  stroke: #ff2d2d;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 1px #ffffff) drop-shadow(0 0 2px #ffffff);
  display: none;
}

.box-handle {
  fill: #ff2d2d;
  stroke: #ffffff;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  display: none;
}

.debug-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
  padding: 10px;
}

.debug-panel h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #1e293b;
}

.debug-panel p,
.results-panel p {
  margin: 4px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.84rem;
}

.results-panel {
  border-color: #b9c7db;
  background: linear-gradient(180deg, #f8fafc 0%, #eef4fd 100%);
}

.scale-inputs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.scale-inputs label {
  color: #1e293b;
  font-size: 0.9rem;
  font-weight: 600;
}

.scale-inputs input {
  color: var(--text);
  background: #fff;
}

.calc-status {
  color: var(--muted);
}

.results-panel #estimated-size {
  margin-top: 8px;
  font-size: 0.92rem;
  font-weight: 700;
}

.steps-panel {
  display: grid;
  gap: 10px;
}

.copyright {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.estimate-error {
  min-height: 1.2em;
  margin-top: 8px;
  color: var(--danger);
}

#generate-estimate-button.is-loading {
  position: relative;
  color: transparent;
}

#generate-estimate-button.is-loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid #a8b8d8;
  border-top-color: #0f4dbf;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.sheet-view {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-head h2 {
  margin: 0;
}

.sheet-copy {
  margin: 8px 0 12px;
  color: var(--muted);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

#pricing-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

#pricing-table th,
#pricing-table td {
  border: 1px solid #d5deea;
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 0.86rem;
}

#pricing-table th {
  background: #edf3ff;
}

.markup-grid {
  display: grid;
  gap: 8px;
  max-width: 240px;
}

.estimate-view {
  margin-top: 14px;
  display: grid;
  place-items: center;
}

.estimate-paper {
  width: min(860px, 100%);
  border: 1px solid #cfd9e6;
  border-radius: 16px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow);
}

.estimate-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.estimate-head h2 {
  margin: 0;
}

.estimate-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.estimate-grid h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.estimate-grid p {
  margin: 2px 0;
}

.estimate-image-wrap {
  margin-top: 14px;
}

#estimate-image {
  width: 240px;
  max-width: 100%;
  border: 1px solid #cfd9e6;
  border-radius: 10px;
}

.estimate-line-items {
  padding-left: 18px;
  margin: 6px 0;
}

.estimate-line-items li {
  margin: 4px 0;
}

.estimate-total {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0b2f78;
}

.estimate-note {
  margin: 8px 0;
  color: #334155;
}

.estimate-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
  color: #475569;
  font-size: 0.82rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

@media (min-width: 900px) and (min-height: 760px) {
  .page {
    padding: 22px 18px 34px;
  }

  .workspace {
    grid-template-columns: minmax(520px, 2.3fr) minmax(280px, 1fr);
    grid-template-areas:
      "upload upload"
      "preview side";
    gap: 14px;
    align-items: start;
  }

  .workspace > .step-card:first-child {
    grid-area: upload;
  }

  .preview-card {
    grid-area: preview;
    position: sticky;
    top: 12px;
  }

  .steps-panel {
    grid-area: side;
  }

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

  .image-preview-wrap {
    min-height: 60vh;
    max-height: 76vh;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .page {
    padding: 8px 8px 14px;
  }

  .summary,
  .tenant-note {
    display: none;
  }

  .workspace {
    gap: 8px;
  }

  .image-preview-wrap {
    min-height: 66vh;
    max-height: 80vh;
  }

  .card {
    padding: 10px;
  }
}
