/* ============================================================
   Forbys — Layout
   App shell (sidebar + main), login, KPIs, theme toggle.
   ============================================================ */

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  transition: transform 250ms ease;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  flex-shrink: 0;
}

.brand:hover { text-decoration: none; }

.brand-mark {
  width: 30px;
  height: 30px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 16px;
  height: 16px;
  color: white;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

/* Nav */
.nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: var(--space-3) var(--space-3) var(--space-2);
  margin-top: var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  user-select: none;
}

.nav-item svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

[data-theme="dark"] .nav-item.active {
  color: #93C5FD;
}

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 100px;
  min-width: 16px;
  text-align: center;
}

.nav-spacer {
  flex: 1;
}

/* User card */
.user-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-subtle);
  text-transform: capitalize;
}

.user-actions {
  display: flex;
  gap: 2px;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.page-titles {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

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

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.page-content {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

/* ============================================================
   KPIs
   ============================================================ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: var(--space-6);
}

.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -1px;
  line-height: 1.1;
}

.kpi-delta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 3px;
}

.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* ============================================================
   LOGIN SHELL
   ============================================================ */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
}

.login-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, color-mix(in srgb, var(--primary) 15%, transparent), transparent),
    radial-gradient(ellipse 50% 40% at 80% 80%, color-mix(in srgb, var(--info) 8%, transparent), transparent);
  pointer-events: none;
}

.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
  text-align: center;
}

.login-brand-mark {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand-mark svg {
  width: 22px;
  height: 22px;
  color: white;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  z-index: 1000;
  transition: transform var(--transition), box-shadow var(--transition),
              color var(--transition), background var(--transition);
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
  color: var(--primary);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    transform: translateX(-100%);
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }

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

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .kpi-row {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .page-header {
    padding: 16px 20px;
    flex-direction: column;
    gap: var(--space-3);
  }

  .page-content {
    padding: 16px 20px;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .search {
    min-width: unset;
  }
}
