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

:root {
  --bg-dark: #1a1d23;
  --bg-sidebar: #12141a;
  --bg-main: #f5f6fa;
  --bg-card: #ffffff;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-sidebar: #9ca3af;
  --text-sidebar-active: #ffffff;
  --border: #e5e7eb;
  --badge-gray: #9ca3af;
  --badge-blue: #3b82f6;
  --badge-orange: #f59e0b;
  --badge-yellow: #eab308;
  --badge-green: #22c55e;
  --badge-purple: #a855f7;
  --badge-red: #ef4444;
  --red: #ef4444;
  --orange: #f97316;
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary);
  background: var(--bg-main);
  overflow: hidden;
  height: 100vh;
}

/* LOGIN */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%);
}
.login-box {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 48px 40px;
  width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box h1 {
  font-size: 24px;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.login-box .sub {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}
.login-box label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.login-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.login-box input:focus {
  border-color: var(--accent);
}
.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.login-box button:hover {
  background: var(--accent-hover);
}
.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

/* APP LAYOUT */
#app-layout {
  display: flex;
  height: 100vh;
  display: none;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 20px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header .logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.sidebar-header .logo span {
  color: var(--accent);
}
.sidebar-close {
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 18px;
  cursor: pointer;
}
.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-sidebar);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-sidebar-active);
}
.nav-item.active {
  background: rgba(245,158,11,0.15);
  color: var(--accent);
}
.nav-item .icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
}
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}
.sidebar-user .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
}
.sidebar-user .info .name {
  font-size: 13px;
  font-weight: 600;
  color: white;
}
.sidebar-user .info .role {
  font-size: 11px;
  color: var(--text-sidebar);
}

/* MAIN */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-left h2 {
  font-size: 16px;
  font-weight: 600;
}
.segment-selector {
  display: flex;
  gap: 4px;
  background: var(--bg-main);
  border-radius: 8px;
  padding: 3px;
}
.segment-btn {
  padding: 5px 14px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.segment-btn.active {
  background: white;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.demo-badge {
  font-size: 12px;
  color: var(--accent);
  background: #fff7ed;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 500;
}
.demo-tag {
  font-size: 11px;
  color: var(--accent);
  background: #fff7ed;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 4px 10px;
  font-weight: 600;
  white-space: nowrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-right .user-badge {
  font-size: 13px;
  color: var(--text-secondary);
}
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* MODULES */
.module {
  display: none;
}
.module.active {
  display: block;
}

/* CARDS */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
}

/* DASHBOARD */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
}
.metric-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.metric-card .value {
  font-size: 28px;
  font-weight: 700;
}
.charts-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  min-height: 280px;
}
.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}
.alerts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.alert-card, .checkin-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  min-height: 300px;
}
.alert-card h3, .checkin-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.alert-item:last-child {
  border-bottom: none;
}
.alert-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.checkin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.checkin-table th {
  text-align: left;
  padding: 8px 6px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.checkin-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
.map-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  min-height: 220px;
  margin-bottom: 24px;
}
.map-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.map-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 160px;
  background: var(--bg-main);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* TABLE */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.table-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.table-header .count {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 14px;
}
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-primary);
  transition: all 0.15s;
}
.btn:hover {
  background: var(--bg-main);
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.filter-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: white;
  color: var(--text-primary);
  cursor: pointer;
}
.status-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  background: var(--bg-main);
  border-radius: 8px;
  padding: 3px;
}
.status-tab {
  padding: 6px 14px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.status-tab.active {
  background: white;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 8px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover {
  background: rgba(0,0,0,0.01);
}
.data-table .warning-icon {
  color: var(--orange);
  margin-right: 4px;
}
.data-table .date-overdue {
  color: var(--red);
  font-weight: 500;
}
.id-cell {
  font-weight: 600;
  color: var(--text-primary);
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-blue { background: #eff6ff; color: #2563eb; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-yellow { background: #fefce8; color: #a16207; }
.badge-green { background: #f0fdf4; color: #16a34a; }
.badge-purple { background: #faf5ff; color: #7c3aed; }
.badge-red { background: #fef2f2; color: #dc2626; }

/* toggle */
.toggle-group {
  display: flex;
  gap: 4px;
  background: var(--bg-main);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 16px;
}
.toggle-btn {
  padding: 6px 16px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.toggle-btn.active {
  background: white;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* property cards */
.property-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.property-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
}
.property-card .name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.property-card .address {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.property-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}
.property-stat {
  text-align: center;
}
.property-stat .val {
  font-size: 20px;
  font-weight: 700;
}
.property-stat .lbl {
  font-size: 11px;
  color: var(--text-secondary);
}
.occupancy-bar {
  height: 6px;
  background: var(--bg-main);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.occupancy-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}
.property-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

/* B2B Pipeline */
.pipeline-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pipeline-table th {
  text-align: left;
  padding: 10px 8px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
}
.pipeline-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

/* automations */
.automation-row {
  display: flex;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.automation-row:last-child {
  border-bottom: none;
}
.automation-row .name {
  flex: 2;
  font-weight: 600;
}
.automation-row .trigger {
  flex: 2;
  color: var(--text-secondary);
}
.automation-row .action {
  flex: 2;
  color: var(--text-secondary);
}
.automation-row .status {
  flex: 0.8;
}
.automation-row .last-run {
  flex: 0.8;
  color: var(--text-secondary);
  text-align: right;
}
.auto-header {
  display: flex;
  padding: 10px 0;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.auto-header .name { flex: 2; }
.auto-header .trigger { flex: 2; }
.auto-header .action { flex: 2; }
.auto-header .status { flex: 0.8; }
.auto-header .stats { flex: 0.6; text-align: right; }
.auto-header .last-run { flex: 0.8; text-align: right; }

/* simple chart bars */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding-top: 10px;
}
.bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
}
.bar-pair {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 100%;
  width: 100%;
  justify-content: center;
}
.bar-student {
  width: 16px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  min-height: 4px;
}
.bar-apartment {
  width: 16px;
  border-radius: 3px 3px 0 0;
  background: #3b82f6;
  min-height: 4px;
}
.bar-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 6px;
}
.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
  font-size: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.donut-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  height: 200px;
}
.donut-canvas {
  position: relative;
  width: 140px;
  height: 140px;
}
.donut-canvas svg {
  transform: rotate(-90deg);
}
.donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.donut-center .val {
  font-size: 20px;
  font-weight: 700;
}
.donut-center .lbl {
  font-size: 11px;
  color: var(--text-secondary);
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.donut-legend-item .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open {
  display: flex;
}
.modal-box {
  background: white;
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.3);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.modal-close:hover {
  background: var(--bg-main);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-right: 40px;
}
.modal-title {
  font-size: 22px;
  font-weight: 700;
}
.modal-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.detail-section {
  margin-bottom: 20px;
}
.detail-section h4 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}
.detail-label {
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-right: 12px;
  min-width: 120px;
}
.timeline {
  position: relative;
  padding-left: 20px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding: 0 0 16px 20px;
  font-size: 13px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
}
.timeline-date {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.timeline-event {
  font-weight: 500;
}
.modal-box::-webkit-scrollbar {
  width: 6px;
}
.modal-box::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

/* logout btn */
.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-sidebar);
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  border-radius: 8px;
  transition: all 0.15s;
}
.logout-btn:hover {
  background: rgba(239,68,68,0.12);
  color: #ef4444;
}

/* dashboard extra */
.metrics-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

/* map markers */
.map-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-marker {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-main);
  border-radius: 10px;
  transition: background 0.15s;
}
.map-marker:hover {
  background: #eef2ff;
}
.map-marker-pin {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}
.map-marker-info {
  flex: 1;
}
.map-marker-name {
  font-weight: 600;
  font-size: 14px;
}
.map-marker-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.map-marker-occ {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.occ-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* scrollbar */
.content::-webkit-scrollbar {
  width: 6px;
}
.content::-webkit-scrollbar-track {
  background: transparent;
}
.content::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}