/* ==========================================================================
   layout.css - auth screen, app shell, sidebar, topbar, responsive behaviour
   ========================================================================== */

/* ============================ AUTH SCREEN ============================ */
.auth-screen { min-height: 100vh; background: var(--bg); }
.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
}
.auth-hero {
  position: relative;
  padding: var(--sp-12) var(--sp-10);
  display: flex; flex-direction: column; justify-content: center;
  color: #fff;
  background:
    radial-gradient(1200px 600px at 10% 0%, rgba(99,102,241,.55), transparent 60%),
    radial-gradient(900px 500px at 90% 100%, rgba(16,185,129,.35), transparent 60%),
    linear-gradient(155deg, #0f172a 0%, #1e1b4b 55%, #312e81 100%);
  overflow: hidden;
}
.auth-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(600px 400px at 30% 40%, #000, transparent 75%);
}
.auth-hero-logo { display: flex; align-items: center; gap: var(--sp-2); font-weight: 700; font-size: 1.02rem; position: relative; z-index: 1; }
.auth-hero h1 { font-size: clamp(1.6rem, 3.2vw, 2.5rem); max-width: 22ch; margin: var(--sp-8) 0 var(--sp-4); position: relative; z-index: 1; }
.auth-hero-sub { color: rgba(255,255,255,.74); max-width: 52ch; font-size: .96rem; position: relative; z-index: 1; }
.auth-hero-list { list-style: none; padding: 0; margin: var(--sp-8) 0 0; display: grid; gap: var(--sp-3); position: relative; z-index: 1; }
.auth-hero-list li { display: flex; align-items: center; gap: var(--sp-3); font-size: .92rem; color: rgba(255,255,255,.9); }
.auth-hero-list span {
  display: grid; place-items: center; width: 22px; height: 22px; flex: 0 0 auto;
  border-radius: var(--r-full); background: rgba(16,185,129,.2); color: #6ee7b7; font-size: .78rem;
}
.auth-hero-foot { margin-top: auto; padding-top: var(--sp-10); font-size: .78rem; color: rgba(255,255,255,.5); position: relative; z-index: 1; }

.auth-panel { display: grid; place-items: center; padding: var(--sp-10) var(--sp-6); background: var(--bg-elev); }
.auth-panel-inner { width: 100%; max-width: 430px; }
.auth-panel h2 { font-size: 1.5rem; margin-bottom: var(--sp-2); }
.auth-note { color: var(--text-muted); font-size: .88rem; margin-bottom: var(--sp-6); }
.auth-status:empty { display: none; }
.auth-status { margin-bottom: var(--sp-4); }
.auth-divider {
  display: flex; align-items: center; gap: var(--sp-3);
  margin: var(--sp-6) 0 var(--sp-4); color: var(--text-faint); font-size: .76rem; text-transform: uppercase; letter-spacing: .07em;
}
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.role-picker { display: grid; gap: var(--sp-2); }
.role-opt { display: block; cursor: pointer; }
.role-opt input { position: absolute; opacity: 0; pointer-events: none; }
.role-card {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-elev-2); transition: all .16s var(--ease);
}
.role-card small { color: var(--text-muted); font-size: .78rem; }
.role-opt:hover .role-card { border-color: var(--brand-300); transform: translateY(-1px); }
.role-opt input:checked + .role-card {
  border-color: var(--brand-500); background: var(--brand-50);
  box-shadow: 0 0 0 3px rgba(99,102,241,.14);
}
.role-opt input:focus-visible + .role-card { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.auth-legal { margin-top: var(--sp-6); font-size: .74rem; color: var(--text-faint); line-height: 1.5; }

/* ============================ APP SHELL ============================ */
.app-shell { min-height: 100vh; display: block; }
.main {
  min-height: 100vh;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  transition: margin-left .22s var(--ease);
}

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 800;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  border-right: 1px solid rgba(255,255,255,.06);
  transition: transform .24s var(--ease);
}
.sidebar-head {
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--topbar-h); flex: 0 0 auto;
  padding: 0 var(--sp-4); border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto;
  border-radius: var(--r-md); font-size: 17px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  box-shadow: 0 4px 12px rgba(79,70,229,.4);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { color: #fff; font-size: .93rem; letter-spacing: .01em; white-space: nowrap; }
.brand-text small { color: var(--sidebar-muted); font-size: .68rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-close { display: none; color: var(--sidebar-text); }

.sidebar-user {
  flex: 0 0 auto; padding: var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: var(--sp-3);
}
.sidebar-user .avatar { width: 38px; height: 38px; font-size: .92rem; }
.sidebar-user-meta { min-width: 0; }
.sidebar-user-meta strong { display: block; color: #fff; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-meta small { display: block; color: var(--sidebar-muted); font-size: .72rem; }
.role-pill {
  margin-top: 3px; display: inline-block; padding: 1px 8px; border-radius: var(--r-full);
  font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  background: rgba(99,102,241,.22); color: #c7d2fe;
}
.role-pill.admin    { background: rgba(239,68,68,.2);  color: #fca5a5; }
.role-pill.co-admin { background: rgba(245,158,11,.2); color: #fcd34d; }
.role-pill.student  { background: rgba(16,185,129,.2);color: #6ee7b7; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-3) var(--sp-3) var(--sp-6); }
.nav-group + .nav-group { margin-top: var(--sp-4); }
.nav-group-label {
  padding: 0 var(--sp-3) var(--sp-2);
  font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--sidebar-muted);
}
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); margin-bottom: 2px;
  border-radius: var(--r-md); color: var(--sidebar-text);
  font-size: .87rem; font-weight: 500;
  transition: background .14s var(--ease), color .14s var(--ease);
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--brand-400);
}
.nav-ico { width: 20px; text-align: center; font-size: 15px; flex: 0 0 auto; opacity: .9; }
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; height: 18px;
  display: grid; place-items: center; border-radius: var(--r-full);
  background: var(--brand-600); color: #fff; font-size: .66rem; font-weight: 700;
}
.nav-badge.warn { background: var(--warn-600); }
.nav-badge.err  { background: var(--err-600); }

.sidebar-foot { flex: 0 0 auto; padding: var(--sp-3) var(--sp-4) var(--sp-4); border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-foot .btn { color: var(--sidebar-text); }
.sidebar-foot .btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-version { margin-top: var(--sp-3); font-size: .66rem; color: var(--sidebar-muted); text-align: center; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 700;
  height: var(--topbar-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-menu { display: none; }
.breadcrumbs { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; font-size: .84rem; flex: 0 1 auto; }
.breadcrumbs ol { display: flex; align-items: center; gap: var(--sp-2); list-style: none; padding: 0; margin: 0; flex-wrap: nowrap; min-width: 0; }
.breadcrumbs li { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.breadcrumbs li + li::before { content: "/"; color: var(--text-faint); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--brand-600); text-decoration: none; }
.breadcrumbs .current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

.global-search { position: relative; }
.global-search input {
  width: 300px; max-width: 34vw; height: 36px;
  padding: 0 var(--sp-3) 0 34px;
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--bg-sunken) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.4' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='M20 20l-3.5-3.5'/></svg>") no-repeat 12px center;
  font-size: .85rem; transition: all .16s var(--ease);
}
.global-search input:focus { outline: none; border-color: var(--brand-400); background-color: var(--bg-elev); box-shadow: 0 0 0 3px rgba(99,102,241,.14); }
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: 400px; max-width: 92vw;
  max-height: 62vh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: var(--sp-2); z-index: 50;
}
.search-group-label { padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.search-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); cursor: pointer; }
.search-item:hover, .search-item.sel { background: var(--bg-sunken); text-decoration: none; }
.search-item .si-ico { width: 26px; height: 26px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--brand-50); font-size: 13px; flex: 0 0 auto; }
.search-item .si-body { min-width: 0; }
.search-item .si-body strong { display: block; font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .si-body small { display: block; font-size: .74rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  position: relative; width: 36px; height: 36px; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: var(--r-md);
  color: var(--text-muted); font-size: 16px; transition: all .15s var(--ease);
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.icon-btn.has-dot .dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--err-500); border: 2px solid var(--bg-elev);
}
.topbar-menu span { display: block; width: 17px; height: 2px; background: currentColor; border-radius: 2px; margin: 3px 0; }
.topbar-menu { flex-direction: column; justify-content: center; }

.user-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  height: 38px; padding: 0 var(--sp-3) 0 var(--sp-2);
  border-radius: var(--r-full); border: 1px solid var(--border);
  background: var(--bg-elev); transition: all .15s var(--ease);
}
.user-chip:hover { border-color: var(--border-strong); background: var(--bg-sunken); }
.user-chip-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-chip-text strong { font-size: .8rem; font-weight: 600; }
.user-chip-text small { font-size: .68rem; color: var(--text-muted); text-transform: capitalize; }
.user-chip .caret { font-size: .6rem; color: var(--text-faint); }
.user-menu { position: relative; }

.avatar {
  width: 30px; height: 30px; flex: 0 0 auto; border-radius: var(--r-full);
  display: grid; place-items: center; font-size: .78rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
}
.avatar.lg { width: 60px; height: 60px; font-size: 1.3rem; }
.avatar.xl { width: 84px; height: 84px; font-size: 1.9rem; }
.avatar.cat-0 { background: linear-gradient(135deg,#6366f1,#4338ca); }
.avatar.cat-1 { background: linear-gradient(135deg,#0ea5e9,#0369a1); }
.avatar.cat-2 { background: linear-gradient(135deg,#10b981,#047857); }
.avatar.cat-3 { background: linear-gradient(135deg,#f59e0b,#b45309); }
.avatar.cat-4 { background: linear-gradient(135deg,#ec4899,#be185d); }
.avatar.cat-5 { background: linear-gradient(135deg,#8b5cf6,#6d28d9); }

/* ---------- view ---------- */
.view { flex: 1 1 auto; padding: var(--sp-6) var(--sp-6) var(--sp-10); min-width: 0; }
.view-loading { display: grid; place-items: center; gap: var(--sp-3); padding: var(--sp-12) 0; color: var(--text-muted); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { font-size: 1.42rem; display: flex; align-items: center; gap: var(--sp-3); }
.page-head .page-sub { color: var(--text-muted); font-size: .88rem; margin-top: var(--sp-1); max-width: 80ch; }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

.app-footer {
  flex: 0 0 auto; padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border); color: var(--text-faint); font-size: .78rem;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap;
}
.footer-links a { color: var(--text-faint); }
.footer-links a:hover { color: var(--brand-600); }

/* ---------- scrim + bottom nav (mobile) ---------- */
.scrim { position: fixed; inset: 0; z-index: 790; background: rgba(2,6,23,.55); backdrop-filter: blur(2px); animation: fadeIn .2s var(--ease); }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 780;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-elev); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 14px rgba(15,23,42,.07);
}
.bottom-nav-inner { display: flex; height: var(--bottomnav-h); }
.bn-item {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-faint); font-size: .64rem; font-weight: 600; padding: 4px 2px;
}
.bn-item .bn-ico { font-size: 17px; line-height: 1; }
.bn-item.active { color: var(--brand-600); }
.bn-item:hover { text-decoration: none; color: var(--brand-600); }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 1180px) {
  .global-search input { width: 210px; }
  .search-results { width: 340px; }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-xl); }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: grid; margin-left: auto; }
  .main { margin-left: 0; }
  .topbar-menu { display: flex; }
  .user-chip-text { display: none; }
  .user-chip { padding: 0 var(--sp-2); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-panel { padding: var(--sp-8) var(--sp-5); }
}

@media (max-width: 860px) {
  .global-search { display: none; }
  .view { padding: var(--sp-4) var(--sp-4) calc(var(--bottomnav-h) + var(--sp-8) + env(safe-area-inset-bottom)); }
  .bottom-nav { display: block; }
  .app-footer { padding-bottom: calc(var(--bottomnav-h) + var(--sp-4)); }
  .page-head h1 { font-size: 1.22rem; }
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .breadcrumbs { font-size: .78rem; }
}

@media (max-width: 520px) {
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .breadcrumbs ol li:not(:last-child) { display: none; }
  .breadcrumbs ol li:not(:last-child) + li::before { display: none; }
}

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .bottom-nav, .app-footer, .page-actions, .toast-host, .scrim { display: none !important; }
  .main { margin-left: 0; }
  .view { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
}
