:root {
  --bg: #f3efe7;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #fff;
  --text: #17231d;
  --muted: #5f6b64;
  --line: rgba(23, 35, 29, 0.12);
  --accent: #245a46;
  --accent-2: #a85f2f;
  --accent-3: #194d55;
  --accent-soft: rgba(36, 90, 70, 0.12);
  --danger: #9f4c4c;
  --shadow: 0 20px 50px rgba(20, 27, 22, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-family: "IBM Plex Sans", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(36, 90, 70, 0.14), transparent 30%),
    radial-gradient(circle at top right, rgba(168, 95, 47, 0.14), transparent 22%),
    linear-gradient(180deg, #f9f7f1 0%, #ece6db 100%);
}

h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(18px);
  background: rgba(248, 245, 239, 0.82);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
}

.topbar h1 { font-size: 28px; letter-spacing: -0.02em; }
.nav { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.nav a {
  text-decoration: none;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.03);
}

.shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 18px 24px 40px;
}

.rehab-app-shell { min-height: calc(100vh - 90px); }

.hero, .panel, .metric, .loading-card, .room-card, .task-card, .saved-item, .chart-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero {
  border-radius: var(--radius-xl);
  padding: 22px 24px;
  margin-bottom: 14px;
}

.hero-stack {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.hero-copy {
  max-width: 920px;
}

.hero-copy h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  margin-bottom: 10px;
}

.hero-copy p {
  color: var(--muted);
  max-width: 880px;
  line-height: 1.55;
  font-size: 15px;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
}

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

.hero-select {
  display: grid;
  gap: 6px;
  min-width: 180px;
}
.hero-select select {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--accent); color: white; }
.btn.secondary { background: rgba(255, 255, 255, 0.82); border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: #f5e0e0; color: var(--danger); border: 1px solid rgba(159, 76, 76, 0.2); }
.btn.tiny {
  padding: 7px 10px;
  font-size: 12px;
}

.tabbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
}

.tab-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
}
.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.tab-panel.hidden { display: none; }

.panel {
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
}

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

.panel-head h3, .panel-head h4 {
  font-size: 18px;
  letter-spacing: -0.02em;
}

.hint, .detail-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.metric {
  border-radius: 18px;
  padding: 16px;
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.metric strong {
  display: block;
  font-size: 22px;
  letter-spacing: -0.03em;
}

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

.chart-card {
  border-radius: 18px;
  padding: 16px;
}

.bars { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 10px;
  align-items: center;
}
.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.bar-track {
  height: 10px;
  background: rgba(23, 35, 29, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, #4e8c74 100%);
}
.bar-value {
  font-size: 13px;
  color: var(--muted);
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.grid-form.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.grid-form input,
.grid-form select,
.grid-form textarea {
  width: 100%;
  border: 1px solid rgba(23, 35, 29, 0.14);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 12px;
  font: inherit;
}
.grid-form textarea { resize: vertical; }
.grid-form .full { grid-column: 1 / -1; }

.inline-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

.empty, .empty-cell {
  color: var(--muted);
  padding: 12px 4px;
}

.loading-card {
  border-radius: var(--radius-xl);
  padding: 28px;
  max-width: 760px;
}
.loading-card h2 {
  font-size: 30px;
  margin-bottom: 8px;
}
.loading-card p {
  color: var(--muted);
  line-height: 1.55;
}

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

.room-card {
  border-radius: var(--radius-lg);
  padding: 16px;
}
.room-card.selected {
  outline: 2px solid rgba(36, 90, 70, 0.18);
}

.room-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
}
.room-title-input {
  font-size: 18px;
  font-weight: 700;
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text);
  width: min(100%, 420px);
}
.room-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.room-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(23, 35, 29, 0.08);
}
.room-sums {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.depth-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.depth-btn.active {
  background: var(--accent-2);
  color: white;
  border-color: transparent;
}

.room-body {
  margin-top: 14px;
  display: grid;
  gap: 14px;
}
.room-body.collapsed { display: none; }

.material-groups {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.check-group {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
}
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
}
.chip input { accent-color: var(--accent); }
.chip.active {
  background: rgba(36, 90, 70, 0.12);
  border-color: rgba(36, 90, 70, 0.24);
}

.task-list {
  display: grid;
  gap: 10px;
}
.task-card {
  border-radius: 18px;
  overflow: hidden;
}
.task-card summary {
  list-style: none;
  cursor: pointer;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}
.task-card summary::-webkit-details-marker { display: none; }
.task-sums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 12px;
  color: var(--muted);
}
.task-lines {
  border-top: 1px solid rgba(23, 35, 29, 0.08);
  background: rgba(255, 255, 255, 0.8);
}

.line-row {
  display: grid;
  grid-template-columns: 34px minmax(260px, 1.5fr) 92px 70px 100px 100px 180px;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-top: 1px solid rgba(23, 35, 29, 0.06);
}
.line-row:first-child { border-top: none; }
.line-row.dim { opacity: 0.46; }
.line-row.forced { background: rgba(36, 90, 70, 0.05); }
.line-title { font-weight: 650; }
.line-check { padding-top: 3px; }
.line-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qty-input {
  width: 100%;
  border: 1px solid rgba(23, 35, 29, 0.14);
  border-radius: 10px;
  padding: 8px 10px;
  background: white;
  font: inherit;
}

.catalog-sheet { min-width: 980px; }
.catalog-desc { font-weight: 650; }
.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}
.sheet {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}
.sheet thead th {
  position: sticky;
  top: 0;
  background: rgba(244, 240, 232, 0.98);
  padding: 12px 10px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.sheet td {
  padding: 10px;
  border-bottom: 1px solid rgba(23, 35, 29, 0.08);
  vertical-align: top;
}
.sheet .btn.tiny { white-space: nowrap; }

.package-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.saved-item {
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.load-drawer {
  position: fixed;
  top: 92px;
  right: 16px;
  bottom: 16px;
  width: min(430px, calc(100vw - 32px));
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: auto;
  transform: translateX(110%);
  transition: transform 0.2s ease;
  z-index: 40;
}
.load-drawer.open { transform: translateX(0); }
.load-list { display: grid; gap: 10px; }

.report-room {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  padding: 14px;
  margin-bottom: 12px;
}
.report-task {
  border-top: 1px solid rgba(23, 35, 29, 0.08);
  padding-top: 12px;
  margin-top: 12px;
}
.report-task-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.report-line {
  display: grid;
  grid-template-columns: 1.5fr 70px 60px 90px 90px;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px dashed rgba(23, 35, 29, 0.08);
  font-size: 13px;
}
.report-line:first-child { border-top: none; }

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(23, 35, 29, 0.08);
  padding: 8px 0;
}

.detail-sub { margin-top: 4px; }

@media (max-width: 1200px) {
  .summary-grid,
  .panel-grid,
  .material-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .line-row,
  .report-line {
    grid-template-columns: 34px minmax(220px, 1fr);
  }
  .line-row > :nth-child(n + 3),
  .report-line > :nth-child(n + 3) {
    grid-column: 2;
  }
  .hero-stack,
  .panel-head,
  .inline-tools {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 820px) {
  .shell { padding: 14px; }
  .summary-grid,
  .panel-grid,
  .grid-form,
  .grid-form.compact,
  .material-groups {
    grid-template-columns: 1fr;
  }
  .bar-row {
    grid-template-columns: 1fr;
  }
  .room-head,
  .room-meta {
    flex-direction: column;
    align-items: flex-start;
  }
  .load-drawer {
    width: calc(100vw - 16px);
    right: 8px;
    left: 8px;
  }
}
