/**
 * Quantum Code Technologies–inspired theme (quantumcode.co.ke)
 * Light futuristic UI · clean telemetry · violet/cyan accents
 */
:root {
  --qc-bg: #f8fafc;
  --qc-bg-elevated: rgba(255, 255, 255, 0.75);
  --qc-purple: #7c3aed;
  --qc-purple-dim: rgba(124, 58, 237, 0.12);
  --qc-cyan: #0891b2;
  --qc-green: #16a34a;
  --qc-green-dim: rgba(22, 163, 74, 0.12);
  --qc-amber: #d97706;
  --qc-rose: #db2777;
  --qc-border: rgba(124, 58, 237, 0.15);
  --qc-glow: 0 10px 30px rgba(124, 58, 237, 0.05), 0 1px 10px rgba(0, 0, 0, 0.02);
  --qc-font-display: 'Orbitron', sans-serif;
  --qc-font-body: 'Inter', system-ui, sans-serif;
  --qc-font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  font-family: var(--qc-font-body);
  background: var(--qc-bg);
  color: #0f172a;
  min-height: 100vh;
  overflow-x: hidden;
}

.font-orbitron { font-family: var(--qc-font-display); }
.font-mono { font-family: var(--qc-font-mono); }

/* Animated background */
.quantum-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 58, 237, 0.07), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(8, 145, 178, 0.05), transparent),
    var(--qc-bg);
}

.quantum-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(124, 58, 237, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 58, 237, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 40%, transparent 80%);
}

.quantum-scanline {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.2) 2px,
    rgba(255, 255, 255, 0.2) 4px
  );
  animation: scanMove 8s linear infinite;
  opacity: 0.3;
}

@keyframes scanMove {
  0% { transform: translateY(0); }
  100% { transform: translateY(4px); }
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.22;
}
.orb-purple {
  width: 400px;
  height: 400px;
  background: #a78bfa;
  top: -100px;
  right: -100px;
  animation: orbFloat 12s ease-in-out infinite;
}
.orb-cyan {
  width: 300px;
  height: 300px;
  background: #67e8f9;
  bottom: 10%;
  left: -80px;
  animation: orbFloat 15s ease-in-out infinite reverse;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(20px, 30px); }
}

#app {
  position: relative;
  z-index: 1;
}

/* Header */
#main-nav {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--qc-border);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 6px;
  filter: drop-shadow(0 2px 8px rgba(124, 58, 237, 0.15));
}

@media (min-width: 768px) {
  .brand-logo {
    width: 40px;
    height: 40px;
  }
  .brand-title {
    font-size: 0.95rem;
  }
}

.brand-title {
  font-family: var(--qc-font-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #0f172a !important;
  line-height: 1.1;
}

.brand-title span {
  display: block;
  font-size: 0.6rem;
  color: var(--qc-cyan);
  letter-spacing: 0.12em;
  font-family: var(--qc-font-mono);
  font-weight: 500;
}

#main-nav .nav-link {
  color: #475569;
  font-family: var(--qc-font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  font-weight: 500;
  padding: 0.4rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  transition: all 0.2s;
  text-transform: uppercase;
  white-space: nowrap;
}

#main-nav .nav-link:hover {
  color: var(--qc-purple);
  background: rgba(124, 58, 237, 0.05);
}

#main-nav .nav-link.active {
  color: #fff;
  background: var(--qc-purple);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
}

/* Panels */
.glass-panel,
.qc-panel {
  background: var(--qc-bg-elevated);
  backdrop-filter: blur(14px);
  border: 1px solid var(--qc-border);
  border-radius: 6px;
  box-shadow: var(--qc-glow);
  position: relative;
}

.qc-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--qc-purple), var(--qc-cyan), transparent);
  opacity: 0.8;
}

.sys-tag {
  font-family: var(--qc-font-mono);
  font-size: 0.65rem;
  color: var(--qc-purple);
  letter-spacing: 0.08em;
  font-weight: 600;
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border: 1px solid rgba(124, 58, 237, 0.2);
  background: rgba(124, 58, 237, 0.06);
  margin-bottom: 0.5rem;
}

.section-head {
  margin-bottom: 1.5rem;
}

.section-num {
  font-family: var(--qc-font-mono);
  font-size: 0.75rem;
  color: var(--qc-cyan);
  letter-spacing: 0.12em;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.section-title {
  font-family: var(--qc-font-display);
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(90deg, #1e1b4b 0%, var(--qc-purple) 60%, var(--qc-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.02em;
}

.section-desc {
  font-family: var(--qc-font-mono);
  font-size: 0.8rem;
  color: #475569;
  margin-top: 0.35rem;
  font-weight: 500;
}

.section-desc::before {
  content: '>_ ';
  color: var(--qc-cyan);
}

/* Inputs & buttons */
.cyber-input,
.qc-input {
  width: 100%;
  font-family: var(--qc-font-mono);
  font-size: 0.85rem;
  background: #ffffff;
  border: 1px solid rgba(124, 58, 237, 0.25);
  border-radius: 4px;
  padding: 0.7rem 0.9rem;
  color: #0f172a;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

.cyber-input:focus,
.qc-input:focus {
  outline: none;
  border-color: var(--qc-purple);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15), 0 8px 20px rgba(124, 58, 237, 0.05);
}

.cyber-input::placeholder {
  color: #94a3b8;
}

.cyber-btn,
.qc-btn {
  font-family: var(--qc-font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-radius: 4px;
  border: 1px solid var(--qc-purple);
  background: #ffffff;
  color: var(--qc-purple);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.cyber-btn:hover:not(:disabled),
.qc-btn:hover:not(:disabled) {
  background: var(--qc-purple);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.2);
}

.cyber-btn:disabled,
.qc-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.cyber-btn-accent,
.qc-btn-primary {
  background: var(--qc-purple);
  border-color: var(--qc-purple);
  color: #ffffff;
}

.cyber-btn-accent:hover:not(:disabled),
.qc-btn-primary:hover:not(:disabled) {
  background: #6d28d9;
  border-color: #6d28d9;
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.35);
}

.qc-btn-secondary {
  background: transparent;
  border-color: var(--qc-cyan);
  color: var(--qc-cyan);
}
.qc-btn-secondary:hover:not(:disabled) {
  background: rgba(6, 182, 212, 0.15);
  border-color: #22d3ee;
}

.qc-btn-danger {
  background: transparent;
  border-color: #ef4444;
  color: #ef4444;
}
.qc-btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
  border-color: #f87171;
}

.form-label {
  font-family: var(--qc-font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  margin-bottom: 0.35rem;
  display: block;
  font-weight: 600;
}

.form-label::before {
  content: '>_ ';
  color: var(--qc-purple);
}

/* Metrics */
.metric-card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--qc-border);
}

.metric-card .metric-value {
  font-family: var(--qc-font-display);
  color: #0f172a;
  font-weight: 700;
}

.metric-card.metric-green {
  border-left: 3px solid var(--qc-green);
}
.metric-card.metric-green .metric-value {
  color: var(--qc-green);
}

.metric-card.metric-warn {
  border-left: 3px solid var(--qc-amber);
}
.metric-card.metric-warn .metric-value {
  color: var(--qc-amber);
}

.metric-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(124, 58, 237, 0.03) 50%, transparent 60%);
  animation: shimmer 5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Clickable dashboard cards (open the records behind the figure) */
.metric-card[data-drill],
#collection-progress-panel[data-drill] {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.metric-card[data-drill]:hover,
#collection-progress-panel[data-drill]:hover {
  border-color: var(--qc-purple);
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.15);
}
.metric-card[data-drill]:focus-visible,
#collection-progress-panel[data-drill]:focus-visible {
  outline: 2px solid var(--qc-purple);
  outline-offset: 2px;
}

/* Collection progress bar */
.progress-track {
  height: 10px;
  background: rgba(15, 23, 42, 0.08);
  border: 1px solid var(--qc-border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--qc-green), #4ade80);
  border-radius: 999px;
  transition: width 0.6s ease;
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-family: var(--qc-font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-active {
  border: 1px solid rgba(22, 163, 74, 0.3);
  color: var(--qc-green);
  background: rgba(22, 163, 74, 0.05);
}
.badge-active .status-dot {
  background: var(--qc-green);
  box-shadow: 0 0 6px var(--qc-green);
  animation: pulse-dot 2s infinite;
}

.badge-expired {
  border: 1px solid rgba(225, 29, 72, 0.3);
  color: var(--qc-rose);
  background: rgba(225, 29, 72, 0.05);
}
.badge-expired .status-dot {
  background: var(--qc-rose);
  animation: pulse-dot 1.5s infinite;
}

.badge-suspended,
.badge-pending {
  border: 1px solid rgba(217, 119, 6, 0.3);
  color: var(--qc-amber);
  background: rgba(217, 119, 6, 0.05);
}
.badge-suspended .status-dot,
.badge-pending .status-dot { background: var(--qc-amber); }

.badge-vacant {
  border: 1px solid rgba(100, 116, 139, 0.3);
  color: #64748b;
  background: rgba(100, 116, 139, 0.05);
}
.badge-vacant .status-dot {
  background: #64748b;
}

.badge-sent {
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #818cf8;
  background: rgba(99, 102, 241, 0.05);
}
.badge-sent .status-dot {
  background: #818cf8;
}

.badge-delivered {
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #4ade80;
  background: rgba(34, 197, 94, 0.05);
}
.badge-delivered .status-dot {
  background: #4ade80;
}

.badge-read {
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #22d3ee;
  background: rgba(6, 182, 212, 0.05);
}
.badge-read .status-dot {
  background: #22d3ee;
}

.badge-failed {
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  background: rgba(239, 68, 68, 0.05);
}
.badge-failed .status-dot {
  background: #f87171;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* WhatsApp module */
.wa-qr-panel {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--qc-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
}

.wa-qr-panel.wa-qr-waiting {
  padding: 1.5rem 1rem;
  border: 1px dashed rgba(217, 119, 6, 0.3);
  border-radius: 6px;
  background: rgba(217, 119, 6, 0.03);
}

.wa-qr-panel.wa-linked {
  padding: 1rem;
  border: 1px solid rgba(22, 163, 74, 0.3);
  border-radius: 6px;
  background: rgba(22, 163, 74, 0.04);
  text-align: center;
}

.wa-gateway-section {
  margin-top: 0.5rem;
}

.wa-qr-image {
  display: block;
  margin: 0.75rem auto 0;
  padding: 0.5rem;
  background: #ffffff;
  border: 1px solid var(--qc-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  max-width: 100%;
  height: auto;
}

.whatsapp-module {
  border-color: rgba(22, 163, 74, 0.25) !important;
  background: rgba(255, 255, 255, 0.85);
}

.beacon-wrap {
  position: relative;
  width: 48px;
  height: 48px;
}
.beacon-pulse, .beacon-core {
  position: absolute;
  inset: 0;
  border-radius: 4px;
}
.beacon-green { background: var(--qc-green); }
.beacon-amber { background: var(--qc-amber); }
.beacon-red { background: var(--qc-rose); }
.beacon-pulse.beacon-green { animation: beacon-ping 2s infinite; opacity: 0.25; }
.beacon-pulse.beacon-amber { animation: beacon-ping 1.2s infinite; opacity: 0.2; }
.beacon-pulse.beacon-red { animation: beacon-ping 1s infinite; opacity: 0.2; }
.beacon-core { transform: scale(0.45); margin: auto; inset: 0; }

@keyframes beacon-ping {
  0% { transform: scale(0.5); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Tables */
.data-grid th {
  font-family: var(--qc-font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: #475569;
  text-transform: uppercase;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--qc-border);
  background: rgba(124, 58, 237, 0.03);
  text-align: left;
}

.data-grid td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(124, 58, 237, 0.06);
  font-size: 0.85rem;
  color: #334155;
}

.data-grid tr:hover td {
  background: rgba(124, 58, 237, 0.02);
}

/* ── In-app report tables ────────────────────────────────────────────────
   `.cyber-table` is applied to every report view (Monthly, Enhanced,
   Water Bills, Management Expenses, Commissions, Occupancy, Registers...).
   It guarantees professional, readable tables from the first view:
   consistent header styling, wrapping for long tenant/apartment names,
   zebra rows for tracking across wide grids, and a minimum width so the
   scroll wrapper kicks in instead of crushing columns on phones. */
.cyber-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  line-height: 1.4;
}
.cyber-table thead th {
  font-family: var(--qc-font-mono, monospace);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #1e3a5f;
  background: #eef2ff;
  border-bottom: 2px solid rgba(124, 58, 237, 0.35);
  border-right: 1px solid rgba(100, 116, 139, 0.15);
  padding: 0.6rem 0.7rem;
  text-align: left;
  vertical-align: middle;
  white-space: normal;
  overflow-wrap: anywhere;
}
.cyber-table tbody td {
  border-bottom: 1px solid rgba(100, 116, 139, 0.18);
  border-right: 1px solid rgba(100, 116, 139, 0.1);
  padding: 0.55rem 0.7rem;
  vertical-align: top;
  overflow-wrap: anywhere;
}
/* Zebra rows make wide rows easy to follow without misreading columns. */
.cyber-table tbody tr:nth-child(even) td {
  background: rgba(124, 58, 237, 0.035);
}
.cyber-table tbody tr:hover td {
  background: rgba(124, 58, 237, 0.08);
}
.cyber-table th:last-child,
.cyber-table td:last-child {
  border-right: none;
}
.cyber-table tfoot td {
  font-weight: 700;
  border-top: 2px solid rgba(124, 58, 237, 0.35);
}

.action-btn {
  font-family: var(--qc-font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(124, 58, 237, 0.2);
  color: var(--qc-purple);
  background: #ffffff;
  border-radius: 4px;
  margin-left: 0.25rem;
  cursor: pointer;
  transition: all 0.15s;
}

.action-btn:hover {
  background: var(--qc-purple);
  color: #ffffff;
  border-color: var(--qc-purple);
}

.action-btn-danger {
  color: var(--qc-rose);
  border-color: rgba(225, 29, 72, 0.2);
}

.action-btn-danger:hover {
  background: var(--qc-rose);
  border-color: var(--qc-rose);
  color: #ffffff;
}

/* Quick actions */
.quick-action-card {
  background: #ffffff;
  border: 1px solid var(--qc-border);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.quick-action-card:hover {
  transform: translateY(-2px);
  border-color: var(--qc-purple) !important;
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.1);
}

.quick-action-card p {
  color: #0f172a !important;
}

/* Modals */
div[id$="modal"] {
  background-color: rgba(15, 23, 42, 0.35) !important;
  backdrop-filter: blur(8px);
}

div[id$="modal"] .glass-panel {
  background: #ffffff !important;
  border: 1px solid var(--qc-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

div[id$="modal"] h3,
div[id$="modal"] label {
  color: #0f172a !important;
}

/* Ensure hidden views are truly hidden (overrides .login-wrap display:flex) */
[data-view].hidden {
  display: none !important;
}

/* Global hidden utility: guarantees elements hidden even if the Tailwind
   CDN script is slow or unavailable, so dynamic panels toggle reliably. */
.hidden {
  display: none !important;
}

.login-wrap {
  min-height: calc(100vh - 2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

@media (min-width: 1024px) {
  .app-shell.login-mode {
    grid-template-columns: 1fr;
  }
  .app-shell.login-mode #sidebar {
    display: none !important;
  }
  .login-wrap {
    grid-column: 1 / -1;
  }
}

.login-logo {
  width: 220px;
  max-width: 70vw;
  height: auto;
  object-fit: contain;
}

.dash-logo {
  width: 180px;
  max-width: 55vw;
  height: auto;
  object-fit: contain;
}

.login-panel {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  padding: 2.5rem !important;
  border-radius: 8px;
  box-shadow: 0 20px 40px rgba(124, 58, 237, 0.08);
}

.login-title {
  font-family: var(--qc-font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #0f172a;
  text-align: center;
}

.login-title .accent {
  color: var(--qc-purple);
}

.section-desc.mb-6 {
  text-align: center;
}

/* Logout button */
#logout-btn {
  font-family: var(--qc-font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--qc-rose);
  border: 1px solid rgba(225, 29, 72, 0.3);
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

#logout-btn:hover {
  background: var(--qc-rose);
  color: #ffffff;
  border-color: var(--qc-rose);
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
}

/* View transitions — transform ONLY. Never animate opacity on full views:
   if the fade sticks at its first frame (seen on some GPUs/tab states),
   the whole view computes opacity:0 and paints invisibly blank. */
[data-view] {
  animation: viewSlideIn 0.4s ease;
}

@keyframes viewSlideIn {
  from { transform: translateY(8px); }
  to { transform: translateY(0); }
}

/* Hard guarantee: a shown view is always fully opaque. */
[data-view]:not(.hidden) {
  opacity: 1 !important;
}

/* Inline Editing */
.inline-edit-input {
  width: 100%;
  font-family: var(--qc-font-mono);
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--qc-purple);
  border-radius: 4px;
  background: #ffffff;
  color: #0f172a;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
}

.inline-edit-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.inline-edit-input--sm {
  max-width: 80px;
}

.inline-edit-error {
  border-color: var(--qc-rose);
  background: rgba(225, 29, 72, 0.05);
}

.inline-edit-error:focus {
  box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.2);
}

.action-btn-save {
  background: rgba(22, 163, 74, 0.1);
  color: var(--qc-green);
  border-color: rgba(22, 163, 74, 0.3);
}

.action-btn-save:hover {
  background: var(--qc-green);
  color: #ffffff;
  border-color: var(--qc-green);
}

.action-btn-wa {
  color: var(--qc-green);
  border-color: rgba(22, 163, 74, 0.2);
}

.action-btn-wa:hover {
  background: var(--qc-green);
  border-color: var(--qc-green);
  color: #ffffff;
}

/* ============================================================
   APP SHELL — CSS Grid Layout (Desktop)
   ============================================================ */

.app-shell {
  display: block;
}

@media (min-width: 1024px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width, 250px) minmax(0, 1fr);
    min-height: 100vh;
  }
}

.main-area {
  min-width: 0;
  width: 100%;
}

.main-content {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
}

@media (min-width: 1024px) {
  .main-content {
    padding: 2rem 2rem;
  }
}

/* ============================================================
   SIDEBAR NAVIGATION — Light Theme (Desktop, lg+)
   ============================================================ */

/* ============================================================
   SIDEBAR NAVIGATION — Light Theme (Desktop, lg+)
   Mobile: display:none — zero layout impact
   ============================================================ */

#sidebar {
  /* Mobile: hidden, no layout impact */
  display: none;
}

@media (min-width: 1024px) {
#sidebar {
  display: flex;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease-in-out;
  width: var(--sidebar-width, 250px);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Brand area */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 20px 18px 16px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
  min-height: 68px;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  overflow: hidden;
  transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar-brand-name {
  font-family: var(--qc-font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #0f172a;
}

/* Toggle button */
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
  position: absolute;
  top: 20px;
  right: 12px;
  z-index: 10;
}

.sidebar-toggle:hover {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}

.sidebar-toggle-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.25s ease-in-out;
}

/* Scrollable navigation area */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 10px;
  scrollbar-width: thin;
  scrollbar-color: #e2e8f0 transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 4px;
}

/* Section labels */
.sidebar-section-label {
  font-family: var(--qc-font-mono);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #94a3b8;
  padding: 16px 10px 6px;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.2s ease;
}

.sidebar-section-label:first-child {
  padding-top: 4px;
}

/* Navigation links */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  font-family: var(--qc-font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  transition: all 0.15s ease;
  cursor: pointer;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  color: #1e293b;
  background: #f1f5f9;
}

.sidebar-link.active {
  color: var(--qc-purple);
  background: var(--qc-purple-dim);
  font-weight: 600;
}

.sidebar-link.active .sidebar-icon {
  color: var(--qc-purple);
}

/* Icons */
.sidebar-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  color: #64748b;
  transition: color 0.15s ease;
}

.sidebar-link:hover .sidebar-icon {
  color: #334155;
}

.sidebar-link.active .sidebar-icon {
  color: var(--qc-purple);
}

/* Labels (text) — hidden when collapsed */
.sidebar-label {
  transition: opacity 0.15s ease;
}

/* User / Sign Out section */
.sidebar-user {
  flex-shrink: 0;
  border-top: 1px solid #f1f5f9;
  padding: 14px 14px;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-avatar svg {
  width: 18px;
  height: 18px;
  color: #64748b;
}

.sidebar-user-details {
  overflow: hidden;
  transition: opacity 0.2s ease;
}

.sidebar-username {
  font-family: var(--qc-font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-signout {
  background: none;
  border: none;
  color: #94a3b8;
  font-family: var(--qc-font-mono);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease;
}

.sidebar-signout:hover {
  color: var(--qc-rose);
}
} /* end @media (min-width: 1024px) for sidebar */

/* ============================================================
   COLLAPSED SIDEBAR STATE (desktop only)
   ============================================================ */

#sidebar.collapsed {
  width: var(--sidebar-collapsed-width, 68px);
}

#sidebar.collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}

#sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 20px 8px 16px;
}

#sidebar.collapsed .sidebar-brand-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: 10px;
}

#sidebar.collapsed .sidebar-label {
  opacity: 0;
  width: 0;
  height: 0;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-nav {
  padding: 8px 6px;
}

#sidebar.collapsed .sidebar-user {
  padding: 14px 8px;
}

#sidebar.collapsed .sidebar-user-info {
  justify-content: center;
}

#sidebar.collapsed .sidebar-user-details {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-toggle {
  right: 50%;
  transform: translateX(50%);
}

/* Tooltip for collapsed icons */
#sidebar.collapsed .sidebar-link {
  position: relative;
}

#sidebar.collapsed .sidebar-link::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #f8fafc;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--qc-font-body);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

#sidebar.collapsed .sidebar-link:hover::after {
  opacity: 1;
}

/* ─── Tenancy agreements + tenant dashboard: small screens ─── */
@media (max-width: 640px) {
  #td-agreement-panel.glass-panel {
    padding: 12px;
  }
  #td-agreement-panel .data-grid {
    font-size: 12px;
  }
  #td-agreement-panel .data-grid th,
  #td-agreement-panel .data-grid td {
    padding: 8px;
    white-space: nowrap;
  }
  #td-agreement-panel .action-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
  #btn-td-agreement-upload,
  #btn-td-scan-doc {
    flex: 1 1 auto;
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 13px;
  }
  #td-agreement-modal .glass-panel {
    margin: 0;
    max-height: 94vh;
    padding: 12px;
  }
  #td-agreement-frame {
    height: 70vh;
  }
  section[data-view="tenant-dashboard"] .section-head .qc-btn {
    flex: 1 1 46%;
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 13px;
  }
  section[data-view="tenant-dashboard"] .metric-card {
    padding: 12px;
  }
}

/* ============================================================
   PRINT / PDF SHARING — browser print() renders one report page
   cleanly: app chrome hidden, only the report (marked .print-active)
   prints, wide tables land on A4 landscape with visible borders.
   ============================================================ */
@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    overflow: visible !important;
  }

  /* Hide everything, then reveal only the report being printed. */
  body * {
    visibility: hidden !important;
  }
  .print-active,
  .print-active * {
    visibility: visible !important;
  }
  .print-active {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    padding: 0 !important;
  }

  /* Chrome inside the report never prints. */
  .print-active button,
  .print-active .qc-btn,
  .print-active .action-btn,
  .print-active .sys-tag {
    display: none !important;
  }

  /* Full table width on paper — no clipped columns. */
  .print-active .overflow-x-auto {
    overflow: visible !important;
  }
  .print-active .cyber-table {
    min-width: 0 !important;
    font-size: 10pt !important;
  }
  .print-active .cyber-table thead {
    display: table-header-group;
  }
  .print-active .cyber-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .print-active .cyber-table th,
  .print-active .cyber-table td {
    border-color: #94a3b8 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Decorative background layers never print. */
  .quantum-bg,
  .quantum-grid {
    display: none !important;
  }
}


/* ── GEHPM Central Notification Bar + emergency indicator ─────────────────── */
.ne-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border: 1px solid #334155; border-radius: 10px; padding: 12px 16px;
  background: #0f172a; cursor: pointer; transition: border-color .3s, background .3s;
}
.ne-bar:hover { border-color: #475569; }
.ne-bar.emergency {
  border-color: #b91c1c;
  background: linear-gradient(90deg, rgba(127,29,29,.35), rgba(15,23,42,1) 60%);
}
.ne-dot {
  width: 16px; height: 16px; border-radius: 50%; background: #475569;
  display: inline-block; flex-shrink: 0;
}
.ne-bar.emergency .ne-dot {
  background: #ef4444;
  animation: ne-pulse 1.3s cubic-bezier(.4,0,.6,1) infinite;
}
@keyframes ne-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,.75); transform: scale(1); }
  70% { box-shadow: 0 0 0 14px rgba(239,68,68,0); transform: scale(1.15); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); transform: scale(1); }
}
.ne-title { font-weight: 800; letter-spacing: .04em; font-size: 13px; text-transform: uppercase; }
.ne-bar.emergency .ne-title { color: #fecaca; }
.ne-bar:not(.emergency) .ne-title { color: #86efac; }
.ne-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ne-chip {
  font-size: 10px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  border: 1px solid #334155; color: #cbd5e1; background: #1e293b; font-family: ui-monospace, monospace;
}
.ne-chip.critical { background: #7f1d1d; border-color: #b91c1c; color: #fecaca; }
.ne-chip.overdue { background: #78350f; border-color: #b45309; color: #fde68a; }
.ne-chip.due_soon { background: #713f12; border-color: #a16207; color: #fde68a; }
.ne-chip.pending { background: #1e3a8a; border-color: #1d4ed8; color: #bfdbfe; }
.ne-chip.review { background: #4c1d95; border-color: #7c3aed; color: #ddd6fe; }
.ne-row-priority { font-weight: 800; text-transform: uppercase; font-size: 10px; }
.ne-row-priority.critical { color: #f87171; }
.ne-row-priority.overdue { color: #fbbf24; }
.ne-row-priority.due_soon { color: #fcd34d; }
.ne-row-priority.pending { color: #93c5fd; }
.ne-row-priority.review { color: #c4b5fd; }

/* ── Minimal notification bell + count badge ──────────────────────────────── */
.ne-bell {
  position: relative; width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: #94a3b8; cursor: pointer; transition: background .2s, color .2s;
}
.ne-bell:hover { background: #1e293b; color: #e2e8f0; }
.ne-bell svg { width: 22px; height: 22px; }
.ne-bell.emergency { color: #f87171; }
.ne-bell.emergency:hover { color: #fca5a5; }
.ne-bell.unavailable { opacity: .35; }
.ne-badge {
  position: absolute; top: 3px; right: 3px;
  min-width: 18px; padding: 1px 5px; border-radius: 999px;
  background: #334155; color: #fff; font-size: 10px; font-weight: 800;
  line-height: 1.4; text-align: center; font-family: ui-monospace, monospace;
}
.ne-badge.urgent { background: #ef4444; animation: ne-pulse 1.3s cubic-bezier(.4,0,.6,1) infinite; }