:root {
  --paper: #f7f4ef;
  --surface: #fffdf9;
  --surface-strong: #ffffff;
  --ink: #20211f;
  --muted: #6b6a64;
  --line: #ded8cd;
  --line-strong: #c8c0b3;
  --sage: #627464;
  --sage-dark: #364a3a;
  --blue: #345f7d;
  --amber: #a76522;
  --red: #9b3f35;
  --shadow: 0 14px 36px rgba(46, 38, 28, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.hidden {
  display: none !important;
}

.entry-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.entry-card {
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.entry-card h1 {
  margin: 0;
  font-size: 24px;
}

.entry-card p {
  margin: 0;
  color: var(--muted);
}

.cloud-status {
  display: inline-block;
  margin-top: 7px;
  color: var(--sage-dark);
  font-size: 12px;
  font-weight: 650;
}

.cloud-status.offline {
  color: var(--amber);
}

.entry-card label {
  display: grid;
  gap: 6px;
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 12px;
}

.dashboard-card {
  width: min(100%, 760px);
}

.dashboard-head,
.dashboard-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.dashboard-actions input {
  flex: 1;
}

.client-limit-control {
  display: flex !important;
  grid-template-columns: none !important;
  gap: 7px !important;
  align-items: center;
  white-space: nowrap;
}

.client-limit-control select {
  width: 72px;
}

.client-results {
  display: grid;
  gap: 8px;
}

.client-result {
  display: grid;
  grid-template-columns: 1fr 38px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  overflow: visible;
}

.client-result.archived {
  background: #fbfaf7;
  border-style: dashed;
}

.client-result.empty-result {
  display: block;
  padding: 10px;
}

.client-result strong,
.client-result span {
  display: block;
}

.client-result span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.client-open {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 10px;
}

.client-open:hover {
  background: rgba(98, 116, 100, 0.08);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(32, 33, 31, 0.32);
  padding: 18px;
}

.modal-card {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.modal-card h2,
.modal-card p {
  margin: 0;
}

.modal-card p {
  color: var(--muted);
  font-size: 13px;
}

.modal-card label {
  display: grid;
  gap: 6px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.topbar {
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
}

.client-block {
  display: grid;
  gap: 4px;
  min-width: min(520px, 54vw);
}

label,
.client-block label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.client-input,
.title-input {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  font-weight: 700;
  min-width: 0;
  outline: 0;
}

.title-input {
  width: min(520px, 100%);
  font-size: 22px;
}

.top-actions,
.section-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px;
  min-height: 0;
  width: 100%;
}

.spaces-panel,
.editor-panel,
.summary-panel,
.surface-panel,
.compare-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.spaces-panel,
.summary-panel {
  padding: 14px;
  align-self: center;
  position: static;
  top: auto;
  max-height: none;
  overflow: auto;
}

.editor-panel {
  padding: 14px;
  min-width: 0;
}

.surface-panel {
  padding: 14px;
  box-shadow: none;
}

.wallpaper-panel {
  margin-top: 14px;
  box-shadow: none;
  border-color: var(--line-strong);
}

.wallpaper-panel .compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wallpaper-panel .advanced-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.layout-card {
  width: min(100%, 820px);
  min-width: 340px;
  min-height: 90px;
  max-width: calc(100vw - 28px);
  resize: both;
  overflow: auto;
}

.layout-card.dragging {
  opacity: 0.58;
}

.layout-card.drag-over {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.layout-card > .panel-head,
.layout-card > .section-bar {
  cursor: grab;
}

.layout-card > .panel-head:active,
.layout-card > .section-bar:active {
  cursor: grabbing;
}

.walls-panel {
  margin-top: 14px;
}

.panel-head,
.section-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

h1,
h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

h2 {
  font-size: 14px;
}

.panel-context {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.spaces-list,
.summary-cards {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.space-card,
.metric-card,
.material-tab {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 8px;
}

.space-card {
  width: 100%;
  text-align: left;
  color: var(--ink);
  padding: 0;
  overflow: hidden;
}

.space-card.active {
  border-color: var(--sage);
  box-shadow: inset 3px 0 0 var(--sage);
}

.space-card-head {
  display: grid;
  grid-template-columns: 1fr 36px;
  align-items: start;
}

.space-select {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 10px;
}

.space-menu,
.client-menu {
  position: relative;
}

.space-menu {
  padding: 7px 7px 0 0;
}

.client-menu {
  padding: 7px 7px 0 0;
}

.space-menu summary,
.client-menu summary {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  line-height: 1;
  list-style: none;
  cursor: pointer;
}

.space-menu summary::-webkit-details-marker,
.client-menu summary::-webkit-details-marker {
  display: none;
}

.space-menu-popover,
.client-menu-popover {
  position: absolute;
  right: 7px;
  top: 40px;
  z-index: 4;
  min-width: 120px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 4px;
}

.space-menu-popover button,
.client-menu-popover button {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 8px;
  font-weight: 650;
}

.space-menu-popover button:hover,
.client-menu-popover button:hover {
  background: var(--paper);
}

.space-menu-popover .danger-text,
.client-menu-popover .danger-text {
  color: var(--red);
}

.space-wallpapers {
  display: grid;
  gap: 7px;
  padding: 0 10px 10px;
}

.space-wallpaper-item {
  display: grid;
  grid-template-columns: 1fr 28px;
  gap: 6px;
  align-items: stretch;
}

.space-wallpaper-item.active .space-wallpaper-card {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.space-wallpaper-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 8px 9px;
}

.space-wallpaper-card strong {
  display: block;
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 5px;
}

.space-wallpaper-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.delete-wallpaper-option {
  width: 28px;
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--red);
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

.delete-wallpaper-option:hover {
  border-color: var(--red);
}

.space-card strong,
.metric-card strong,
.material-tab strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.material-tab strong {
  margin-bottom: 5px;
}

.material-tab .material-area,
.material-tab .material-amount {
  display: block;
}

.material-tab .material-amount {
  margin-top: 4px;
}

.space-card span,
.metric-card span,
.micro {
  color: var(--muted);
  font-size: 12px;
}

.metric-card .subtle-check {
  display: block;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--blue);
}

.material-tabs {
  display: none;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 2px;
}

.material-tab {
  min-width: 150px;
  padding: 9px 10px;
  text-align: left;
  color: var(--ink);
}

.material-tab.active {
  border-color: var(--blue);
  box-shadow: inset 0 -3px 0 var(--blue);
}

.edit-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 14px;
}

.walls-table {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.wall-row {
  display: grid;
  grid-template-columns: minmax(82px, 1fr) minmax(132px, 160px) minmax(132px, 160px) 36px;
  gap: 6px;
  align-items: end;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.wall-row label {
  display: grid;
  gap: 4px;
}

.dimension-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.dimension-pair label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

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

.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid label {
  display: grid;
  gap: 5px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52, 95, 125, 0.13);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

input[type="number"] {
  -moz-appearance: textfield;
}

.check-row {
  display: flex !important;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  align-self: end;
  min-height: 38px;
  color: var(--ink);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.toggle-field {
  display: flex !important;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  align-self: end;
  min-height: 38px;
  color: var(--ink);
}

.toggle-field input {
  width: 16px;
  min-height: 16px;
}

.mural-only {
  display: none !important;
}

.wallpaper-panel.mural-active .mural-only {
  display: grid !important;
}

.wallpaper-panel.mural-active .roll-only {
  display: none !important;
}

.show-more {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.show-more summary {
  width: max-content;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  padding: 7px 12px;
  color: var(--ink);
  font-weight: 650;
  list-style-position: inside;
  cursor: pointer;
}

.show-more[open] summary {
  border-color: var(--blue);
}

.advanced-form {
  margin-top: 12px;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 13px;
  font-weight: 650;
  background: var(--sage);
  color: white;
}

.ghost-button,
.icon-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.danger-button {
  background: #fff;
  color: var(--red);
  border-color: #d7ada7;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.remove-wall {
  color: var(--red);
}

.metric-card {
  padding: 12px;
}

.metric-card .value {
  margin-top: 3px;
  font-size: 24px;
  font-weight: 750;
}

.metric-card.accent {
  border-color: rgba(98, 116, 100, 0.45);
}

.metric-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.metric-list span,
.summary-group span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.summary-group .amount-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.summary-group .amount-line > span {
  display: inline;
}

.romo-inline,
.price-inline {
  border-left: 1px solid var(--line-strong);
  padding-left: 8px;
  font-size: 11px !important;
  font-weight: 650;
}

.romo-inline {
  color: var(--blue) !important;
}

.price-inline {
  color: var(--sage-dark) !important;
}

.summary-group {
  display: grid;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.summary-group:first-child {
  padding-top: 0;
  border-top: 0;
}

.summary-group strong {
  font-size: 13px;
}

.metric-card.warning {
  border-color: rgba(167, 101, 34, 0.45);
}

.compare-panel {
  margin-top: 14px;
  padding: 14px;
  box-shadow: none;
}

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

.compare-row {
  display: grid;
  grid-template-columns: 1fr 80px 80px;
  gap: 8px;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.method-row {
  color: var(--muted);
}

.difference-alert {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(167, 101, 34, 0.55);
  background: #fff6e8;
  color: #58330e;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
}

.difference-alert strong {
  color: var(--amber);
}

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

#summaryText {
  margin-top: 14px;
  min-height: 220px;
  resize: vertical;
  line-height: 1.45;
}

.save-status {
  color: var(--muted);
  font-size: 12px;
}

.summary-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.summary-toggle input {
  width: 16px;
  min-height: 16px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--sage-dark);
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .wallpaper-panel .compact-form,
  .wallpaper-panel .advanced-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 850px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .client-block {
    width: 100%;
  }

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

  .wallpaper-panel .compact-form,
  .wallpaper-panel .advanced-form {
    grid-template-columns: 1fr 1fr;
  }

  .spaces-panel {
    position: static;
    max-height: none;
  }

  .spaces-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .wall-row {
    grid-template-columns: 1fr 1fr 36px;
  }

  .wall-row .wall-name {
    grid-column: 1 / -1;
  }

  .wall-row .wall-dimension {
    grid-column: auto;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 8px;
  }

  .dashboard-head,
  .dashboard-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .client-limit-control {
    justify-content: space-between;
  }

  .client-limit-control select {
    width: 100px;
  }

  .layout-card {
    min-width: 0;
    resize: none;
    width: 100% !important;
  }

  .spaces-list,
  .summary-cards,
  .form-grid,
  .wallpaper-panel .compact-form,
  .wallpaper-panel .advanced-form {
    grid-template-columns: 1fr;
  }

  .wall-row {
    grid-template-columns: 1fr 36px;
  }

  .wall-row .wall-name,
  .wall-row .wall-dimension {
    grid-column: 1 / -1;
  }

  .wall-row .wall-name {
    grid-column: 1;
  }

  .wall-row .remove-wall {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .top-actions,
  .section-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button,
  .section-actions button {
    flex: 1;
  }
}
