:root {
  --primary: #1B3A6B;
  --primary-dark: #12284f;
  --secondary: #2E6DB4;
  --accent: #F5A623;
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --text: #222222;
  --muted: #888888;
  --border: #DDDDDD;
  --danger: #D32F2F;
  --success: #388E3C;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Microsoft JhengHei', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: white;
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 { font-size: 1.4rem; font-weight: 600; }
header p { font-size: 0.78rem; opacity: 0.7; margin-top: 2px; }

/* ── Toast ── */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  background: var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: opacity 0.3s;
  max-width: 320px;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.warning { background: #E65100; }
.toast.success { background: var(--success); }

/* ── Stats Bar ── */
.stats-bar {
  background: white;
  display: flex;
  border-bottom: 1px solid #eee;
  overflow-x: auto;
}
.stat {
  padding: 14px 24px;
  border-right: 1px solid #eee;
  text-align: center;
  white-space: nowrap;
}
.stat .num { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.stat .label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }

/* ── Filter Bar ── */
.filter-bar {
  background: white;
  padding: 12px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid #ddd;
}
.filter-bar label {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.filter-bar select,
.filter-bar input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.84rem;
  font-family: inherit;
  background: white;
}
.filter-bar select { min-width: 110px; }
.filter-bar input[type="text"] { min-width: 160px; }
.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--secondary);
}
.range-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.range-inputs input { width: 80px; }
.range-inputs span { color: var(--muted); font-size: 0.8rem; }

.btn-secondary {
  padding: 7px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { background: #f0f0f0; }
.btn-secondary.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-primary {
  padding: 7px 16px;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: inherit;
  color: white;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary:hover { background: var(--primary-dark); }

.star-col { min-width: 56px; }

.rank-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 1px 5px;
  margin-left: 2px;
  vertical-align: middle;
}

.badge.priority { background: #7b1fa2; }

.move-btns { display: flex; flex-direction: column; gap: 1px; }

/* ── Table ── */
.table-wrap { padding: 16px 20px; overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  min-width: 900px;
}
thead { background: var(--primary); color: white; }
th {
  padding: 10px 12px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
th:hover { background: var(--primary-dark); }
th .sort-arrow { font-size: 0.6rem; margin-left: 3px; opacity: 0.35; }
th.sorted .sort-arrow { opacity: 1; }

tbody tr { border-bottom: 1px solid #f0f0f0; }
tbody tr:nth-child(even) { background: #EEF4FA; }
tbody tr:hover { background: #e3eef8; }
tbody tr.sold { opacity: 0.6; }
tbody tr.priority-row {
  border-left: 3px solid var(--accent);
}

td { padding: 8px 10px; font-size: 0.84rem; text-align: center; }
td.estate { text-align: left; font-weight: 500; }
td.price { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Star Button ── */
.star-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: transform 0.15s;
  line-height: 1;
}
.star-btn:hover { transform: scale(1.2); background: #fff3cd; }
.star-btn.favorited { color: var(--accent); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge.sold { background: #c8e6c9; color: #2e7d32; }
.badge.new { background: #fff3e0; color: #e65100; }

/* ── PDF Button ── */
.pdf-btn {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--secondary);
  color: var(--secondary);
  transition: all 0.15s;
}
.pdf-btn:hover { background: var(--secondary); color: white; }
.pdf-btn.disabled {
  border-color: #ccc;
  color: #ccc;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
}
.pagination button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.84rem;
  font-family: inherit;
}
.pagination button:hover:not(:disabled) { background: #f0f0f0; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 0.82rem; color: var(--muted); }

/* ── Priority Panel ── */
.priority-panel {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: white;
  border-radius: 12px 0 0 12px;
  box-shadow: -2px 0 12px rgba(0,0,0,0.15);
  width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 500;
  display: none;
}
.priority-panel.open { display: block; }
.priority-panel.open ~ .modal { /* no change */ }
.priority-panel h3 {
  padding: 12px 14px;
  background: var(--primary);
  color: white;
  font-size: 0.85rem;
  border-radius: 12px 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.priority-list { padding: 8px; }
.priority-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  border: 1px solid #eee;
  margin-bottom: 4px;
  background: #fffef0;
}
.priority-item .rank {
  font-weight: 700;
  color: var(--accent);
  min-width: 20px;
}
.priority-item .unit-info { flex: 1; }
.priority-item .move-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 1px 4px;
  color: var(--muted);
}
.priority-item .move-btn:hover { background: #eee; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 48px; color: var(--muted); }

/* ── Modal ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }
.modal-content {
  background: white;
  border-radius: 10px;
  width: 95vw;
  height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 10px 10px 0 0;
  font-size: 0.88rem;
}
.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
#pdfFrame {
  flex: 1;
  border: none;
  border-radius: 0 0 10px 10px;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  header { padding: 14px 16px; }
  .filter-bar { padding: 10px 14px; }
  .table-wrap { padding: 10px 8px; }
  .priority-panel { width: 180px; }
  th, td { font-size: 0.78rem; padding: 6px 6px; }
}
