:root {
  --bg: #f4f1ea;
  --ink: #1f2524;
  --green: #2e6650;
  --green-soft: #eaf2ee;
  --line: #d6d3d1;
  --muted: #78716c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 8px;
  height: 100vh;
  padding: 8px;
  overflow: hidden;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.toolbar {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbar p,
.modalHead p {
  margin: 0;
  color: #6f5b39;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.toolbar h1,
.modalHead h2 {
  margin: 2px 0 0;
  font-size: 20px;
}

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

.primary,
.secondary,
.icon,
.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.primary,
.primary-button {
  background: var(--green);
  color: white;
  border-color: var(--green);
  padding: 0 14px;
}

.secondary,
.icon,
.secondary-button,
.icon-button {
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

.icon-button {
  width: 36px;
  padding: 0;
}

.primary:hover,
.secondary:hover,
.icon:hover,
.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.canvasFrame {
  position: relative;
  display: grid;
  min-height: 0;
}

.viewport {
  display: grid;
  place-items: center;
  overflow: auto;
  border-radius: 6px;
}

.canvas {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, calc((100vh - 54px) * 1.333));
  aspect-ratio: 1448 / 1086;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: 0 1px 2px #0002;
}

.canvas img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

.sceneStrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.sceneStrip.hidden {
  display: none;
}

.scene-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 5px 8px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
}

.scene-chip img {
  width: 52px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: #eee;
}

.scene-chip.is-active {
  border-color: var(--green);
  background: var(--green-soft);
  color: #214837;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffffff5;
}

.panel-body {
  display: grid;
  min-height: 0;
}

.panel-body.is-mobile-closed {
  display: none;
}

.mobile-panel-toggle {
  display: flex;
  min-height: 42px;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px;
  background: #f5f3ef;
  padding: 0 12px;
  font-weight: 700;
}

.mobile-panel-toggle svg {
  transition: transform 160ms ease;
}

.mobile-panel-toggle svg.rotate-180 {
  transform: rotate(180deg);
}

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

.tabs button,
.allBtn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font-weight: 800;
  cursor: pointer;
}

.tabs .active {
  border-color: var(--green);
  background: var(--green-soft);
  color: #214837;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 14px 0 8px;
}

body.nearme-only .brand-filter,
body.nearme-only .collection-filter {
  display: none;
}

body.nearme-only .filters {
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfaf7;
  padding: 10px;
}

body.nearme-only .door-style-filter {
  color: #214837;
}

body.nearme-only .door-style-filter select {
  min-height: 44px;
  border-color: rgb(46 102 80 / 0.45);
  color: #1f2524;
}

body.nearme-only .door-style-filter {
  display: none;
}

.style-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.style-pill {
  flex: 0 0 auto;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: #44403c;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
  scroll-snap-align: start;
}

.style-pill.is-active {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.filters.hidden {
  display: none;
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.filters select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
  font-size: 14px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

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

.card,
.option-card {
  position: relative;
  display: grid;
  gap: 6px;
  min-height: 120px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.card.active,
.option-card.is-active {
  border-color: var(--green);
  box-shadow: 0 0 0 2px #2e66502e;
}

.card button:first-child,
.option-select-button {
  display: grid;
  gap: 6px;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.card img,
.option-card img,
.option-select-button img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 5px;
  background: #f3f0ea;
}

.card strong,
.option-card span,
.option-select-button span {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.card small,
.option-card small,
.option-select-button small {
  color: var(--muted);
  line-height: 1.25;
}

.allBtn,
.all-cabinets-button {
  min-height: 32px;
  background: #edf5f1;
  color: #214837;
  border-color: #2e66504d;
}

.check {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 99px;
  background: var(--green);
  color: white;
  font-size: 13px;
}

.empty {
  grid-column: 1 / -1;
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: white;
  padding: 14px;
  color: var(--muted);
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.summary {
  margin-top: 12px;
  border-radius: 6px;
  background: #fbfaf7;
  padding: 14px;
  font-size: 14px;
  overflow: auto;
}

.summary h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.summary p {
  margin: 0 0 9px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  max-width: 760px;
  width: min(760px, calc(100vw - 32px));
}

dialog::backdrop {
  background: #0008;
}

.modal {
  padding: 20px;
}

.modalHead {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.modalGrid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  margin-top: 18px;
}

.fields {
  display: grid;
  gap: 10px;
}

.fields label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 800;
  text-transform: capitalize;
}

.fields input,
.fields textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

#previewDialog {
  width: min(96vw, 1400px);
  max-width: 1400px;
  background: transparent;
}

#previewDialog form {
  position: relative;
  margin: 0;
}

.previewCanvas {
  width: min(96vw, 1400px);
  max-height: 92vh;
}

.previewClose {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 20;
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 46vh) minmax(0, 54vh);
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    padding: 6px;
    gap: 6px;
  }

  .stage {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
    gap: 6px;
  }

  .toolbar {
    min-height: 32px;
  }

  .toolbar p {
    font-size: 10px;
    letter-spacing: 0.14em;
  }

  .toolbar h1 {
    font-size: 16px;
  }

  .toolbarActions .primary {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .panel {
    grid-column: 1;
    grid-row: 2;
    max-height: none;
    min-height: 0;
    overflow: hidden;
    padding: 8px;
  }

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

  .canvas {
    width: min(100%, calc((46vh - 46px) * 1.333));
    max-height: 100%;
  }

  body.nearme-only .panel {
    max-height: none;
  }

  body.nearme-only .filters {
    margin: 6px 0 8px;
    padding: 8px 8px 2px;
  }

  .mobile-panel-toggle {
    min-height: 34px;
  }

  .panel-body {
    min-height: 0;
    overflow: hidden;
  }

  .tabs {
    gap: 6px;
  }

  .tabs button {
    min-height: 34px;
    padding: 5px;
    font-size: 12px;
  }

  .options {
    display: flex;
    min-height: 0;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 2px 6px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .option-card {
    flex: 0 0 104px;
    min-height: 106px;
    padding: 5px;
    gap: 4px;
    scroll-snap-align: start;
  }

  .option-select-button {
    gap: 4px;
  }

  .option-card img,
  .option-select-button img {
    aspect-ratio: 4 / 3;
  }

  .option-card span,
  .option-select-button span {
    font-size: 11px;
    line-height: 1.1;
  }

  .option-card small,
  .option-select-button small {
    font-size: 9px;
    line-height: 1.1;
  }

  .all-cabinets-button {
    display: inline-flex;
    min-height: 23px;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    font-size: 9px;
  }

  .summary {
    display: block;
    max-height: 72px;
    margin-top: 8px;
    padding: 8px;
    font-size: 11px;
    line-height: 1.25;
    overflow-y: auto;
  }

  .summary h3 {
    margin-bottom: 5px;
    font-size: 12px;
  }

  .summary p {
    margin-bottom: 5px;
  }

  .actions {
    margin-top: 8px;
    padding-top: 8px;
    gap: 6px;
  }

  .style-pill {
    min-height: 38px;
    padding: 0 13px;
    font-size: 13px;
  }
}

@media (min-width: 901px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: none;
  }

  .stage,
  .panel {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (min-width: 1024px) {
  body {
    overflow: hidden;
  }

  .shell {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .stage {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .toolbar {
    min-height: 38px;
  }

  .canvas {
    align-self: center;
    justify-self: center;
    height: auto;
    max-height: 100%;
    width: min(100%, calc((100vh - 54px) * 1.333));
    max-width: 100%;
  }

  .panel {
    display: flex;
    height: calc(100vh - 16px);
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  .options {
    min-height: 0;
  }

  .panel-body {
    overflow-y: auto;
    padding-right: 4px;
  }

  .panel-body.is-mobile-closed {
    display: grid;
  }

  .mobile-panel-toggle {
    display: none;
  }

  .scene-chip {
    display: none;
  }
}
