:root {
  /* Colors - Grihavana Purple & Gold Palette */
  --primary-50:  #FAF5FF;
  --primary-100: #F3E8FF;
  --primary-200: #E9D5FF;
  --primary-300: #D8B4FE;
  --primary-400: #C084FC;
  --primary-500: #A855F7;
  --primary-600: #9333EA;
  --primary-700: #7E22CE;
  --primary-800: #581C87;
  --primary-900: #3B0764;
  --primary-950: #1A032E;

  /* Gold Accents */
  --gold-50:  #FDFBF5;
  --gold-100: #FBF6E9;
  --gold-200: #F5E8BE;
  --gold-300: #EED993;
  --gold-400: #E0C068;
  --gold-500: #C9A84C;
  --gold-600: #A88636;
  --gold-700: #826425;
  --gold-800: #5C4417;
  --gold-900: #3B2A0C;

  /* Neutrals */
  --slate-50:  #F8FAFC;
  --slate-100: #F1F5F9;
  --slate-200: #E2E8F0;
  --slate-300: #CBD5E1;
  --slate-400: #94A3B8;
  --slate-500: #64748B;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1E293B;
  --slate-900: #0F172A;

  /* Semantic */
  --emerald-50:  #ECFDF5;
  --emerald-500: #10B981;
  --emerald-600: #059669;
  --emerald-700: #047857;

  --amber-50:  #FFFBEB;
  --amber-500: #F59E0B;
  --amber-600: #D97706;
  --amber-700: #B45309;

  --rose-50:  #FFF1F2;
  --rose-500: #F43F5E;
  --rose-600: #E11D48;
  --rose-700: #BE123C;

  --white: #FFFFFF;

  /* Dimensions */
  --topbar-height: 64px;
  --sidebar-width: 250px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

/* ==========================================================================
   CSS Reset & Global Defaults
   ========================================================================== */

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--slate-50);
  color: var(--slate-800);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--primary-700);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--primary-900);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ==========================================================================
   App Shell Layout
   ========================================================================== */

.app-container {
  display: block;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: linear-gradient(90deg, var(--primary-950) 0%, var(--primary-900) 50%, var(--primary-800) 100%);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1000;
  border-bottom: 1px solid rgba(201, 168, 76, 0.35);
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.hamburger {
  display: none;
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.hamburger:hover {
  background: rgba(255, 255, 255, 0.1);
}

.brand {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--white);
  line-height: 1.2;
}

.brand-name .badge-admin {
  background: var(--gold-500);
  color: var(--primary-950);
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.05em;
}

.building-name {
  font-size: 0.75rem;
  color: var(--gold-300);
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 500;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-700);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  border: 1px solid var(--gold-500);
}

.btn-logout {
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-logout:hover {
  background: var(--gold-500);
  color: var(--primary-950);
  border-color: var(--gold-500);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--primary-950);
  border-right: 1px solid rgba(201, 168, 76, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 900;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
}

.sidebar-logo {
  max-height: 38px;
  width: auto;
  object-fit: contain;
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
  color: var(--gold-400);
  background: rgba(201, 168, 76, 0.15);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--gold-500);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-link.active .nav-icon {
  opacity: 1;
  color: var(--gold-400);
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 850;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   Main Content Area - Desktop (> 768px)
   ========================================================================== */
@media (min-width: 769px) {
  .main-content {
    margin-top: var(--topbar-height);
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    min-height: calc(100vh - var(--topbar-height));
    padding: 1.5rem 2rem;
    box-sizing: border-box;
    display: block;
  }
}

.container-xl {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ==========================================================================
   Page Headers & Action Bars
   ========================================================================== */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary-900);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--slate-500);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   Stats Cards (SaaS KPI Grid)
   ========================================================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  min-width: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--gold-400);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gold-500);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.stat-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
}

.stat-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--primary-50);
  color: var(--primary-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary-900);
  line-height: 1.1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.stat-footer {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--slate-500);
}

/* Card Variations */
.stat-card.success .stat-value { color: var(--emerald-700); }
.stat-card.warning .stat-value { color: var(--amber-700); }
.stat-card.danger  .stat-value { color: var(--rose-700); }

/* ==========================================================================
   Cards & Panels
   ========================================================================== */

.card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-900);
  letter-spacing: -0.01em;
}

.card-body {
  padding: 1.25rem;
}

.card-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--slate-200);
  background: var(--slate-50);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Desktop 2-Column Split Grid */
.dashboard-pc-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 1.25rem;
  align-items: start;
  width: 100%;
}

/* ==========================================================================
   SaaS Data Tables
   ========================================================================== */

.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.table th {
  background: var(--slate-50);
  color: var(--slate-600);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--slate-200);
  white-space: nowrap;
}

.table td {
  padding: 12px 14px;
  color: var(--slate-700);
  border-bottom: 1px solid var(--slate-200);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color 0.15s ease;
}

.table tbody tr:hover {
  background-color: var(--slate-50);
}

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

/* ==========================================================================
   Badges & Status Pills
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.badge-success, .badge-paid { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-500); }
.badge-warning, .badge-partial { background: var(--amber-50);   color: var(--amber-700);   border: 1px solid var(--amber-500); }
.badge-danger,  .badge-unpaid  { background: var(--rose-50);    color: var(--rose-700);    border: 1px solid var(--rose-500); }
.badge-gold    { background: var(--gold-100);   color: var(--gold-800);    border: 1px solid var(--gold-500); }
.badge-default, .badge-not_generated { background: var(--slate-100);  color: var(--slate-700);   border: 1px solid var(--slate-300); }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary-900); color: var(--white); border-color: var(--primary-950); }
.btn-primary:hover { background: var(--primary-950); color: var(--white); }

.btn-gold { background: var(--gold-500); color: var(--primary-950); border-color: var(--gold-600); }
.btn-gold:hover { background: var(--gold-600); color: var(--primary-950); }

.btn-outline { background: var(--white); color: var(--slate-700); border-color: var(--slate-300); }
.btn-outline:hover { background: var(--slate-50); color: var(--slate-900); border-color: var(--slate-400); }

.btn-whatsapp {
  background: #25D366 !important;
  color: #FFFFFF !important;
  border: 1px solid #1EBE5D !important;
  font-weight: 700 !important;
}

.btn-whatsapp:hover {
  background: #1EBE5D !important;
  color: #FFFFFF !important;
  border-color: #128C7E !important;
}

.btn-success {
  background: #10B981 !important;
  color: #FFFFFF !important;
  border-color: #059669 !important;
}

.btn-danger {
  background: #E11D48 !important;
  color: #FFFFFF !important;
  border-color: #BE123C !important;
}

.btn-sm { padding: 5px 10px; font-size: 0.8125rem; }

/* ==========================================================================
   Forms & Controls
   ========================================================================== */

.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--slate-700); margin-bottom: 5px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.875rem;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--slate-900);
}
.form-control:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.2);
}

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ==========================================================================
   Flash Messages
   ========================================================================== */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 500;
}
.flash-success { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-500); }
.flash-error   { background: var(--rose-50);    color: var(--rose-700);    border: 1px solid var(--rose-500); }
.flash-close { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; line-height: 1; }

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-title { font-size: 1.15rem; font-weight: 700; color: var(--slate-800); margin-bottom: 0.35rem; }
.empty-desc { font-size: 0.875rem; color: var(--slate-500); margin-bottom: 1.25rem; }

.app-footer {
  padding: 1.5rem 0 0;
  margin-top: auto;
  border-top: 1px solid var(--slate-200);
  font-size: 0.75rem;
  color: var(--slate-400);
  text-align: center;
}

/* ==========================================================================
   Mobile & Responsive Breakpoints
   ========================================================================== */

@media (max-width: 991px) {
  .dashboard-pc-grid {
    grid-template-columns: 1fr !important;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 768px) {
  html, body, .app-container {
    overflow-x: hidden;
  }

  .hamburger {
    display: block;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-top: var(--topbar-height) !important;
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 1.25rem 1rem 5.5rem !important;
    box-sizing: border-box !important;
    display: block !important;
  }

  .container-xl {
    width: 100% !important;
    max-width: 100% !important;
  }

  .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 0.875rem !important;
    width: 100% !important;
  }

  .stat-card {
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .topbar-right .user-badge {
    display: none;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    width: 100%;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .header-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .header-actions .btn {
    width: 100% !important;
    flex: none;
    justify-content: center;
  }

  /* Bottom Nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--primary-950);
    border-top: 1px solid rgba(201, 168, 76, 0.3);
    z-index: 800;
  }

  .bottom-nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.7rem;
    gap: 3px;
  }

  .bottom-nav-link.active {
    color: var(--gold-400);
  }
}

@media print {
  .no-print, .topbar, .sidebar, .bottom-nav {
    display: none !important;
  }
  .main-content {
    margin: 0 !important;
    padding: 0 !important;
  }
}

/* ==========================================================================
   Floating PWA Install Banner
   ========================================================================== */

.pwa-install-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 400px;
  width: calc(100% - 48px);
  background: var(--primary-950);
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  animation: slideUpFade 0.3s ease-out;
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .pwa-install-banner {
    bottom: 74px; /* Above mobile bottom-nav */
    left: 16px;
    right: 16px;
    width: auto;
  }
}
