:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --ink: #1e2423;
  --muted: #66716e;
  --line: #d9dfdb;
  --teal: #0f766e;
  --teal-soft: #dff4ee;
  --amber: #bd7a13;
  --amber-soft: #fff0d3;
  --coral: #c9543f;
  --coral-soft: #ffe5de;
  --green: #367a41;
  --green-soft: #e3f4df;
  --blue: #356ea3;
  --blue-soft: #e0edf8;
  --shadow: 0 18px 36px rgba(30, 36, 35, 0.08);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.brand h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  color: var(--teal);
  font-size: 14px;
  font-weight: 700;
}

.top-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 620px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.stat-pill strong {
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(0, 1fr);
  gap: 0;
}

.control-panel {
  position: sticky;
  top: 0;
  align-self: start;
  height: calc(100vh - 1px);
  overflow: auto;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #eff5f2;
}

.workspace {
  min-width: 0;
  padding: 18px clamp(16px, 2vw, 28px) 40px;
}

.panel-section,
.detail-panel,
.formula-panel,
.sheet-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-section {
  margin-bottom: 14px;
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.section-title output {
  color: var(--ink);
  font-weight: 700;
}

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

.segmented button,
.action-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  color: var(--ink);
  cursor: pointer;
}

.segmented button {
  padding: 8px;
  font-weight: 700;
}

.segmented button[aria-selected="true"] {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: #074a45;
}

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

.field-grid.compact {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.field small {
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
}

.selected-room {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.room-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.room-line b {
  font-size: 14px;
}

.input-group {
  margin-top: 14px;
}

.input-group:first-child {
  margin-top: 0;
}

.input-group h2 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.25;
}

.result-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.mobile-results {
  display: none;
}

.metric {
  min-height: 132px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(26px, 3.1vw, 38px);
  line-height: 1.15;
  letter-spacing: 0;
}

.metric strong small {
  margin-left: 4px;
  font-size: 0.72em;
  font-weight: 700;
}

.metric span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.metric.good {
  border-color: #badbb6;
  background: var(--green-soft);
}

.metric.warn {
  border-color: #f1d29b;
  background: var(--amber-soft);
}

.metric.bad {
  border-color: #efbfaf;
  background: var(--coral-soft);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
  align-items: start;
}

.detail-panel,
.formula-panel,
.sheet-panel {
  padding: 16px;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #174b75;
  font-size: 12px;
  font-weight: 800;
}

.badge.good {
  background: var(--green-soft);
  color: var(--green);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.bad {
  background: var(--coral-soft);
  color: var(--coral);
}

.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.calc-table th,
.calc-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.calc-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.calc-table td:last-child,
.calc-table th:last-child {
  text-align: right;
}

.formula-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.formula-list li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: #28302e;
  font-family: Consolas, "Microsoft JhengHei", monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.source-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sheet-panel {
  margin-top: 14px;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.sheet-item {
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.sheet-item b {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.empty {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 18px 14px;
  }

  .top-stats {
    justify-content: flex-start;
  }

  .control-panel,
  .workspace {
    padding: 12px;
  }

  .panel-section,
  .detail-panel,
  .formula-panel,
  .sheet-panel,
  .metric {
    border-radius: 8px;
    box-shadow: none;
  }

  .segmented,
  .field-grid,
  .result-strip,
  .sheet-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 112px;
  }

  .calc-table {
    font-size: 13px;
  }

  .mobile-results {
    display: grid;
    margin: 0 0 14px;
  }

  .workspace > .result-strip {
    display: none;
  }

  .calc-table th:nth-child(2),
  .calc-table td:nth-child(2) {
    display: none;
  }
}
