:root {
  --glass-bg: rgba(255, 255, 255, 0.10);
  --glass-border: rgba(255, 255, 255, 0.15);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --glass-blur: 16px;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --primary-deep: #1d4ed8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 16px;
  --radius-sm: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-start, #0f172a) 0%, var(--bg-end, #1e3a5f) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--font-color, var(--text));
  line-height: 1.5;
}

/* ====== GLASS NAV ====== */
.nav-toggle { display: none; background: none; border: none; color: var(--nav-color); font-size: 1.5rem; cursor: pointer; padding: 0.25rem; }
nav {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 58px;
}
nav h1 { color: var(--title-color); font-size: 1.15rem; margin-right: auto; white-space: nowrap; letter-spacing: -0.02em; font-weight: 700; }
nav h1 span { color: var(--primary-light); }
.nav-links { display: flex; gap: 0.2rem; align-items: center; flex-wrap: wrap; }
nav a, nav .nav-link {
  color: var(--nav-color);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: all 0.2s;
}
nav a:hover, nav .nav-link:hover { color: var(--title-color); background: rgba(217,119,6,0.12); }
nav a.active {
  color: #fff;
  background: rgba(217, 119, 6, 0.4);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.15);
}

/* ====== CONTAINER ====== */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }

/* ====== GLASS CARD ====== */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin-bottom: 0.75rem; color: var(--title-color, #fff); font-size: 1.1rem; font-weight: 600; }
.card p, .card td, .card th, .card label, .card .label { color: var(--font-color); }

/* ====== GLASS STATS ====== */
.stats { display: grid; grid-template-columns: repeat(9, 1fr); gap: 0.25rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.4rem 0.3rem;
  text-align: center;
  box-shadow: var(--glass-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(0,0,0,0.12); }
.stat-card .value { font-size: 0.8rem; font-weight: 700; color: var(--title-color); }
.stat-card .label { color: var(--font-color); font-size: 0.5rem; margin-top: 0.05rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }

/* ====== TABLES ====== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; min-width: 600px; font-size: 0.875rem; }
th, td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid rgba(0,0,0,0.08); vertical-align: middle; }
th { background: rgba(0,0,0,0.04); font-weight: 600; color: var(--font-color); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
td { color: var(--font-color); }
tr:hover td { background: rgba(0,0,0,0.04); }
tr.row-overdue td { background: rgba(239, 68, 68, 0.08); }
tr.row-active td { background: rgba(16, 185, 129, 0.08); }
tr.row-expired td { background: rgba(100, 116, 139, 0.1); }

/* ====== BADGES ====== */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; backdrop-filter: blur(4px); }
.badge-paid { background: var(--success-bg); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
.badge-pending { background: var(--warning-bg); color: #fcd34d; border: 1px solid rgba(245,158,11,0.2); }
.badge-late, .badge-overdue { background: var(--danger-bg); color: #dc2626; border: 1px solid rgba(239,68,68,0.2); }
.badge-active { background: var(--success-bg); color: #059669; border: 1px solid rgba(16,185,129,0.2); }
.badge-expired, .badge-terminated { background: rgba(100,116,139,0.15); color: #64748b; border: 1px solid rgba(100,116,139,0.2); }
.badge-available { background: rgba(16,185,129,0.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
.badge-rented { background: rgba(59,130,246,0.15); color: #93c5fd; border: 1px solid rgba(59,130,246,0.2); }
.badge-occupied { background: rgba(217,119,6,0.25); color: #b45309; border: 1px solid rgba(217,119,6,0.4); }
.badge-maintenance { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.2); }
.badge-unavailable { background: rgba(100,116,139,0.15); color: #94a3b8; border: 1px solid rgba(100,116,139,0.2); }
.badge-confirmed { background: rgba(16,185,129,0.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
.badge-category { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.2); }

/* ====== DASHBOARD CLASSES ====== */
.empty-state { text-align: center; color: rgba(255,255,255,0.4); }
.amount-red { color: #fca5a5; font-weight: 600; }
.overdue-card { border-left: 4px solid rgba(239,68,68,0.5); }
.overdue-card h2 { color: #fca5a5; }
.overdue-card h2 i { color: #fca5a5; }
.dashboard-occupied-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  padding: 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.dashboard-overview-list { display: flex; flex-direction: column; }
.dashboard-overview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.9rem;
}
.dashboard-overview-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(255,255,255,0.7);
}
.dashboard-overview-left i { width: 18px; height: 18px; color: #6ee7b7; }
.dashboard-overview-row strong { color: #fff; font-size: 0.95rem; }
.dashboard-overview-row strong.green { color: #6ee7b7; }
.dashboard-overview-row strong.red { color: #fca5a5; }
.alert-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  border-left: 4px solid transparent;
}
.dashboard-alert-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
}
.dashboard-alert-item.overdue { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.2); color: #fca5a5; }
.dashboard-alert-item.overdue i { color: #fca5a5; }
.dashboard-alert-item.overdue strong { color: #fca5a5; }
.dashboard-alert-item.warning { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.2); color: #fcd34d; }
.dashboard-alert-item.warning i { color: #fcd34d; }
.dashboard-alert-item.warning strong { color: #fcd34d; }
.dashboard-alert-item.info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.15); color: #93bbfc; }
.dashboard-alert-item.info i { color: #93bbfc; }
.dashboard-alert-item.info strong { color: #93bbfc; }

/* Dashboard payment list */
.dashboard-pay-list { display: flex; flex-direction: column; gap: 0.5rem; }
.dashboard-pay-item {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dashboard-pay-left { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; }
.dashboard-pay-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dashboard-pay-icon.confirmed { background: rgba(16,185,129,0.15); color: #6ee7b7; }
.dashboard-pay-icon.pending { background: rgba(245,158,11,0.15); color: #fcd34d; }
.dashboard-pay-info { flex: 1; min-width: 0; }
.dashboard-pay-name { font-weight: 600; color: #fff; font-size: 0.9rem; }
.dashboard-pay-meta { color: rgba(255,255,255,0.5); font-size: 0.78rem; margin-top: 0.1rem; }
.dashboard-pay-right { text-align: right; flex-shrink: 0; margin-left: 0.75rem; }
.dashboard-pay-amount { font-weight: 700; color: #fff; font-size: 0.95rem; }

/* Dashboard expense list */
.dashboard-exp-list { display: flex; flex-direction: column; gap: 0.5rem; }
.dashboard-exp-item {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dashboard-exp-left { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; }
.dashboard-exp-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dashboard-exp-info { flex: 1; min-width: 0; }
.dashboard-exp-desc { font-weight: 600; color: #fff; font-size: 0.9rem; }
.dashboard-exp-meta { color: rgba(255,255,255,0.5); font-size: 0.78rem; margin-top: 0.1rem; }
.dashboard-exp-right { text-align: right; flex-shrink: 0; margin-left: 0.75rem; }
.dashboard-exp-amount { font-weight: 700; color: #fca5a5; font-size: 0.95rem; }

/* Dashboard overdue list */
.dashboard-overdue-list { display: flex; flex-direction: column; gap: 0.5rem; }
.dashboard-overdue-item {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(239,68,68,0.2);
  border-left: 4px solid #ef4444;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dashboard-overdue-left { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; }
.dashboard-overdue-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: rgba(239,68,68,0.15);
  color: #fca5a5;
}
.dashboard-overdue-info { flex: 1; min-width: 0; }
.dashboard-overdue-name { font-weight: 600; color: #fff; font-size: 0.9rem; }
.dashboard-overdue-meta { color: rgba(255,255,255,0.5); font-size: 0.78rem; margin-top: 0.1rem; }
.dashboard-overdue-right {
  text-align: right;
  flex-shrink: 0;
  margin-left: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
}
.dashboard-overdue-amount { font-weight: 700; color: #fca5a5; font-size: 0.95rem; }

/* ====== BUTTONS ====== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.5rem 1rem; border-radius: 8px; border: none; cursor: pointer;
  font-size: 0.85rem; font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: all 0.2s; line-height: 1.4;
  backdrop-filter: blur(4px);
}
.btn-primary { background: rgba(59, 130, 246, 0.35); color: #93c5fd; border: 1px solid rgba(59,130,246,0.25); }
.btn-primary:hover { background: rgba(59, 130, 246, 0.55); color: #fff; }
.btn-success { background: rgba(16, 185, 129, 0.3); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25); }
.btn-success:hover { background: rgba(16, 185, 129, 0.5); color: #fff; }
.btn-danger { background: rgba(239, 68, 68, 0.3); color: #fca5a5; border: 1px solid rgba(239,68,68,0.25); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.5); color: #fff; }
.btn-warning { background: rgba(245, 158, 11, 0.3); color: #fcd34d; border: 1px solid rgba(245,158,11,0.25); }
.btn-warning:hover { background: rgba(245, 158, 11, 0.5); color: #fff; }
.btn-outline { background: rgba(0,0,0,0.04); color: var(--font-color); border: 1px solid rgba(0,0,0,0.15); }
.btn-outline:hover { background: rgba(0,0,0,0.08); color: var(--title-color); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }

/* ====== FORMS ====== */
.form-group { margin-bottom: 0.85rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; color: var(--font-color); font-size: 0.85rem; opacity: 0.8; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.55rem 0.75rem;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  font-size: 0.9rem; font-family: inherit;
  color: var(--font-color);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-group input::placeholder { color: var(--font-color); opacity: 0.4; }
.form-group select option { background: #1e293b; color: #e2e8f0; }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }

/* ====== FLASH ====== */
.flash {
  padding: 0.7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
  font-weight: 500; font-size: 0.875rem; backdrop-filter: blur(8px);
}
.flash-success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
.flash-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.2); }

/* ====== LAYOUT HELPERS ====== */
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.header-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
.header-actions h2 { margin-bottom: 0; }
.form-inline { display: inline; }
.filter-bar { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 0.75rem; }

footer { text-align: center; padding: 2rem 1rem; color: var(--font-color); font-size: 0.8rem; opacity: 0.5; }

.backup-actions { display: flex; gap: 1rem; flex-wrap: wrap; }
.backup-box { flex: 1; min-width: 260px; }

/* ====== SPECIFIC OVERRIDES ====== */
.card[style*="border-left"] { border-left: 4px solid rgba(239, 68, 68, 0.5) !important; }
.card[style*="color"] h2 { color: #fca5a5 !important; }

/* ====== PWA SAFE AREA ====== */
@supports (padding-top: env(safe-area-inset-top)) {
  nav { padding-left: calc(1.5rem + env(safe-area-inset-left)); padding-right: calc(1.5rem + env(safe-area-inset-right)); }
  .container { padding-left: calc(1rem + env(safe-area-inset-left)); padding-right: calc(1rem + env(safe-area-inset-right)); padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
  footer { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
}
@media all and (display-mode: standalone) {
  nav { padding-top: max(0.5rem, env(safe-area-inset-top)); }
  body { -webkit-user-select: none; user-select: none; }
  input, textarea { -webkit-user-select: text; user-select: text; }
}

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none; position: absolute; top: 58px; left: 0; right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-direction: column; padding: 0.5rem;
    gap: 0.15rem; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    overflow-x: visible;
  }
  .nav-links.open { display: flex; }
  nav { position: relative; }
  nav a { width: 100%; padding: 0.55rem 0.75rem; }

  .container { padding: 1rem 0.75rem; }
  .card { padding: 1rem; border-radius: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 0.35rem; }
  .stat-card { padding: 0.5rem 0.4rem; }
  .stat-card .value { font-size: 0.85rem; }
  .form-row { grid-template-columns: 1fr; }
  .header-actions h2 { font-size: 1rem; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: 0.3rem; }
  .stat-card { padding: 0.4rem 0.3rem; }
  .stat-card .value { font-size: 0.8rem; }
  .stat-card .label { font-size: 0.55rem; }
  .btn { font-size: 0.8rem; padding: 0.45rem 0.8rem; }
  .btn-sm { font-size: 0.72rem; padding: 0.3rem 0.5rem; }
  th, td { padding: 0.5rem 0.5rem; font-size: 0.8rem; }
  .card { padding: 0.75rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .container { max-width: 100%; padding: 1.25rem 1rem; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
