:root {
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8dde5;
  --panel: #ffffff;
  --page: #f5f7fa;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b42318;
  --green: #087f5b;
  --plan-width: 1122px;
  --plan-height: 1402px;
  --foot-grid: 36px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  max-height: 100vh;
}

.app-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--line);
}

.app-title h1,
.tool-section h2 {
  margin: 0;
}

.app-title h1 {
  font-size: 1.45rem;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.save-status {
  flex: 0 0 auto;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.tool-section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-heading h2 {
  font-size: 0.95rem;
}

.stacked-form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: #344054;
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c9d2df;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

.color-input {
  height: 42px;
  padding: 4px;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 0;
  border-radius: 5px;
}

.color-input::-moz-color-swatch {
  border: 0;
  border-radius: 5px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.furniture-piece:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

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

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.small-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #0f766e;
  color: #fff;
}

.secondary-button:hover {
  background: #115e59;
}

.ghost-button,
.small-button {
  color: #344054;
  background: #fff;
  border-color: #c9d2df;
}

.ghost-button:hover,
.small-button:hover {
  background: #eef2f7;
}

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

.danger-button:hover {
  background: #fff3f2;
}

.item-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.list-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.list-row:hover,
.list-row.is-selected {
  border-color: var(--accent);
  background: #eff6ff;
}

.list-row strong,
.list-row span {
  display: block;
}

.list-row strong {
  font-size: 0.88rem;
}

.list-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.workspace-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.toolbar-group,
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.local-save-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.3;
}

.inline-control {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.inline-control input {
  width: 84px;
}

.unit-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.check-control {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

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

.board-scroll {
  overflow: auto;
  padding: 24px;
  min-width: 0;
}

.plan-board {
  position: relative;
  width: var(--plan-width);
  height: var(--plan-height);
  background: #fff;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.16);
  user-select: none;
  touch-action: none;
}

.floor-plan,
.grid-layer,
.measurement-layer,
.furniture-layer {
  position: absolute;
  inset: 0;
}

.floor-plan {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.grid-layer {
  background-image:
    linear-gradient(rgba(37, 99, 235, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.11) 1px, transparent 1px);
  background-size: var(--foot-grid) var(--foot-grid);
  opacity: 0.8;
  pointer-events: none;
}

.grid-layer.is-hidden {
  display: none;
}

.measurement-layer,
.furniture-layer {
  pointer-events: none;
}

.furniture-piece {
  position: absolute;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 24px;
  min-height: 24px;
  border: 2px solid rgba(15, 23, 42, 0.85);
  border-radius: 6px;
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  padding: 4px;
  pointer-events: auto;
  touch-action: none;
}

.rotate-button {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(15, 23, 42, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2933;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  touch-action: manipulation;
}

.rotate-button:hover {
  background: #fff;
}

.furniture-piece span,
.furniture-piece small {
  max-width: 100%;
  padding: 0 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.45);
}

.furniture-piece span {
  font-size: 0.82rem;
  font-weight: 900;
}

.furniture-piece small {
  font-size: 0.66rem;
  font-weight: 800;
}

.furniture-piece.is-selected {
  border-color: #fbbf24;
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.35), 0 8px 18px rgba(15, 23, 42, 0.18);
}

.furniture-piece.has-overlap {
  border-color: #dc2626;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.22), 0 8px 18px rgba(15, 23, 42, 0.18);
}

.measure-segment,
.measure-handle,
.measure-label {
  position: absolute;
  pointer-events: auto;
}

.measure-segment {
  height: 18px;
  margin-top: -9px;
  transform-origin: 0 50%;
  cursor: move;
}

.measure-segment::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 8px;
  height: 3px;
  background: #0f766e;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.measure-segment.is-selected::before {
  background: #f97316;
}

.measure-handle {
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid #064e3b;
  border-radius: 50%;
  background: #ccfbf1;
  cursor: grab;
}

.measure-handle.is-selected {
  border-color: #c2410c;
  background: #fed7aa;
}

.measure-label {
  transform: translate(-50%, -100%);
  border: 1px solid #99f6e4;
  border-radius: 6px;
  background: rgba(240, 253, 250, 0.94);
  color: #134e4a;
  padding: 3px 7px;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.measure-label.is-selected {
  border-color: #fdba74;
  background: rgba(255, 247, 237, 0.95);
  color: #9a3412;
}

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

.empty-state {
  color: var(--muted);
  font-size: 0.88rem;
}

.selected-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-note {
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  padding: 9px 10px;
  font-size: 0.8rem;
  font-weight: 800;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 760px;
  }
}

@media (max-width: 560px) {
  .app-title,
  .tool-section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .two-cols {
    grid-template-columns: 1fr;
  }

  .board-scroll {
    padding: 14px;
  }
}
