/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: #171a2b;
  color: #cbd0e0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
/* Taken out of grid flow unconditionally (not just under the mobile breakpoint below) —
   otherwise it's an unpositioned grid child at desktop widths and CSS Grid auto-placement
   pushes .main-col into row 2 / column 1, squeezing it under the sidebar. */
.sidebar-scrim {
  display: none;
  position: fixed; inset: 0; background: rgba(10,12,20,0.4); z-index: 25;
}
.sidebar-scrim.open { display: block; }
.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.sidebar-brand .brand-logo { height: 24px; width: auto; display: block; }
.sidebar-brand .logo-sub {
  font-size: 10px; font-weight: 600; color: #cbd0e0;
  text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap;
  padding: 3px 9px; border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 999px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--space-4) var(--space-3); }
.sidebar-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: #6b7290; padding: var(--space-3) var(--space-3) var(--space-1);
}
.nav-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: #b7bcd4;
  font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-link .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-link.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11.5px;
  color: #6b7290;
}

/* ---------- Main column ---------- */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar-breadcrumb { font-size: 12.5px; color: var(--color-text-muted); }
.topbar-breadcrumb b { color: var(--color-text); font-weight: 600; }
.mobile-nav-toggle {
  display: none;
  background: none; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  width: 34px; height: 34px; align-items: center; justify-content: center; cursor: pointer;
}

.topbar-right { display: flex; align-items: center; gap: var(--space-4); }
.portal-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent-text); background: var(--accent-soft);
  padding: 4px 10px; border-radius: 999px;
}
.user-menu { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; position: relative; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center;
}
.user-menu-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.user-menu-role { font-size: 11px; color: var(--color-text-muted); }
.user-dropdown {
  position: absolute; top: 44px; right: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  width: 180px; padding: var(--space-2); display: none; flex-direction: column;
}
.user-dropdown.open { display: flex; }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; color: var(--color-text);
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--color-bg); }

.content { padding: var(--space-6); flex: 1; }
.content-narrow { max-width: 1080px; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap;
}
.page-header-text { display: flex; flex-direction: column; gap: 4px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-5);
}

@media (max-width: 1080px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- Responsive sidebar ---------- */
@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-nav-toggle { display: inline-flex; }
  .content { padding: var(--space-4); }
}

/* ---------- Auth (login) layout ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #171a2b 0%, #23273f 45%, var(--accent) 130%);
  padding: var(--space-5);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6) var(--space-5);
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin-bottom: var(--space-5); }
.auth-logo .logo-mark { width: 44px; height: 44px; border-radius: 12px; }
.auth-footer-link { text-align: center; margin-top: var(--space-5); font-size: 13px; color: var(--color-text-muted); }

/* ---------- Portal chooser (landing) ---------- */
.chooser-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: #171a2b; padding: var(--space-5);
}
.chooser-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-5);
  max-width: 760px; width: 100%;
}
@media (max-width: 640px) { .chooser-grid { grid-template-columns: 1fr; } }
