:root {
  --bg: #fafbff;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --shadow-soft: 0 18px 45px rgba(15, 23, 42, .08);
  --unit-cell-size: 132px;
  --status-lock-bg: #fef3c7;
  --status-lock-text: #92400e;
  --status-control-bg: #ffe4e6;
  --status-control-text: #9f1239;
  --status-reserve-bg: #dbeafe;
  --status-reserve-text: #1e3a8a;
  --status-signed-bg: #e5e7eb;
  --status-signed-text: #374151;
  --status-unsold-bg: #dcfce7;
  --status-unsold-text: #047857;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.brand.compact {
  margin-bottom: 24px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1 {
  margin: 0;
  color: #020617;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.25;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label span {
  color: #475569;
  font-size: 13px;
  font-weight: 650;
}

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

select {
  appearance: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(37, 99, 235, .14);
}

.select-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
}

.select-wrap select {
  padding-right: 38px;
}

.primary,
.ghost {
  height: 40px;
  border-radius: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  font-weight: 750;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.ghost {
  background: #fff;
  border-color: #dbe3ef;
  color: #0f172a;
}

.ghost:hover {
  border-color: #b9c6d8;
  background: #f8fafc;
}

.error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.main-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fafbff;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  position: relative;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #475569;
  text-align: left;
  padding: 0 14px 0 16px;
  font-weight: 750;
}

.nav button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  width: 3px;
  height: 24px;
  border-radius: 999px;
  background: transparent;
}

.nav button.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav button.active::before {
  background: var(--primary);
}

#logoutBtn {
  margin-top: auto;
}

.content {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.app-context {
  margin: 0 0 5px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.topbar h2 {
  margin: 0;
  color: #020617;
  font-size: 26px;
  font-weight: 850;
  line-height: 1.2;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.badge {
  display: none;
}

.filters {
  display: grid;
  grid-template-columns: 164px minmax(320px, 1fr);
  align-items: end;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  margin-bottom: 12px;
}

.filters label {
  margin: 0;
}

.status-stats,
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-height: 42px;
  color: #334155;
  font-size: 13px;
  font-weight: 760;
}

.stat-pill,
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.view-toolbar {
  display: none;
}

.legend-box {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border: 0;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(15, 23, 42, .04);
}

.legend-box.lock { background: var(--status-lock-text); }
.legend-box.control { background: var(--status-control-text); }
.legend-box.reserve { background: var(--status-reserve-text); }
.legend-box.signed { background: var(--status-signed-text); }
.legend-box.unsold { background: var(--status-unsold-text); }

.control-chart {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  overflow: hidden;
}

.chart-scroll {
  overflow: auto;
  max-height: calc(100vh - 210px);
}

.control-grid {
  width: max-content;
  padding: 14px;
}

.control-meta,
.control-row {
  display: grid;
  column-gap: 10px;
}

.control-meta {
  position: sticky;
  top: 0;
  z-index: 2;
  row-gap: 6px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.control-row {
  align-items: stretch;
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.meta-label,
.meta-value {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 760;
}

.meta-value {
  background: #fff;
  color: #0f172a;
  font-weight: 800;
}

.floor-label {
  min-height: var(--unit-cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  font-weight: 820;
}

.unit-cell {
  width: var(--unit-cell-size);
  height: var(--unit-cell-size);
  min-height: var(--unit-cell-size);
  border: 0;
  border-radius: 8px;
  padding: 10px;
  color: #263238;
  display: grid;
  grid-template-rows: 28px repeat(3, 1fr);
  gap: 4px;
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}

.unit-cell:not(.empty):hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 12px 24px rgba(15, 23, 42, .12);
  filter: saturate(1.03);
}

.unit-cell.lock {
  background: var(--status-lock-bg);
  color: var(--status-lock-text);
}

.unit-cell.control {
  background: var(--status-control-bg);
  color: var(--status-control-text);
}

.unit-cell.reserve {
  background: var(--status-reserve-bg);
  color: var(--status-reserve-text);
}

.unit-cell.signed {
  background: var(--status-signed-bg);
  color: var(--status-signed-text);
}

.unit-cell.unsold {
  background: var(--status-unsold-bg);
  color: var(--status-unsold-text);
}

.unit-cell.empty {
  background: transparent;
  color: transparent;
  pointer-events: none;
}

.room-no {
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
}

.cell-line {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  min-height: 0;
  border: 0;
  font-size: 11px;
}

.cell-line span,
.cell-line strong {
  min-width: 0;
  padding: 0 1px;
  white-space: nowrap;
}

.cell-line span {
  color: currentColor;
  font-weight: 650;
  opacity: .72;
}

.cell-line strong {
  color: currentColor;
  font-size: 12px;
  font-weight: 820;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  padding: 38px;
  text-align: center;
  color: var(--muted);
}

.desktop-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

tbody tr:hover {
  background: #f8fbff;
}

.status {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f6;
  font-size: 12px;
  font-weight: 800;
}

.status.sale { background: #dcfce7; color: #047857; }
.status.lock { background: #fef3c7; color: #92400e; }
.status.done { background: #e5e7eb; color: #374151; }

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

.section-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 850;
}

.drawer {
  margin-top: 14px;
  max-width: 520px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.drawer h3 {
  margin: 0 0 14px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkline input {
  width: 16px;
  height: 16px;
}

.checkline span {
  color: var(--ink);
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.mobile-cards {
  display: none;
}

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

.house-card + .house-card {
  margin-top: 10px;
}

.house-card h3 {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 16px;
}

.house-card dl {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px 10px;
  margin: 0;
  font-size: 14px;
}

.house-card dt {
  color: var(--muted);
}

.house-card dd {
  margin: 0;
  color: var(--ink);
}

@media (max-width: 760px) {
  :root {
    --unit-cell-size: 124px;
  }

  .main-shell {
    display: block;
  }

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

  .brand.compact {
    margin-bottom: 12px;
  }

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

  .nav button {
    text-align: center;
    padding: 0 6px;
    font-size: 13px;
  }

  .nav button::before {
    display: none;
  }

  #logoutBtn {
    margin-top: 10px;
  }

  .content {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h2 {
    font-size: 22px;
  }

  .filters {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .chart-scroll {
    max-height: none;
  }

  .unit-cell {
    width: var(--unit-cell-size);
    height: var(--unit-cell-size);
    min-height: var(--unit-cell-size);
    padding: 9px;
  }

  .floor-label {
    min-height: var(--unit-cell-size);
  }

  .cell-line {
    grid-template-columns: 56px minmax(0, 1fr);
    font-size: 10px;
  }
}
