:root {
  /* ธีมหลัก: เขียวสดใส ไล่เฉด */
  --brand: #22c55e;
  --brand-dark: #15803d;
  --brand-light: #ecfdf5;
  --brand-gradient: linear-gradient(135deg, #4ade80 0%, #16a34a 55%, #15803d 100%);
  --blue: #22c55e;
  --blue-dark: #15803d;
  --blue-light: #ecfdf5;
  /* สีสถานะ "มีผู้เช่า/กำลังดำเนินการ" แยกจากสีธีมหลัก (เขียว) เพื่อให้แยกแยะจากสถานะ "ว่าง" ได้ชัดเจน */
  --status-info: #4f46e5;
  --status-info-light: #eef2ff;
  --green: #16a34a;
  --green-light: #dcfce7;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans Thai', 'Noto Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(160deg, #ecfdf5 0%, #f8fafc 38%, #f8fafc 100%);
  color: var(--gray-900);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: inherit; text-decoration: none; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: #fff; border-right: 1px solid var(--gray-200);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand-gradient); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }
.brand .name { font-weight: 700; font-size: 15px; }
.brand .sub { font-size: 11px; color: var(--gray-500); }

.nav-group { margin-bottom: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--gray-700); font-size: 14px; font-weight: 500; cursor: pointer; margin-bottom: 2px;
}
.nav-item .ic { width: 18px; text-align: center; }
.nav-item:hover { background: var(--gray-100); }
.nav-item.active { background: var(--brand-gradient); color: #fff; }

.main { flex: 1; min-width: 0; padding: 22px 26px 90px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 10px; }
.topbar h1 { font-size: 19px; margin: 0; }
.topbar .actions { display: flex; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--gray-500); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-light); color: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

/* Mobile bottom nav */
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 12px 84px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff;
    border-top: 1px solid var(--gray-200); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; z-index: 40;
  }
  .bottom-nav .bn-item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--gray-500); padding: 4px 6px; border-radius: 10px; flex: 1; }
  .bottom-nav .bn-item.active { color: var(--blue); }
  .bottom-nav .bn-item .ic { font-size: 18px; }
}

/* ---------- Cards / Grid ---------- */
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }

.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--gray-700); }
.stat-card .stat-value { font-size: 26px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.stat-card.tone-red .stat-value { color: var(--red); }
.stat-card.tone-amber .stat-value { color: var(--amber); }
.stat-card.tone-green .stat-value { color: var(--green); }
.stat-card.tone-blue .stat-value { color: var(--blue); }

/* Donut */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.donut { width: 168px; height: 168px; border-radius: 50%; display: flex; align-items: center; justify-content: center; position: relative; }
.donut .hole { width: 108px; height: 108px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut .hole b { font-size: 24px; }
.donut .hole span { font-size: 11px; color: var(--gray-500); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; font-size: 12.5px; color: var(--gray-700); }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* ---------- Table / List ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; color: var(--gray-500); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
table.tbl td { padding: 10px; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
table.tbl tr:hover td { background: var(--gray-50); }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--gray-100); font-size: 13.5px; }
.list-row:last-child { border-bottom: none; }
.list-row .rm { font-weight: 600; }
.list-row .amt { font-weight: 700; }
.meta { color: var(--gray-500); font-size: 12px; }

/* Badge */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.paid { background: var(--green-light); color: #166534; }
.badge.pending { background: var(--amber-light); color: #92400e; }
.badge.overdue { background: var(--red-light); color: #991b1b; }
.badge.vacant { background: var(--green-light); color: #166534; }
.badge.occupied { background: var(--status-info-light); color: var(--status-info); }
.badge.reserved { background: var(--amber-light); color: #92400e; }
.badge.maintenance { background: var(--gray-100); color: var(--gray-500); }
.badge.open { background: var(--amber-light); color: #92400e; }
.badge.in_progress { background: var(--status-info-light); color: var(--status-info); }
.badge.done { background: var(--green-light); color: #166534; }
.badge.cancelled { background: var(--gray-100); color: var(--gray-500); }

/* ---------- Buttons / Forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 10px; padding: 9px 15px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--brand-gradient); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-outline { background: #fff; border: 1px solid var(--gray-200); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--gray-500); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--gray-200); border-radius: 10px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 500px) { .field-row { grid-template-columns: 1fr; } }

/* ---------- Room grid ---------- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.room-tile { border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: #fff; box-shadow: var(--shadow); }
.room-tile .no { font-weight: 700; font-size: 15px; }
.room-tile .st { font-size: 10.5px; opacity: .9; margin-top: 2px; }
.room-tile.vacant { background: var(--brand-gradient); }
.room-tile.occupied { background: var(--status-info); }
.room-tile.reserved { background: #d97706; }
.room-tile.maintenance { background: #64748b; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal { background: #fff; border-radius: 18px 18px 0 0; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal h2 { margin: 0 0 14px; font-size: 16px; }
.modal .close { position: absolute; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Toast */
#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast-msg { background: var(--gray-900); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); }
.toast-msg.error { background: var(--red); }
.toast-msg.success { background: var(--green); }

/* Login page */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #ecfdf5 0%, #f8fafc 45%, #f8fafc 100%); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; }
.auth-card .logo { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-gradient); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; margin: 0 auto 14px; }
.auth-card h1 { text-align: center; font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 20px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; }

.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 10px; }
.muted { color: var(--gray-500); }
.empty-state { text-align: center; padding: 40px 16px; color: var(--gray-500); font-size: 13.5px; }
.spacer-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;}
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input { flex: 1; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--gray-200); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #fff; border: 1px solid var(--gray-200); color: var(--gray-700); cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--brand-gradient); color: #fff; border-color: var(--brand); }

.loading { text-align: center; padding: 40px; color: var(--gray-400); }
