:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d0d5dd;
  --line-dark: #7a7a7a;
  --primary: #1f2937;
  --primary-2: #374151;
  --available: #ffffff;
  --hold: #00ff00;
  --sold: #ffff00;
  --band4: #ffc000;
  --band: #cccccc;
  --danger: #b42318;
  --shadow: 0 14px 36px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 38px);
  background: rgba(17,24,39,.97);
  color: white;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.brand-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg,#fff,#d8dee8);
  color: #111827; font-weight: 900; letter-spacing: -.5px;
  flex: 0 0 auto;
}
.app-header h1 { margin: 0; font-size: 16px; line-height: 1.2; font-weight: 750; }
.app-header p { margin: 3px 0 0; color: #cfd4dc; font-size: 12px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 38px;
  padding: 8px 13px;
  font-weight: 700;
  font-size: 13px;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: #fff; color: #111827; border-color: #fff; }
.btn-secondary { background: transparent; color: #fff; border-color: #667085; }
.control-card .btn-secondary, .modal .btn-secondary { color: #344054; background: #fff; border-color: #d0d5dd; }
.control-card .btn-primary, .modal .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.pill { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 700; }
.pill-muted { background: #344054; color: #e4e7ec; }
.pill-live { background: #073d26; color: #9ef0bf; }
.pill-warn { background: #5f3f00; color: #ffe4a6; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(255,255,255,.08); }
.user-chip { border: 1px solid #475467; border-radius: 10px; padding: 7px 10px; font-size: 12px; color: #e4e7ec; }
.user-chip strong { color: #fff; }

.main-content { width: min(1480px, 100%); margin: 0 auto; padding: 22px clamp(12px, 2vw, 28px) 32px; }
.control-card, .sheet-card { background: var(--surface); border: 1px solid #e4e7ec; border-radius: 16px; box-shadow: var(--shadow); }
.control-card { padding: 14px 16px; margin-bottom: 14px; }
.count-strip { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; }
.count-item { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 9px 11px; border: 1px solid #eaecf0; border-radius: 12px; background: #fcfcfd; }
.count-item > div { display: flex; flex-direction: column; min-width: 0; }
.count-item strong { font-size: 19px; line-height: 1; }
.count-item small { margin-top: 4px; color: var(--muted); font-weight: 650; font-size: 11px; }
.legend-box { width: 17px; height: 17px; display: inline-block; flex: 0 0 auto; border: 1px solid #7d7d7d; border-radius: 4px; }
.legend-available { background: var(--available); }
.legend-hold { background: var(--hold); }
.legend-sold { background: var(--sold); }
.legend-band4 { background: var(--band4); }
.control-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid #eaecf0; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.legend-line { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; color: #475467; font-size: 12px; font-weight: 650; }
.legend-line span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line .legend-box { width: 14px; height: 14px; border-radius: 3px; }
.search-form { display: flex; align-items: center; gap: 7px; min-width: min(360px, 100%); }
.search-form input { flex: 1; min-width: 0; height: 38px; border: 1px solid #d0d5dd; border-radius: 10px; padding: 0 11px; outline: none; }
.search-form input:focus { border-color: #667085; box-shadow: 0 0 0 3px rgba(102,112,133,.14); }

.notice { padding: 12px 14px; margin: 0 0 14px; border-radius: 12px; border: 1px solid #f5cf7c; background: #fffaeb; color: #7a4f01; font-size: 13px; line-height: 1.45; }
.notice.error { border-color: #f7b9b3; background: #fef3f2; color: #8e1c13; }
.notice.success { border-color: #a6e0b8; background: #ecfdf3; color: #067647; }

.sheet-card { overflow: hidden; }
.sheet-toolbar { min-height: 52px; display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 10px 14px; border-bottom: 1px solid #eaecf0; background: #fcfcfd; }
.sheet-toolbar > div:first-child { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sheet-toolbar strong { font-size: 13px; }
.sheet-toolbar span { color: var(--muted); font-size: 11px; }
.sheet-help { text-align: right; }
#editHint { color: #067647; font-weight: 700; }
.sheet-scroll { width: 100%; overflow: auto; -webkit-overflow-scrolling: touch; background: #fff; max-height: calc(100vh - 178px); }

.inventory-table {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 910px;
  margin: 0 auto;
  font-family: Calibri, Arial, sans-serif;
  color: #000;
  font-size: 11px;
  background: #fff;
}
.inventory-table col.col-a { width: 54px; }
.inventory-table col.col-b, .inventory-table col.col-c { width: 238px; }
.inventory-table col.col-d, .inventory-table col.col-e { width: 190px; }
.inventory-table td {
  border: 1px solid #7e7e7e;
  padding: 2px 5px;
  text-align: center;
  vertical-align: middle;
  white-space: pre-line;
  line-height: 1.14;
  overflow-wrap: anywhere;
  background: #fff;
}
.inventory-table td.cell-title { background: #ccc; font-size: 14px; font-weight: 700; }
.inventory-table td.cell-title-side { background: #ccc; }
.inventory-table td.cell-header { background: #fff; color: #ff0000; font-weight: 700; }
.inventory-table td.cell-band { background: #ccc; font-weight: 700; }
.inventory-table td.cell-band-side { background: #ccc; }
.inventory-table td.cell-band4 { background: var(--band4); font-weight: 700; }
.inventory-table td.cell-floor { background: #fff; font-weight: 400; }
.inventory-table td.cell-blank { background: #fff; }
.inventory-table td.unit-cell { position: relative; transition: box-shadow .15s ease, transform .08s ease; }
.inventory-table td.unit-cell.status-available { background: var(--available); font-weight: 400; }
.inventory-table td.unit-cell.status-hold { background: var(--hold); font-weight: 400; }
.inventory-table td.unit-cell.status-sold { background: var(--sold); font-weight: 700; }
.inventory-table td.unit-cell.status-hold.band-iv { background: var(--band4); font-weight: 700; }
.inventory-table td.unit-cell.status-loading { background: #f7f7f7; color: #667085; }
.inventory-table.editor td.unit-cell { cursor: pointer; }
.inventory-table.editor td.unit-cell:hover { box-shadow: inset 0 0 0 3px rgba(17,24,39,.55); z-index: 2; }
.inventory-table td.unit-cell.search-hit { animation: highlightCell 1.25s ease; box-shadow: inset 0 0 0 4px #2563eb, 0 0 0 3px rgba(37,99,235,.16); z-index: 3; }
.inventory-table td.unit-cell.live-hit::after { content: "updated"; position: absolute; top: 4px; right: 4px; font-family: Inter, Arial, sans-serif; font-size: 8px; line-height: 1; padding: 3px 4px; color: #fff; background: #111827; border-radius: 4px; text-transform: uppercase; letter-spacing: .2px; }
@keyframes highlightCell { 0%,100% { transform: scale(1); } 35% { transform: scale(1.018); } }

/* First/floor column stays visible while horizontally scrolling on phones. */
.inventory-table td[data-col="1"] { position: sticky; left: 0; z-index: 6; }
.inventory-table tr:first-child td[data-col="1"], .inventory-table tr:nth-child(2) td[data-col="1"] { z-index: 8; }

footer { margin-top: auto; padding: 16px clamp(16px,3vw,38px) 22px; color: #667085; font-size: 11px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.modal { border: 0; border-radius: 16px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: min(90vh, 820px); box-shadow: 0 26px 80px rgba(0,0,0,.28); }
.modal::backdrop { background: rgba(15,23,42,.62); backdrop-filter: blur(2px); }
.modal-sm { width: min(430px, calc(100vw - 24px)); }
.modal-wide { width: min(980px, calc(100vw - 24px)); }
.modal-form { padding: 20px; overflow: auto; max-height: min(90vh, 820px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.icon-btn { border: 0; background: #f2f4f7; color: #344054; border-radius: 9px; width: 34px; height: 34px; font-size: 22px; line-height: 1; }
.modal-form > label, .form-grid label { display: flex; flex-direction: column; gap: 6px; color: #344054; font-size: 12px; font-weight: 700; }
.modal input, .modal select, .modal textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 9px; padding: 9px 10px; outline: none; color: #101828; background: #fff; }
.modal input:focus, .modal select:focus, .modal textarea:focus { border-color: #667085; box-shadow: 0 0 0 3px rgba(102,112,133,.12); }
#loginForm > label + label { margin-top: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.full-width { grid-column: 1 / -1; }
.optional { color: #98a2b3; font-weight: 500; }
.unit-summary-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; padding: 10px; margin-bottom: 14px; border-radius: 12px; background: #f9fafb; border: 1px solid #eaecf0; }
.unit-summary-grid div { min-width: 0; }
.unit-summary-grid span { display: block; color: #667085; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; }
.unit-summary-grid strong { display: block; margin-top: 4px; font-size: 12px; overflow-wrap: anywhere; }
.preview-box { margin-top: 14px; border: 1px solid #d0d5dd; border-radius: 12px; overflow: hidden; }
.preview-box > span { display: block; padding: 7px 10px; background: #f2f4f7; color: #667085; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.preview-box pre { margin: 0; min-height: 80px; display: grid; place-items: center; text-align: center; padding: 12px; font: 700 12px/1.25 Calibri, Arial, sans-serif; white-space: pre-wrap; }
.safety-note { margin-top: 12px; padding: 9px 10px; border-radius: 9px; background: #fffaeb; color: #7a4f01; font-size: 11px; line-height: 1.4; }
.form-error { margin: 10px 0 0; color: #b42318; font-size: 12px; font-weight: 650; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid #eaecf0; }
.activity-body { overflow: auto; max-height: 58vh; }
.activity-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.activity-table th, .activity-table td { border-bottom: 1px solid #eaecf0; padding: 9px 8px; text-align: left; vertical-align: top; }
.activity-table th { position: sticky; top: 0; background: #fff; z-index: 1; color: #667085; font-size: 10px; text-transform: uppercase; letter-spacing: .35px; }
.status-text { text-transform: capitalize; font-weight: 750; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; max-width: min(420px, calc(100vw - 36px)); padding: 12px 14px; border-radius: 12px; background: #101828; color: #fff; box-shadow: 0 16px 44px rgba(0,0,0,.25); font-size: 12px; font-weight: 650; }

@media (max-width: 850px) {
  .app-header { position: relative; align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .main-content { padding-top: 12px; }
  .count-strip { grid-template-columns: repeat(2,1fr); }
  .control-row { align-items: stretch; flex-direction: column; }
  .search-form { width: 100%; min-width: 0; }
  .sheet-scroll { max-height: none; }
  .desktop-help { display: none; }
  .inventory-table { margin-left: 0; }
}
@media (max-width: 540px) {
  .brand-mark { width: 38px; height: 38px; }
  .app-header h1 { font-size: 15px; }
  .header-actions .btn { min-height: 36px; padding: 7px 10px; }
  .count-strip { gap: 7px; }
  .count-item { padding: 8px; }
  .legend-line { gap: 9px; }
  .sheet-toolbar { align-items: flex-start; flex-direction: column; }
  .sheet-help { text-align: left; }
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .unit-summary-grid { grid-template-columns: 1fr 1fr; }
  .modal-form { padding: 16px; }
}
