/* ===== ROOT VARIABLES ===== */
:root {
  --bg: #ffffff;
  --bg2: #f5f5f4;
  --bg3: #eeece8;
  --text: #1a1a18;
  --text2: #6b6b66;
  --text3: #a0a09a;
  --border: rgba(0,0,0,0.1);
  --border2: rgba(0,0,0,0.2);
  --radius: 8px;
  --radius-lg: 12px;
  --blue: #185FA5;
  --blue-bg: #E6F1FB;
  --blue-text: #0C447C;
  --green: #3B6D11;
  --green-bg: #EAF3DE;
  --green-text: #27500A;
  --amber: #854F0B;
  --amber-bg: #FAEEDA;
  --amber-text: #633806;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --red-text: #791F1F;
  --sidebar-w: 200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1c;
    --bg2: #272725;
    --bg3: #2f2f2c;
    --text: #e8e6df;
    --text2: #a0a09a;
    --text3: #6b6b66;
    --border: rgba(255,255,255,0.1);
    --border2: rgba(255,255,255,0.2);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg3);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* ===== APP LAYOUT ===== */
.app {
  display: flex;
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.logo {
  padding: 18px 16px 14px;
  border-bottom: 0.5px solid var(--border);
}

.logo-title { font-size: 15px; font-weight: 700; }
.logo-sub { font-size: 11px; color: var(--text2); margin-top: 3px; }

.nav-section {
  padding: 12px 16px 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text2);
  border-left: 2px solid transparent;
  transition: all .13s;
  user-select: none;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); border-left-color: var(--blue); font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 0.5px solid var(--border);
  font-size: 11px;
  color: var(--text3);
}

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  padding: 12px 22px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { flex: 1; overflow-y: auto; padding: 20px 22px; }

/* ===== BUTTONS ===== */
.btn {
  font-size: 12px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border2);
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: all .13s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { background: var(--bg2); }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { opacity: .88; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { opacity: .88; }
.btn-sm { font-size: 11px; padding: 3px 9px; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }

/* ===== PAGES ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 0.5px solid var(--border);
}

.stat-label { font-size: 11px; color: var(--text2); margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 11px; margin-top: 3px; }
.muted { color: var(--text2); }
.cv-blue { color: var(--blue); }
.cv-green { color: var(--green); }
.cv-amber { color: var(--amber); }
.cv-red { color: var(--red); }

/* ===== TABLE ===== */
.section-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.table-wrap {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 400px; }
th {
  background: var(--bg2);
  font-weight: 600;
  font-size: 11px;
  padding: 9px 12px;
  text-align: left;
  color: var(--text2);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-paid { background: var(--green-bg); color: var(--green-text); }
.badge-pending { background: var(--amber-bg); color: var(--amber-text); }
.badge-overdue { background: var(--red-bg); color: var(--red-text); }
.badge-occupied { background: var(--blue-bg); color: var(--blue-text); }
.badge-vacant { background: var(--green-bg); color: var(--green-text); }
.badge-maintenance { background: var(--amber-bg); color: var(--amber-text); }

/* ===== ROOM MAP ===== */
.wing-block { margin-bottom: 16px; }
.wing-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wing-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.room-row { display: flex; flex-wrap: wrap; gap: 5px; }
.room-cell {
  width: 46px;
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  transition: transform .1s;
  border: 0.5px solid transparent;
  user-select: none;
}
.room-cell:hover { transform: scale(1.12); z-index: 10; position: relative; }
.r-occupied { background: #B5D4F4; border-color: #378ADD; color: #0C447C; }
.r-vacant { background: #C0DD97; border-color: #639922; color: #27500A; }
.r-overdue { background: #F7C1C1; border-color: #E24B4A; color: #791F1F; }
.r-maintenance { background: #FAC775; border-color: #BA7517; color: #633806; }

.legend { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text2); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; }

/* ===== FILTER ROW ===== */
.filter-row { display: flex; gap: 7px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filter-btn {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 0.5px solid var(--border2);
  cursor: pointer;
  background: var(--bg);
  color: var(--text2);
  font-family: inherit;
  transition: all .13s;
}
.filter-btn.active, .filter-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

.search-input {
  font-size: 12px;
  padding: 6px 12px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  width: 180px;
}
.search-input:focus { outline: none; border-color: var(--blue); }

/* ===== TENANT CARDS ===== */
.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px,1fr));
  gap: 12px;
}
.tenant-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.tenant-card:hover { border-color: var(--border2); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.tc-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar-lg {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0; overflow: hidden;
}
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.tc-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.tc-room { font-size: 11px; color: var(--text2); }
.tc-row { display: flex; justify-content: space-between; font-size: 11px; padding: 3px 0; }
.tc-row span:first-child { color: var(--text2); }
.tc-row span:last-child { font-weight: 500; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border2);
  width: 520px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-wide { width: 660px; }
.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 0.5px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--bg); z-index: 1;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  cursor: pointer; font-size: 22px;
  color: var(--text2); background: none; border: none;
  font-family: inherit; line-height: 1;
}
.modal-body { padding: 18px 20px; flex: 1; overflow-y: auto; }
.modal-footer {
  padding: 12px 20px;
  border-top: 0.5px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  position: sticky; bottom: 0; background: var(--bg);
  flex-shrink: 0;
}

/* ===== FORMS ===== */
.form-row { margin-bottom: 12px; }
.form-label { font-size: 11px; color: var(--text2); margin-bottom: 4px; display: block; font-weight: 500; }
.form-input, .form-select {
  width: 100%; font-size: 13px;
  padding: 8px 11px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-family: inherit;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--blue); }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.sub-section-title {
  font-size: 11px; font-weight: 700;
  color: var(--text2);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 16px 0 10px;
  padding-bottom: 6px;
  border-bottom: 0.5px solid var(--border);
}

/* ===== PROFILE ===== */
.profile-header {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 18px;
}
.profile-avatar {
  width: 76px; height: 76px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 28px;
  flex-shrink: 0; overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.profile-room { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.profile-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.profile-tabs {
  display: flex;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.profile-tab {
  font-size: 12px; padding: 9px 16px;
  cursor: pointer; color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -0.5px;
  transition: all .13s; white-space: nowrap;
}
.profile-tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.profile-section { display: none; }
.profile-section.active { display: block; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; }
.info-item { padding: 9px 0; border-bottom: 0.5px solid var(--border); }
.info-item:nth-last-child(-n+2) { border-bottom: none; }
.info-item-label { font-size: 10px; color: var(--text2); margin-bottom: 3px; font-weight: 500; }
.info-item-val { font-size: 13px; font-weight: 500; }

.pay-history-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 12px;
}
.pay-history-row:last-child { border-bottom: none; }

.pay-summary-mini { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.mini-stat { background: var(--bg2); border-radius: var(--radius); padding: 10px; text-align: center; }
.mini-stat-val { font-size: 20px; font-weight: 700; }
.mini-stat-lbl { font-size: 10px; color: var(--text2); margin-top: 2px; }

.detail-row {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-bottom: 0.5px solid var(--border); font-size: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text2); }

.upload-area {
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius);
  padding: 20px; text-align: center;
  cursor: pointer; transition: background .13s; margin-top: 10px;
}
.upload-area:hover { background: var(--bg2); }

.doc-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 0.5px solid var(--border); font-size: 12px;
}
.doc-item:last-child { border-bottom: none; }
.note-box {
  background: var(--bg2); border-radius: var(--radius);
  padding: 12px; font-size: 12px; color: var(--text2); margin-top: 10px;
  border-left: 3px solid var(--blue);
}

/* ===== PAYMENT SUMMARY ===== */
.pay-summary {
  display: grid; grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 10px; margin-bottom: 16px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ===== SETTINGS ===== */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); gap: 16px; }
.settings-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.settings-card-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; z-index: 999;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text2); font-size: 13px;
}
.empty-state-icon { font-size: 36px; margin-bottom: 10px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .two-col { grid-template-columns: 1fr; }
  .form-grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .sidebar { width: 54px; }
  .logo-title, .logo-sub, .nav-section, .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .sidebar-footer { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid2, .form-grid3 { grid-template-columns: 1fr; }
  .modal { width: 100% !important; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; max-height: 85vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .tenant-grid { grid-template-columns: 1fr 1fr; }
}
