:root {
  --paper: #f4f0e8;
  --ink: #242522;
  --muted: #6f726b;
  --line: #d5d0c5;
  --panel: #fffdf8;
  --accent: #d95d39;
  --accent-soft: #f6ddd2;
  --teal: #216869;
  --shadow: 0 18px 50px rgba(50, 46, 38, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(52, 54, 49, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(52, 54, 49, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  font-family: "Manrope", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-family: "DM Mono", monospace;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.header-actions,
.stage-toolbar,
.section-heading,
.inspector-actions {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 10px;
}

.grid-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.grid-toggle input {
  accent-color: var(--teal);
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}

.icon-button svg,
.stage-toolbar svg,
.plan-note svg,
.secondary-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
}

.icon-button:hover:not(:disabled),
.secondary-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.icon-button.danger:hover:not(:disabled) {
  border-color: #a53931;
  color: #a53931;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: calc(100vh - 118px);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  z-index: 2;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 12px;
}

.count {
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 11px;
}

.furniture-palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.palette-button {
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #faf7f1;
  text-align: left;
  cursor: pointer;
}

.palette-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.palette-button strong,
.palette-button span {
  display: block;
}

.palette-button strong {
  margin-bottom: 5px;
  font-size: 12px;
  line-height: 1.2;
}

.palette-button span {
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 10px;
}

.empty-state {
  padding: 20px 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

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

.field {
  display: grid;
  gap: 5px;
}

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

.field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(33, 104, 105, 0.12);
}

.field select {
  cursor: pointer;
}

.input-unit {
  position: relative;
}

.input-unit input {
  padding-right: 35px;
}

.input-unit.price-input input {
  padding-right: 46px;
}

.input-unit span {
  position: absolute;
  top: 50%;
  right: 9px;
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  transform: translateY(-50%);
  pointer-events: none;
}

.inspector-actions {
  gap: 8px;
}

.secondary-button {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.plan-stage {
  display: flex;
  min-width: 0;
  flex-direction: column;
  background: #e7e3db;
}

.stage-toolbar {
  justify-content: space-between;
  min-height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
}

.scale-readout {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 11px;
}

.scale-line {
  width: 52px;
  height: 7px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-control input {
  width: 110px;
  accent-color: var(--teal);
}

.plan-scroll {
  display: grid;
  min-height: 520px;
  flex: 1;
  overflow: auto;
  padding: 32px 46px;
  place-items: center;
}

.plan {
  position: relative;
  width: min(53vh, 560px);
  aspect-ratio: 567 / 768;
  flex: 0 0 auto;
  overflow: visible;
  background: #fff;
  box-shadow: 0 12px 35px rgba(43, 40, 34, 0.18);
  transform-origin: center;
}

.plan > img,
.furniture-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.plan > img {
  z-index: 0;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.furniture-layer {
  z-index: 2;
  overflow: hidden;
  touch-action: none;
}

.clearance-zone {
  position: absolute;
  z-index: 1;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px dashed rgba(185, 75, 47, 0.72);
  color: #8d3d2c;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(217, 93, 57, 0.10) 0,
      rgba(217, 93, 57, 0.10) 4px,
      rgba(255, 253, 248, 0.28) 4px,
      rgba(255, 253, 248, 0.28) 8px
    );
  font-family: "DM Mono", monospace;
  font-size: clamp(5px, 0.75vw, 8px);
  line-height: 1;
  text-align: center;
  transform: translate(-50%, -50%) rotate(var(--rotation));
  transform-origin: center;
  pointer-events: none;
}

.clearances-visible .clearance-zone {
  display: flex;
}

.clearance-zone.round {
  border-radius: 50%;
}

.plan.grid-visible .furniture-layer {
  background-image:
    linear-gradient(rgba(33, 104, 105, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 104, 105, 0.16) 1px, transparent 1px),
    linear-gradient(rgba(33, 104, 105, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 104, 105, 0.08) 1px, transparent 1px);
  background-position: 0 0;
  background-size: 13.66% 9.94%, 13.66% 9.94%, 6.83% 4.97%, 6.83% 4.97%;
}

.furniture-item {
  position: absolute;
  display: grid;
  align-content: center;
  justify-items: center;
  min-width: 14px;
  min-height: 8px;
  padding: 3px;
  overflow: hidden;
  border: 1.5px solid color-mix(in srgb, var(--piece-color), #111 25%);
  border-radius: 3px;
  color: #17211f;
  background: color-mix(in srgb, var(--piece-color), transparent 14%);
  box-shadow: 0 2px 7px rgba(24, 28, 26, 0.14);
  cursor: grab;
  transform: translate(-50%, -50%) rotate(var(--rotation));
  transform-origin: center;
  user-select: none;
}

.furniture-item:active {
  cursor: grabbing;
}

.furniture-item.selected {
  z-index: 4;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.furniture-item[data-type="desk-chair"],
.furniture-item[data-type="rosentorp"],
.furniture-item[data-type="lisabo-chair"] {
  border-radius: 38%;
}

.furniture-item[data-shape="round"] {
  border-radius: 50%;
}

.furniture-label {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(7px, 1.2vw, 11px);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.furniture-size {
  margin-top: 2px;
  font-family: "DM Mono", monospace;
  font-size: clamp(6px, 0.95vw, 9px);
  line-height: 1;
}

.plan-dimension {
  position: absolute;
  z-index: 3;
  color: #555951;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  pointer-events: none;
}

.plan-width {
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
}

.plan-height {
  top: 50%;
  right: -42px;
  transform: translateY(-50%) rotate(90deg);
}

.plan-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  margin: 0;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 253, 248, 0.92);
  font-size: 11px;
}

.budget-section {
  min-width: 0;
  max-width: 100%;
  margin-top: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.budget-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.budget-heading .eyebrow {
  margin-bottom: 5px;
}

.budget-heading h2 {
  font-size: 20px;
}

.budget-totals {
  display: grid;
  min-width: 220px;
  gap: 4px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
}

.budget-totals > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
}

.budget-totals > span > span {
  color: var(--muted);
}

.budget-grand-total {
  margin-top: 3px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.budget-total {
  color: var(--teal);
  font-size: 20px;
}

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

.budget-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.budget-table th,
.budget-table td {
  padding: 13px 24px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.budget-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.budget-table th:nth-child(n + 3),
.budget-table td:nth-child(n + 3) {
  text-align: right;
}

.budget-table tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 800px) {
  .app-shell {
    padding: 12px;
  }

  .app-header {
    align-items: center;
  }

  .workspace {
    display: flex;
    min-height: 0;
    flex-direction: column-reverse;
    overflow: visible;
  }

  .sidebar {
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .furniture-palette {
    grid-template-columns: repeat(3, 1fr);
  }

  .plan-scroll {
    min-height: 620px;
    padding: 28px 42px 38px 20px;
  }

  .plan {
    width: min(70vw, 430px);
  }
}

@media (max-width: 480px) {
  .clearance-zone {
    font-size: 0;
  }

  .app-header {
    align-items: flex-start;
  }

  .eyebrow {
    max-width: 190px;
  }

  h1 {
    font-size: 25px;
  }

  .grid-toggle span {
    display: none;
  }

  .grid-toggle {
    width: 40px;
    justify-content: center;
    padding: 0;
  }

  .furniture-palette {
    grid-template-columns: 1fr 1fr;
  }

  .plan-scroll {
    min-height: 550px;
  }

  .stage-toolbar {
    padding: 0 12px;
  }

  .zoom-control input {
    width: 78px;
  }

  .budget-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .budget-totals {
    width: 100%;
  }

  .budget-table th,
  .budget-table td {
    padding-right: 14px;
    padding-left: 14px;
  }

  .budget-table-wrap {
    overflow-x: hidden;
  }

  .budget-table,
  .budget-table tbody {
    display: block;
  }

  .budget-table thead {
    display: none;
  }

  .budget-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 16px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }

  .budget-table td,
  .budget-table td:nth-child(n + 3) {
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
  }

  .budget-table td:nth-child(2) {
    color: var(--muted);
    font-family: "DM Mono", monospace;
    font-size: 10px;
  }

  .budget-table td:nth-child(n + 3) {
    grid-column: 2;
    font-family: "DM Mono", monospace;
    font-size: 10px;
  }

  .budget-table td:nth-child(3) {
    grid-row: 1;
  }

  .budget-table td:nth-child(4) {
    grid-row: 2;
  }

  .budget-table td:nth-child(5) {
    grid-row: 3;
    font-weight: 500;
  }

  .budget-table td:nth-child(3)::before {
    content: "Qty ";
  }

  .budget-table td:nth-child(4)::before {
    content: "Each ";
  }

  .budget-table td:nth-child(5)::before {
    content: "Subtotal ";
  }
}
