/* ==========================================================================
 * Application Shell: Sticky Topbar, Collapsible Sidebar, Banners, Cards, RAG
 * ========================================================================== */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: var(--bg);
  color: #f8fafc;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: #fff;
  white-space: nowrap;
}

.topbar-brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.08);
}

.topbar-tenant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 13px;
  color: #cbd5e1;
  min-width: 0;
}

.topbar-tenant select {
  background: var(--bg-elev);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #f1f5f9;
  max-width: 240px;
}

.user-chip-role {
  font-size: 11px;
  color: #94a3b8;
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

/* Password Expiry Warning Banner */
.pw-banner {
  background: var(--warning-soft);
  border-bottom: 1px solid #fbbf24;
  color: #92400e;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
}

:root[data-theme="dark"] .pw-banner {
  color: #fde68a;
  border-bottom-color: #b45309;
}

/* Workspace Body: Sidebar + Content */
.shell-body {
  flex: 1;
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  color: #cbd5e1;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 10px;
  transition: width 0.2s ease, transform 0.2s ease;
}

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

.nav-section-label {
  padding: 10px 10px 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-decoration: none;
}

.nav-link.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
  font-size: 11.5px;
  color: #64748b;
  padding-left: 10px;
}

.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-w);
}

.app-shell.sidebar-collapsed .nav-link span,
.app-shell.sidebar-collapsed .nav-section-label,
.app-shell.sidebar-collapsed .sidebar-footer {
  display: none;
}

.app-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 10px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 36px;
}

.app-shell.auth-mode .topbar,
.app-shell.auth-mode .sidebar {
  display: none;
}

.app-shell.auth-mode .main-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #1e3a8a 0%, #0f1724 55%, #070b14 100%);
  padding: 24px;
}

/* Standard Cards & Toolbars */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-strong);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink-strong);
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* RAG Status Dots & Badges */
.rag-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.rag-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.rag-green,
.rag-ok {
  background: var(--rag-green-bg);
  color: var(--rag-green);
}

.rag-green .rag-dot,
.rag-dot.rag-green {
  background: var(--rag-green);
}

.rag-amber,
.rag-warning,
.rag-due {
  background: var(--rag-amber-bg);
  color: #b45309;
}

.rag-amber .rag-dot,
.rag-dot.rag-amber {
  background: var(--rag-amber);
}

.rag-red,
.rag-critical,
.rag-overdue {
  background: var(--rag-red-bg);
  color: var(--rag-red);
}

.rag-red .rag-dot,
.rag-dot.rag-red {
  background: var(--rag-red);
  animation: rag-pulse 1.5s infinite;
}

.rag-grey,
.rag-offline,
.rag-nodata {
  background: var(--rag-grey-bg);
  color: var(--rag-grey);
}

.rag-grey .rag-dot,
.rag-dot.rag-grey {
  background: var(--rag-grey);
}

@keyframes rag-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(220, 38, 38, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rag-red .rag-dot,
  .rag-dot.rag-red {
    animation: none;
  }
}

/* Mobile Responsive Drawer */
.sidebar-scrim {
  display: none;
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    z-index: 45;
    transform: translateX(-100%);
  }

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

  .app-shell.sidebar-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    z-index: 44;
    background: rgba(2, 6, 23, 0.55);
  }

  .main-content {
    padding: 14px 14px 28px;
  }

  .topbar-tenant {
    display: none;
  }

  .user-chip-role {
    display: none;
  }
}
