:root {
  --bg: #f7f4ef;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --ink: #26211d;
  --muted: #746b62;
  --line: #e5ded3;
  --wood: #9a643f;
  --wood-dark: #6f432a;
  --sage: #5d7666;
  --blue: #57758c;
  --clay: #b06b5f;
  --gold: #bd8a35;
  --mint: #7ca88d;
  --shadow: 0 18px 40px rgba(73, 55, 38, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(260px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 14px clamp(20px, 4vw, 48px);
  background: rgba(255, 253, 250, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--wood-dark);
  color: #fff;
  font-weight: 800;
}

.brand-block h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand-block p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.desktop-nav,
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar {
  justify-content: flex-end;
}

.nav-link,
.mobile-link {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.nav-link {
  height: 38px;
  padding: 0 16px;
  border-radius: 8px;
}

.nav-link.active {
  background: #efe4d7;
  color: var(--wood-dark);
  font-weight: 700;
}

.icon-button,
.action-button,
.ghost-button,
.text-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.icon-button {
  padding: 0 12px;
  white-space: nowrap;
}

.icon-button.primary,
.action-button {
  border-color: var(--wood-dark);
  background: var(--wood-dark);
  color: #fff;
}

.action-button,
.ghost-button {
  padding: 0 16px;
}

.ghost-button {
  color: var(--wood-dark);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--wood-dark);
  font-weight: 700;
}

main {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 88px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--wood);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(26px, 3vw, 40px);
}

h3 {
  font-size: 18px;
}

.sync-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #c9d9cd;
  border-radius: 8px;
  background: #f2f8f3;
  color: var(--sage);
  font-size: 13px;
  font-weight: 700;
}

.sync-pill span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
}

.sync-pill[data-status="syncing"] {
  border-color: #ead39e;
  background: #fff8e8;
  color: #9a6c1d;
}

.sync-pill[data-status="syncing"] span {
  background: var(--gold);
}

.sync-pill[data-status="offline"],
.sync-pill[data-status="conflict"] {
  border-color: #e5b9b1;
  background: #fff1ee;
  color: var(--clay);
}

.sync-pill[data-status="offline"] span,
.sync-pill[data-status="conflict"] span {
  background: var(--clay);
}

.metrics-grid,
.budget-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card,
.panel,
.budget-card,
.progress-category {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-card p,
.metric-card small {
  margin: 0;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 28px;
}

.overview-layout,
.records-layout,
.notes-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.notes-layout {
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
  margin-top: 0;
  align-items: start;
}

.overview-layout.lower {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.75fr);
}

.panel {
  padding: 20px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-title span {
  color: var(--muted);
  font-size: 13px;
}

.hero-progress {
  padding: 18px;
  border-radius: 8px;
  background: #f2ede5;
}

.progress-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.progress-copy span {
  color: var(--muted);
}

.progress-copy strong {
  font-size: 34px;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #d9cec0;
}

.progress-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sage), var(--gold));
}

.progress-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.progress-row,
.budget-card,
.record-item {
  display: grid;
  gap: 8px;
}

.progress-label,
.budget-head,
.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-label span:first-child,
.budget-head strong,
.record-head strong {
  font-weight: 800;
}

.progress-label span:last-child,
.record-item small,
.budget-card small {
  color: var(--muted);
}

.chart-wrap {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  align-items: center;
  gap: 22px;
}

.donut-chart {
  width: 200px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--wood) 0 25%, var(--sage) 25% 43%, var(--blue) 43% 58%, var(--gold) 58% 73%, var(--clay) 73% 86%, var(--mint) 86% 95%, #9b8c7a 95% 100%);
  position: relative;
}

.donut-chart::after {
  content: "66.6%";
  position: absolute;
  inset: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  font-size: 28px;
  font-weight: 900;
}

.legend {
  display: grid;
  gap: 9px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.bars {
  display: grid;
  grid-template-columns: repeat(6, minmax(48px, 1fr));
  align-items: end;
  gap: 12px;
  min-height: 240px;
}

.bar-item {
  display: grid;
  align-items: end;
  gap: 8px;
  height: 220px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.bar-item i {
  display: block;
  min-height: 24px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--blue), var(--sage));
}

.advice-list {
  display: grid;
  gap: 12px;
}

.advice-list p {
  margin: 0;
  padding: 13px 14px;
  border-left: 4px solid var(--sage);
  background: #f3f6f0;
  line-height: 1.6;
}

.record-form {
  align-self: start;
}

.selection-form,
.selection-panel {
  align-self: start;
}

.record-form,
.selection-form,
.budget-total {
  display: grid;
  gap: 14px;
}

.selection-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
}

.selection-form h3,
.selection-form label:nth-of-type(3),
.selection-form label:nth-of-type(5),
.selection-form button {
  grid-column: 1 / -1;
}

.selection-form h3 {
  padding-bottom: 4px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.full {
  width: 100%;
}

.record-list {
  display: grid;
  gap: 10px;
}

.selection-list {
  display: grid;
  gap: 12px;
}

.record-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 4px 8px;
  border-radius: 7px;
  background: #eef2ef;
  color: var(--sage);
  font-size: 12px;
  font-weight: 800;
}

.selection-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.selection-head,
.selection-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.selection-head div {
  display: grid;
  gap: 4px;
}

.selection-head small,
.selection-meta,
.selection-advice {
  color: var(--muted);
}

.selection-meta {
  flex-wrap: wrap;
  justify-content: flex-start;
  font-size: 13px;
}

.selection-advice {
  margin: 0;
  padding: 10px 12px;
  border-left: 4px solid var(--gold);
  border-radius: 6px;
  background: #fbf4e8;
  line-height: 1.55;
}

.selection-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.selection-option {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 168px;
  padding: 12px;
  border: 1px solid #eadfce;
  border-radius: 8px;
  background: #fffaf3;
}

.option-title {
  display: grid;
  gap: 4px;
}

.option-title strong {
  line-height: 1.35;
}

.option-title span {
  color: var(--wood-dark);
  font-size: 13px;
  font-weight: 800;
}

.selection-option dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.selection-option div {
  display: grid;
  gap: 3px;
}

.selection-option dt {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.selection-option dd {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.notes-panel {
  margin-top: 16px;
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.tip-card {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tip-card h3 {
  color: var(--wood-dark);
  font-size: 16px;
}

.tip-card ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

.budget-total {
  grid-template-columns: minmax(240px, 1fr) auto auto;
  align-items: end;
  margin-bottom: 16px;
}

.budget-total div {
  min-width: 140px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #f2ede5;
}

.budget-total span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.budget-total strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.budget-card {
  padding: 16px;
}

.budget-card input {
  min-height: 36px;
}

.progress-board {
  display: grid;
  gap: 12px;
}

.progress-category {
  padding: 16px;
}

.category-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

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

.todo-item {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.todo-item p {
  margin: 0;
  font-weight: 700;
}

.status-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.status-group button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.status-group button.active {
  border-color: var(--sage);
  background: #eaf3eb;
  color: var(--sage);
  font-weight: 800;
}

.mobile-nav {
  display: none;
}

.floor-plan-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 25;
  display: none;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--wood-dark);
  border-radius: 8px;
  background: var(--wood-dark);
  color: #fff;
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(38, 33, 29, 0.52);
}

.modal-backdrop.open {
  display: flex;
}

.floor-plan-dialog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: min(1040px, 100%);
  max-height: min(86vh, 820px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(38, 33, 29, 0.28);
}

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

.dialog-head {
  margin-bottom: 16px;
}

.dialog-close {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.floor-plan-actions {
  margin-bottom: 14px;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--wood-dark);
  border-radius: 8px;
  background: var(--wood-dark);
  color: #fff;
  font-weight: 700;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.floor-plan-stage {
  position: relative;
  display: grid;
  min-height: 420px;
  overflow: auto;
  place-items: center;
  border: 1px dashed #cfc4b5;
  border-radius: 8px;
  background: #fbf8f3;
}

.floor-plan-empty {
  display: grid;
  gap: 8px;
  place-items: center;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

.floor-plan-empty strong {
  color: var(--ink);
  font-size: 20px;
}

#floor-plan-image {
  display: none;
  width: auto;
  max-width: 100%;
  max-height: 68vh;
  border-radius: 6px;
  object-fit: contain;
}

.floor-plan-stage.has-image {
  align-items: start;
  justify-items: center;
  padding: 14px;
  background: #fff;
}

.floor-plan-stage.has-image .floor-plan-empty {
  display: none;
}

.floor-plan-stage.has-image #floor-plan-image {
  display: block;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .desktop-nav {
    display: none;
  }

  .metrics-grid,
  .budget-grid,
  .overview-layout,
  .overview-layout.lower,
  .records-layout,
  .notes-layout,
  .tips-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-wrap,
  .todo-list,
  .selection-options {
    grid-template-columns: 1fr;
  }

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

  .donut-chart {
    margin: 0 auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 12px 16px;
  }

  .toolbar {
    display: none;
  }

  main {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics-grid,
  .budget-grid,
  .overview-layout,
  .overview-layout.lower,
  .records-layout,
  .notes-layout,
  .tips-grid,
  .budget-total {
    grid-template-columns: 1fr;
  }

  .panel,
  .metric-card,
  .progress-category {
    padding: 15px;
  }

  .bars {
    gap: 8px;
    overflow-x: auto;
    grid-template-columns: repeat(6, 68px);
  }

  .selection-options {
    grid-template-columns: 1fr;
  }

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

  .selection-form label,
  .selection-form h3,
  .selection-form button {
    grid-column: 1 / -1;
  }

  .mobile-nav {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 250, 0.96);
    box-shadow: var(--shadow);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .mobile-link {
    display: grid;
    place-items: center;
    gap: 2px;
    min-height: 46px;
    border-radius: 8px;
    font-size: 12px;
  }

  .mobile-link span {
    font-size: 16px;
  }

  .mobile-link.active {
    background: #efe4d7;
    color: var(--wood-dark);
    font-weight: 800;
  }

  .floor-plan-fab {
    display: block;
    right: 12px;
    bottom: 76px;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .floor-plan-dialog {
    max-height: 88vh;
    padding: 14px;
  }

  .floor-plan-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .upload-button,
  .floor-plan-actions .ghost-button {
    width: 100%;
  }

  .floor-plan-stage {
    min-height: 320px;
  }
}
