/*
 * Room Sketch — application styles.
 *
 * Theme-aware (light/dark via prefers-color-scheme), touch-friendly targets for
 * a tablet/2-in-1, and a layout that puts the canvas first with the wall table
 * alongside on wide screens and stacked below on narrow ones.
 */

:root {
  --bg: #f4f1ea;
  --panel: #fffaf2;
  --ink: #1f2933;
  --ink-soft: #687480;
  --line: #d8cfc0;
  --accent: #1463ff;
  --accent-ink: #ffffff;
  --wall: #222831;
  --opening: #b3a894;
  --warn: #b4531a;
  --ok: #1f7a4d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a1f;
    --panel: #21262e;
    --ink: #e7ecf2;
    --ink-soft: #9aa6b2;
    --line: #333b45;
    --accent: #4d8bff;
    --accent-ink: #0b1220;
    --wall: #cfd6de;
    --opening: #6b7280;
    --warn: #e0873c;
    --ok: #57c48a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.app-bar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.app-bar__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.sketch-id {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.sketch-id__field {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  min-height: 32px;
  width: 130px;
  max-width: 28vw;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.sketch-id__field:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.sketch-id__sep {
  color: var(--ink-soft);
}

/* Sketches panel — a modal list of saved sketches. */
.sketches-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px;
}
.sketches-panel[hidden] {
  display: none;
}
.sketches-panel__card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  width: min(560px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sketches-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sketches-panel__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  flex: 1;
}
.sketches-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
}
.sketches-list__item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 2px;
  border-radius: 10px;
}
.sketches-list__item--current {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.sketches-list__open {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 48px;
}
.sketches-list__open:hover {
  background: var(--bg);
}
.sketches-list__name {
  font-weight: 700;
  font-size: 15px;
}
.sketches-list__when {
  font-size: 12px;
  color: var(--ink-soft);
}
.sketches-list__delete {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  min-width: 44px;
  font-size: 16px;
}
.sketches-list__delete:hover {
  border-color: var(--warn);
}
.sketches-list__empty {
  color: var(--ink-soft);
  padding: 16px;
  text-align: center;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.status--warn { color: var(--warn); font-weight: 700; }
.status--ok { color: var(--ok); font-weight: 700; }

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.canvas-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
  align-items: center;
}

.toolbar__group {
  display: flex;
  gap: 4px;
}
.toolbar__group--right {
  margin-left: auto;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn:disabled:hover {
  border-color: var(--line);
}
.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn--icon {
  min-width: 40px;
  padding: 8px 12px;
  font-size: 18px;
  line-height: 1;
}

.canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(128, 128, 128, 0.08) 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(128, 128, 128, 0.08) 24px);
  touch-action: none;
  cursor: crosshair;
}
.canvas[data-mode="select"] { cursor: default; }
.canvas[data-mode="pan"] { cursor: grab; }

/* Model-space SVG elements. stroke-width uses non-scaling-stroke so lines stay
   a constant visual weight regardless of zoom. */
.raw-stroke {
  fill: none;
  stroke: var(--opening);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
  vector-effect: non-scaling-stroke;
}
.active-stroke {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.wall {
  stroke: var(--wall);
  stroke-width: 5;
  stroke-linecap: round;
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}
.wall--opening {
  stroke: var(--opening);
  stroke-width: 4;
  stroke-dasharray: 2 6;
}
.wall--selected {
  stroke: var(--accent);
  stroke-width: 8;
}
.wall-label__bg {
  fill: var(--panel);
  stroke: var(--line);
}
.wall-label--selected .wall-label__bg {
  fill: var(--accent);
  stroke: var(--accent);
}
.wall-label__number {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
}
.wall-label__length {
  fill: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
}
.wall-label--selected .wall-label__number { fill: var(--accent-ink); }
.wall-label--selected .wall-label__length { fill: var(--accent-ink); }

.table-panel {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 14px;
  overflow-y: auto;
}
.table-panel__title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
}
.table-panel__hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.table-panel__hint code {
  background: var(--bg);
  border-radius: 4px;
  padding: 1px 4px;
}

.wall-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.wall-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}
.wall-table__row td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}
.wall-table__row--selected {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.wall-table__number {
  font-weight: 800;
  width: 52px;
  cursor: pointer;
}
.wall-table__number--door {
  font-weight: 700;
  font-size: 12px;
  color: var(--opening);
}
.wall-table__row--door .wall-table__input {
  border-style: dashed;
}
.wall-table__angle {
  width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  white-space: nowrap;
}
.wall-table__input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.wall-table__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.wall-table__input--invalid {
  border-color: var(--warn);
  outline-color: var(--warn);
}
.wall-table__empty {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 12px 6px;
}

@media (max-width: 720px) {
  .workspace { flex-direction: column; }
  .table-panel {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 40%;
  }
}
