:root {
  --bg-0: #0f172a;
  --bg-1: #102a43;
  --bg-2: #0b1320;
  --accent: #0ea5a4;
  --accent-2: #f59e0b;
  --accent-3: #ef4444;
  --card: #f8fafc;
  --ink: #0f172a;
  --muted: #6b7280;
  --line: #e2e8f0;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Manrope", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 20%, rgba(14, 165, 164, 0.18), transparent 50%),
              radial-gradient(circle at 80% 0%, rgba(245, 158, 11, 0.18), transparent 55%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

body.is-authenticated #loginView {
  display: none !important;
}

body.is-authenticated #mainView {
  display: block;
}

#mainView[hidden],
#loginView[hidden] {
  display: none !important;
}

h1, h2, h3, h4, h5 {
  font-family: "Space Grotesk", "Segoe UI", Arial, sans-serif;
}

.app-bg {
  background-attachment: fixed;
}

.login-card {
  background: var(--card);
  border-radius: 20px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  animation: floatIn 0.6s ease-out;
}

.login-card .form-label {
  display: block;
  margin-bottom: 6px;
}

.login-card .form-control {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
}

.login-card .btn {
  min-height: 44px;
  font-weight: 600;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 20px;
  color: white;
  background: linear-gradient(135deg, var(--accent), #22d3ee);
}

.brand-title {
  font-size: 28px;
  margin: 0;
}

.brand-subtitle {
  margin: 0;
  color: var(--muted);
}

.login-footnote {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.topbar {
  height: 64px;
  padding: 0 24px;
  background: rgba(15, 23, 42, 0.96);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(14, 165, 164, 0.2);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-user .btn {
  min-height: 40px;
  padding: 6px 16px;
  font-weight: 600;
}

#toggleNavBtn {
  min-height: 40px;
  padding: 6px 14px;
  font-weight: 600;
}

.user-email {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.user-role {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(14, 165, 164, 0.2);
  color: #99f6e4;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 64px);
}

.sidebar {
  background: rgba(15, 23, 42, 0.92);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(148, 163, 184, 0.2);
  min-width: 240px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  padding: 12px 16px;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.2;
  font-size: 14px;
  font-weight: 600;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
  background: rgba(14, 165, 164, 0.15);
  color: white;
}

.sidebar-footer {
  margin-top: auto;
}

.pill {
  display: inline-flex;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.2);
  color: #fef3c7;
  font-size: 12px;
}

.content {
  padding: 32px;
  background: #f8fafc;
  min-height: calc(100vh - 64px);
}

.section {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.section.active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.section-header h2 {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
}

.panel {
  background: white;
  border-radius: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.05);
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.condo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.pagination-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.table thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.table td {
  vertical-align: middle;
}

.modal {
  display: none;
}

.modal.show {
  display: block;
}

.modal-backdrop {
  display: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

.btn:focus-visible,
.form-control:focus-visible,
.nav-link:focus-visible,
button:focus-visible {
  outline: 2px solid rgba(14, 165, 164, 0.6);
  outline-offset: 2px;
}

.badge-role {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(14, 165, 164, 0.2);
  color: #0f766e;
  font-size: 12px;
  font-weight: 600;
}

.loading {
  display: grid;
  place-items: center;
  padding: 30px;
  color: var(--muted);
}

.documents-help {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.documents-tip {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}

.documents-tip.muted {
  color: var(--muted);
}

.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.document-card {
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 16px;
  background: white;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.document-card h4 {
  margin: 0;
  font-size: 18px;
}

.document-meta {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.document-description {
  color: var(--muted);
  font-size: 13px;
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.document-actions .btn {
  min-height: 40px;
}

.documents-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0 8px;
}

.documents-error {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
}

.documents-debug-body {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
}

.selfie-instructions {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.selfie-stage {
  background: #0f172a;
  border-radius: 16px;
  overflow: hidden;
  min-height: 240px;
  display: grid;
  place-items: center;
}

.selfie-video,
.selfie-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selfie-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.selfie-fallback {
  margin-top: 16px;
}

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

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

@media (max-width: 991px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 64px 0 0 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
  }

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

  .content {
    padding: 24px 16px 40px;
  }
}

@media (max-width: 575px) {
  .selfie-actions .btn {
    flex: 1 1 100%;
  }
}

@media (min-width: 992px) {
  #toggleNavBtn {
    display: none;
  }
}
