/* ===================================================================
   components.css — ปุ่ม, การ์ด, input, badge, table
   ใช้ร่วมกันทุกหน้าในระบบ
   =================================================================== */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn:hover {
  border-color: var(--line-strong);
  background: var(--panel-hover);
}
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.btn-primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.btn-danger {
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover {
  background: var(--red-dim);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Form fields ---------- */
.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 6px;
}

.field input.has-error {
  border-color: var(--red);
}

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ---------- Stat / metric cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.stat {
  background: var(--panel);
  padding: 18px 16px;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.2;
}

.stat-num.warn { color: var(--amber); }
.stat-num.danger { color: var(--red); }

.stat-label {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 6px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-neutral { background: var(--bg-soft); color: var(--text-dim); border: 1px solid var(--line); }

/* ---------- Status dot ---------- */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.dot-accent { background: var(--accent); }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }
.dot-blue { background: var(--blue); }
.dot-faint { background: var(--text-faint); }

.dot-pulse {
  position: relative;
}
.dot-pulse::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: dot-pulse 2s infinite;
}
@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 rgba(63, 143, 95, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(63, 143, 95, 0); }
  100% { box-shadow: 0 0 0 0 rgba(63, 143, 95, 0); }
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover {
  background: var(--bg-soft);
}

/* ---------- Property list (เลือก/สลับสาขา) ---------- */
.property-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.property-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s;
  text-align: left;
}
.property-card:hover {
  border-color: var(--accent);
}
.p-status {
  flex-shrink: 0;
}
.p-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.p-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.p-meta {
  font-size: 11px;
  color: var(--text-faint);
}
.p-role {
  flex-shrink: 0;
}

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

.empty-state .ti {
  font-size: 32px;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.empty-state-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state-sub {
  font-size: 13px;
  color: var(--text-faint);
}

/* ---------- Loading spinner ---------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Toast notification ---------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px -10px rgba(43, 42, 40, 0.18);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  animation: toast-in 0.2s ease-out;
}

.toast-success { border-color: var(--green); }
.toast-error { border-color: var(--red); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   หน้า "ผังห้องพัก" — chip selector, entity card, room tile (สไตล์ตั๋ว/ตราประทับ)
   =================================================================== */

/* ---------- Chips (เลือกโซน / เลือกชั้น) ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.chip .chip-edit,
.chip .chip-delete {
  opacity: 0;
  font-size: 13px;
  transition: opacity 0.12s, color 0.12s;
}
.chip:hover .chip-edit,
.chip:hover .chip-delete {
  opacity: 0.65;
}
.chip.active .chip-edit,
.chip.active .chip-delete {
  color: var(--bg);
}
.chip .chip-edit:hover {
  opacity: 1;
}
.chip .chip-delete:hover {
  opacity: 1;
  color: var(--red);
}

/* ---------- Entity card grid (ตึก/อาคาร) ---------- */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.entity-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.entity-card:hover {
  border-color: var(--line-strong);
}
.entity-card.active {
  border-color: var(--accent);
}
.entity-card-name {
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 8px;
  padding-right: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entity-card-meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.entity-card-meta .ti {
  margin-right: 3px;
}
.entity-card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}
.entity-card:hover .entity-card-actions {
  opacity: 1;
}

.icon-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 13px;
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}
.icon-btn.danger:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ---------- Room tile grid (ผังห้องแบบกราฟิก — ทึบสี + กรอบจุดไข่ปลา ลายตั๋ว/ตราประทับ) ---------- */
.legend-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-faint);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
}
.room-tile {
  border-radius: 10px;
  padding: 5px;
  cursor: pointer;
  transition: transform 0.1s;
}
.room-tile:hover {
  transform: translateY(-2px);
}
.room-tile-inner {
  border: 1px dashed rgba(250, 248, 244, 0.55);
  border-radius: 7px;
  padding: 9px 4px;
  text-align: center;
}
.room-tile-number {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}
.room-tile-type {
  font-size: 10px;
  margin-top: 3px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-tile.st-available { background: var(--green); color: #F3F8F4; }
.room-tile.st-occupied { background: var(--blue); color: #F1F5F8; }
.room-tile.st-reserved { background: var(--amber); color: #FBF6EC; }
.room-tile.st-maintenance { background: var(--red); color: #FBEEEA; }
.room-tile.st-cleaning { background: var(--text-faint); color: #FAF8F4; }

/* ---------- Modal overlay (ใช้ร่วมกันทุกหน้าที่ต้องมีฟอร์ม popup) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 42, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal-card {
  max-width: 460px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
}
