/* ============================================
   AL-HIRA PUBLIC SCHOOL — Layout System
   Sidebar + Topbar + Content Grid
   ============================================ */

@layer layout {

  /* === Main Application Layout === */
  .app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
      "sidebar topbar"
      "sidebar content";
    min-height: 100vh;
    transition: grid-template-columns var(--transition-normal);
  }

  .app-layout.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed) 1fr;
  }

  /* === Sidebar === */
  .sidebar {
    grid-area: sidebar;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--color-dark-emerald) 0%, var(--color-darkest) 100%);
    color: var(--color-text-inverse);
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    transition: width var(--transition-normal), transform var(--transition-normal);
    overflow: hidden;
  }

  .sidebar-header {
    padding: var(--space-5) var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: 72px;
    flex-shrink: 0;
  }

  .sidebar-logo {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-lg);
    object-fit: contain;
    flex-shrink: 0;
    background: rgba(255,255,255,0.1);
    padding: 3px;
  }

  .sidebar-brand {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
  }

  .sidebar-brand-name {
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-wide);
    color: var(--color-text-inverse);
    white-space: nowrap;
    line-height: 1.2;
  }

  .sidebar-brand-tagline {
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
    white-space: nowrap;
    font-weight: var(--weight-medium);
  }

  /* --- Navigation --- */
  .sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3) var(--space-3);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
  }

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

  .sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-full);
  }

  .nav-section {
    margin-bottom: var(--space-4);
  }

  .nav-section-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wider);
    color: rgba(255, 255, 255, 0.35);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    color: rgba(255, 255, 255, 0.65);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    margin-bottom: 2px;
    text-decoration: none;
    user-select: none;
  }

  .nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
  }

  .nav-item.active {
    background: linear-gradient(135deg, var(--color-gold), var(--color-gold-light));
    color: var(--color-darkest);
    font-weight: var(--weight-semibold);
    box-shadow: 0 2px 8px rgba(200, 155, 60, 0.3);
  }

  .nav-item.active .nav-icon {
    color: var(--color-darkest);
  }

  .nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    opacity: 0.8;
  }

  .nav-item.active .nav-icon {
    opacity: 1;
  }

  .nav-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .nav-badge {
    margin-left: auto;
    background: var(--color-danger);
    color: #fff;
    font-size: 10px;
    font-weight: var(--weight-bold);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
    line-height: 16px;
  }

  .nav-item.active .nav-badge {
    background: var(--color-darkest);
    color: var(--color-gold);
  }

  /* --- Sidebar Footer --- */
  .sidebar-footer {
    padding: var(--space-3) var(--space-3);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
  }

  .sidebar-profile {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background var(--transition-fast);
  }

  .sidebar-profile:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .sidebar-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-gold), var(--color-gold-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    color: var(--color-darkest);
    flex-shrink: 0;
  }

  .sidebar-profile-info {
    overflow: hidden;
  }

  .sidebar-profile-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar-profile-role {
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.4);
    white-space: nowrap;
  }

  .sidebar-logout {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    color: rgba(255, 255, 255, 0.5);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: var(--space-1);
  }

  .sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #FCA5A5;
  }

  .sidebar-logout svg {
    width: 16px;
    height: 16px;
  }

  /* === Top Bar === */
  .topbar {
    grid-area: topbar;
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: rgba(248, 246, 241, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-8);
    z-index: var(--z-sticky);
  }

  .topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
  }

  .topbar-menu-btn {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
  }

  .topbar-menu-btn:hover {
    background: var(--color-surface-active);
  }

  .topbar-menu-btn svg {
    width: 20px;
    height: 20px;
  }

  .topbar-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .topbar-title h1 {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--color-text);
    letter-spacing: var(--tracking-tight);
  }

  .topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }

  .topbar-breadcrumb span {
    color: var(--color-text-light);
  }

  .topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .topbar-search-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 220px;
  }

  .topbar-search-btn:hover {
    border-color: var(--color-border-dark);
    box-shadow: var(--shadow-sm);
  }

  .topbar-search-btn svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-light);
  }

  .topbar-search-shortcut {
    margin-left: auto;
    font-size: 10px;
    font-weight: var(--weight-medium);
    color: var(--color-text-light);
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
  }

  .topbar-icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
  }

  .topbar-icon-btn:hover {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
  }

  .topbar-icon-btn svg {
    width: 20px;
    height: 20px;
  }

  .topbar-notification-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--color-danger);
    border-radius: var(--radius-full);
    border: 2px solid var(--color-bg);
    animation: pulse 2s ease-in-out infinite;
  }

  .topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    color: var(--color-text-inverse);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    margin-left: var(--space-2);
  }

  .topbar-avatar:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-emerald);
  }

  /* === Main Content === */
  .main-content {
    grid-area: content;
    padding: var(--space-8);
    min-height: calc(100vh - var(--topbar-height));
    max-width: 100%;
    overflow-x: hidden;
  }

  .content-wrapper {
    max-width: var(--content-max-width);
    margin: 0 auto;
    width: 100%;
  }

  /* === Page Header === */
  .page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-8);
    flex-wrap: wrap;
    gap: var(--space-4);
  }

  .page-header-left {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .page-header-left h2 {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
  }

  .page-header-left p {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  .page-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  /* === Grid System === */
  .grid {
    display: grid;
    gap: var(--space-6);
  }

  .grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-cols-6 { grid-template-columns: repeat(6, 1fr); }

  .grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  /* === Overlay (Mobile Sidebar) === */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: calc(var(--z-sidebar) - 1);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity var(--transition-normal);
  }

  .sidebar-overlay.active {
    opacity: 1;
  }

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

  .login-screen::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 80%;
    height: 120%;
    background: radial-gradient(ellipse, rgba(11, 77, 68, 0.06) 0%, transparent 70%);
    pointer-events: none;
  }

  .login-screen::after {
    content: '';
    position: absolute;
    bottom: -40%;
    left: -20%;
    width: 60%;
    height: 100%;
    background: radial-gradient(ellipse, rgba(200, 155, 60, 0.05) 0%, transparent 70%);
    pointer-events: none;
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    padding: var(--space-10);
    position: relative;
    z-index: 1;
    border: 1px solid var(--color-border-light);
  }

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

  .login-logo img {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-xl);
    object-fit: contain;
  }

  .login-logo h2 {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--color-primary);
    letter-spacing: var(--tracking-wide);
    text-align: center;
  }

  .login-logo p {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    text-align: center;
  }

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

  .login-btn {
    width: 100%;
    padding: var(--space-3) var(--space-6);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-emerald);
    letter-spacing: var(--tracking-wide);
    position: relative;
    overflow: hidden;
  }

  .login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(11, 77, 68, 0.25);
  }

  .login-btn:active {
    transform: translateY(0);
  }

  .login-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
  }

  .login-footer {
    text-align: center;
    margin-top: var(--space-6);
    font-size: var(--text-xs);
    color: var(--color-text-light);
  }

  .login-footer span {
    color: var(--color-gold);
    font-weight: var(--weight-semibold);
  }

  /* === Mobile Bottom Navigation === */
  .mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border-light);
    z-index: var(--z-sticky);
    padding: 0 var(--space-2);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  }

  .mobile-nav-items {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 100%;
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    min-width: 56px;
  }

  .mobile-nav-item:hover,
  .mobile-nav-item.active {
    color: var(--color-primary);
  }

  .mobile-nav-item.active {
    color: var(--color-gold);
  }

  .mobile-nav-item svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.8;
  }
}
