:root {
  --bg: #f5f1ea;
  --surface: #fffdfa;
  --surface-2: #eee7dc;
  --text: #2a2521;
  --muted: #786c61;
  --border: #e0d6c8;
  --accent: #4f7560;
  --accent-ink: #ffffff;
  --warn: #b0492a;
  --warn-soft: #e8b8a6;
  --planned: #c4d5c9;
  --floor: #faf6ef;
  --grid: rgba(60, 40, 20, 0.09);
  --furn: #e9dfd0;
  --furn-stroke: #9c8b77;
  --shadow: 0 8px 24px rgba(40, 30, 20, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191715;
    --surface: #22201d;
    --surface-2: #2d2a26;
    --text: #ece5da;
    --muted: #a3978a;
    --border: #3a352f;
    --accent: #86b096;
    --accent-ink: #11201a;
    --warn: #e48a6c;
    --warn-soft: #6b3a2c;
    --planned: #3a5244;
    --floor: #1f1d1a;
    --grid: rgba(255, 240, 220, 0.08);
    --furn: #3b352e;
    --furn-stroke: #8a7c6c;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3, .brand {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.05rem; }
a { color: inherit; }
p { margin: 0.25rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { color: var(--warn); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--surface-2); border-color: transparent; }
.danger { color: var(--warn); }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  width: 100%;
}
textarea { resize: vertical; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { font-size: 1.35rem; padding: 0 0.5rem; text-decoration: none; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  text-decoration: none;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
}
#nav a:hover { background: var(--surface-2); }
#nav a.active { background: var(--surface-2); font-weight: 600; }
#nav .count { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.foot-buttons, .sync-buttons { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.sync-line { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; padding: 0 0.5rem; }
.sync-line .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-synced .dot { background: var(--accent); }
.sync-syncing .dot { background: #c08a2e; animation: pulse 1s ease-in-out infinite alternate; }
.sync-error .dot, .sync-conflict .dot { background: var(--warn); }
@keyframes pulse { to { opacity: 0.3; } }

main { padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; max-width: 1200px; width: 100%; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.head-actions, .toolbar, .btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.toolbar { margin: 1rem 0; }
.toolbar select { width: auto; }
.notes { white-space: pre-wrap; max-width: 70ch; margin-bottom: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }

.empty { text-align: center; padding: 4rem 1rem; display: grid; gap: 0.75rem; justify-items: center; }
.empty.small {
  padding: 2.5rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
}

/* ---------- overview ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.bar { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar-planned, .bar-committed { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar-planned { background: var(--planned); }
.bar-committed { background: var(--accent); }
.bar.over .bar-planned { background: var(--warn-soft); }
.bar-limit { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); }
.budget-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 1rem;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-top: 0.4rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.legend { display: inline-block; width: 0.7em; height: 0.7em; border-radius: 2px; margin-right: 0.3em; }

.status-counts { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--s) 14%, var(--surface));
}
.chip::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--s); }

.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.room-card {
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}
.room-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cover {
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font: 600 2.5rem "Iowan Old Style", Georgia, serif;
  color: var(--muted);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.palette-strip { display: flex; height: 8px; }
.palette-strip i { flex: 1; }
.room-card-body { padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.35rem; }

/* ---------- status colours ---------- */
.status-idea { --s: #8a8178; }
.status-shortlist { --s: #c08a2e; }
.status-ordered { --s: #3f72af; }
.status-delivered { --s: #8a5cb8; }
.status-placed { --s: #4f8a5f; }

/* ---------- room ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a {
  text-decoration: none;
  padding: 0.6rem 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  white-space: nowrap;
}
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tab-body { padding-top: 1rem; }

/* items */
.item-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto 9.5rem auto;
  gap: 0.5rem 1rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
}
.thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-name a { text-decoration: none; }
.item-name a:hover { text-decoration: underline; }
.item-notes { margin-top: 0.15rem; white-space: pre-wrap; }
.item-price { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.item-price .muted { font-weight: 400; }
select.status {
  border-color: color-mix(in srgb, var(--s) 45%, transparent);
  background: color-mix(in srgb, var(--s) 14%, var(--surface));
  font-weight: 500;
}
.row-actions { display: flex; }

/* mood board */
.mood-grid { columns: 240px; column-gap: 1rem; }
.mood {
  break-inside: avoid;
  margin: 0 0 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.mood img { display: block; width: 100%; }
.mood figcaption { display: flex; gap: 0.25rem; padding: 0.3rem; }
.mood figcaption input { border-color: transparent; background: transparent; }
.mood figcaption input:hover, .mood figcaption input:focus { border-color: var(--border); }
main.dropping { outline: 3px dashed var(--accent); outline-offset: -10px; border-radius: 16px; }

/* palette */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.swatch {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.swatch .chip-color { display: block; width: 100%; height: 120px; border: 0; border-radius: 0; padding: 0; }
.swatch-body { padding: 0.7rem 0.9rem 0.9rem; display: grid; gap: 0.15rem; }
.swatch-body code { text-transform: uppercase; }
.swatch .remove { position: absolute; top: 0.4rem; right: 0.4rem; background: var(--surface); padding: 0.2rem 0.5rem; }

/* floor plan */
.plan-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1rem; align-items: start; }
.plan-wrap { padding: 0.5rem; }
svg.plan { width: 100%; height: auto; max-height: 75vh; display: block; touch-action: none; user-select: none; }
.room-floor { fill: var(--floor); }
.grid-line { fill: none; stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.room-wall { fill: none; stroke: var(--text); stroke-width: 4; vector-effect: non-scaling-stroke; }
.dim { fill: var(--muted); }
.furn { cursor: grab; }
.furn:active { cursor: grabbing; }
.furn rect { fill: var(--furn); stroke: var(--furn-stroke); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.furn text { fill: var(--text); pointer-events: none; }
.furn.sel rect { stroke: var(--accent); stroke-width: 3; fill: color-mix(in srgb, var(--accent) 22%, var(--furn)); }
.plan-side { display: grid; gap: 0.75rem; }
.plan-side h3 { margin-top: 0.5rem; }
.plan-side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.plan-side li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.4rem 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.plan-side li span { min-width: 0; overflow-wrap: anywhere; }

/* ---------- dialog ---------- */
dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(560px, calc(100vw - 2rem));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(20, 15, 10, 0.45); }
#dialog-form { padding: 1.25rem 1.5rem; }
.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.75rem; margin: 1rem 0 1.25rem; }
.field { grid-column: span 6; display: flex; flex-direction: column; gap: 0.25rem; }
.field.half { grid-column: span 3; }
.field.third { grid-column: span 2; }
.field > label { font-size: 0.85rem; font-weight: 600; }
.field input[type="color"] { height: 48px; padding: 3px; cursor: pointer; }
.field input[type="file"] { padding: 0.35rem; }
.img-current { display: flex; align-items: center; gap: 0.75rem; }
.img-current img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.check { display: flex; gap: 0.4rem; align-items: center; font-size: 0.9rem; }
.check input { width: auto; }
.picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.4rem; max-height: 55vh; overflow: auto; }
.pick { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--surface-2); }
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.35; transition: opacity 0.15s; }
.pick input { position: absolute; top: 6px; left: 6px; width: auto; z-index: 1; accent-color: var(--accent); }
.pick input:checked + img { opacity: 1; }
.pick:has(input:checked) { outline: 3px solid var(--accent); outline-offset: -3px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 2rem);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
  }
  .brand { flex: 1; padding: 0; }
  .sidebar-foot { margin: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #nav { order: 5; width: 100%; flex-direction: row; overflow-x: auto; }
  #nav a { white-space: nowrap; }
  main { padding-top: 1.25rem; }
  h1 { font-size: 1.6rem; }
  .plan-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .item { grid-template-columns: 56px minmax(0, 1fr) auto; }
  .item select.status { grid-column: 1 / 3; }
  .row-actions { justify-self: end; }
}
