/* =====================================================================
   KOSEN Student iFolio — App shell (Sidebar / Topbar / Content)
   Desktop  >= 1025px : fixed sidebar 260px (collapsible to icon rail)
   Tablet   768-1024  : icon rail, expands as overlay
   Mobile   <= 767px  : off-canvas drawer + hamburger in topbar
   ===================================================================== */

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: var(--sidebar-width); height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--white); border-right: 1px solid var(--border);
  transition: width 200ms ease, transform 220ms ease, box-shadow 200ms ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px; height: var(--topbar-height); padding: 0 18px;
  border-bottom: 1px solid var(--border); flex-shrink: 0; color: var(--text);
}
.sidebar-brand:hover { color: var(--text); }
.brand-logo { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; }
.brand-text { min-width: 0; line-height: 1.25; }
.brand-text > span { display: block; }
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; letter-spacing: -.01em; }
.brand-name span { color: var(--primary); display: inline; }
.brand-tagline { font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 14px 20px; }
.nav-section + .nav-section { margin-top: 16px; }
.nav-section-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-tertiary); padding: 0 12px; margin-bottom: 6px; white-space: nowrap;
}
.nav-link {
  display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px; margin-bottom: 2px;
  border-radius: var(--radius); color: #4B5563; font-weight: 400; font-size: 14px; white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.nav-link .icon { width: 20px; height: 20px; color: #6B7280; transition: color var(--transition); }
.nav-link:hover { background: var(--primary-extra-light); color: var(--primary); }
.nav-link:hover .icon { color: var(--primary); }
.nav-link.is-active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.nav-link.is-active .icon { color: var(--primary); }
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-badge { font-size: 11px; font-weight: 600; background: var(--primary); color: var(--white); border-radius: var(--radius-full); padding: 0 7px; line-height: 18px; }

.sidebar-footer { padding: 12px 14px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-md); background: var(--background); }
.sidebar-user-info { min-width: 0; flex: 1; line-height: 1.3; }
.sidebar-user-name { font-weight: 600; font-size: 13.5px; }
.sidebar-user-email { font-size: 12px; color: var(--text-secondary); }
.sidebar-signout { width: 34px; height: 34px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; }
.sidebar-signout:hover { background: var(--danger-light); color: var(--danger); }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 45; background: rgba(15, 23, 42, .38);
  opacity: 0; visibility: hidden; transition: opacity 200ms ease, visibility 200ms ease;
}

/* ---------- Main column ---------- */
.main { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left 200ms ease; }

.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-height);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: rgba(255, 255, 255, .96); backdrop-filter: saturate(180%) blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar-toggle {
  width: 40px; height: 40px; border-radius: var(--radius); border: 0; background: transparent; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center; margin-left: -8px;
}
.topbar-toggle:hover { background: var(--primary-extra-light); color: var(--primary); }
.topbar-title { font-weight: 600; font-size: 16px; min-width: 0; }
.topbar-breadcrumb { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; min-width: 0; }
.topbar-breadcrumb .icon { width: 14px; height: 14px; }
.topbar-breadcrumb .current { color: var(--text); font-weight: 600; font-size: 15px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar-icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: var(--radius); border: 0; background: transparent; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
.topbar-icon-btn:hover { background: var(--primary-extra-light); color: var(--primary); }
.topbar-icon-btn .dot { position: absolute; top: 9px; right: 10px; box-shadow: 0 0 0 2px var(--white); }
.topbar-user {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border: 1px solid transparent; border-radius: var(--radius-full);
  background: transparent; color: var(--text);
}
.topbar-user:hover { border-color: var(--border); background: var(--white); }
.topbar-user-name { font-weight: 500; font-size: 13.5px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user .icon { width: 16px; height: 16px; color: var(--text-secondary); }

.notif-menu { width: 340px; padding: 0; }
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); color: inherit; }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--primary-extra-light); color: inherit; }
.notif-item.is-unread { background: #F8FBFE; }
.notif-item .notif-title { font-weight: 500; font-size: 13.5px; }
.notif-item .notif-time { font-size: 12px; color: var(--text-tertiary); }

.content { flex: 1; width: 100%; max-width: calc(var(--content-max) + 64px); margin: 0 auto; padding: 28px 32px 48px; }

/* ---------- Desktop: collapsed rail ---------- */
@media (min-width: 1025px) {
  body.sidebar-collapsed .sidebar { width: var(--sidebar-rail); }
  body.sidebar-collapsed .main { margin-left: var(--sidebar-rail); }
}

/* Rail appearance (desktop collapsed + tablet default) */
@media (min-width: 1025px) {
  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .nav-text,
  body.sidebar-collapsed .nav-badge,
  body.sidebar-collapsed .sidebar-user-info,
  body.sidebar-collapsed .sidebar-signout { display: none; }
  body.sidebar-collapsed .nav-section-label { visibility: hidden; height: 0; margin: 0; }
  body.sidebar-collapsed .nav-section + .nav-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
  body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
  body.sidebar-collapsed .nav-link { justify-content: center; padding: 0; }
  body.sidebar-collapsed .sidebar-user { justify-content: center; background: transparent; padding: 0; }
}

/* ---------- Tablet ---------- */
@media (min-width: 768px) and (max-width: 1024px) {
  .main { margin-left: var(--sidebar-rail); }
  .sidebar { width: var(--sidebar-rail); }
  body:not(.sidebar-open) .brand-text,
  body:not(.sidebar-open) .nav-text,
  body:not(.sidebar-open) .nav-badge,
  body:not(.sidebar-open) .sidebar-user-info,
  body:not(.sidebar-open) .sidebar-signout { display: none; }
  body:not(.sidebar-open) .nav-section-label { visibility: hidden; height: 0; margin: 0; }
  body:not(.sidebar-open) .nav-section + .nav-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
  body:not(.sidebar-open) .sidebar-brand { justify-content: center; padding: 0; }
  body:not(.sidebar-open) .nav-link { justify-content: center; padding: 0; }
  body:not(.sidebar-open) .sidebar-user { justify-content: center; background: transparent; padding: 0; }
  body.sidebar-open .sidebar { width: var(--sidebar-width); box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  .content { padding: 24px 24px 40px; }
}

/* ---------- Mobile drawer ---------- */
@media (max-width: 767px) {
  .sidebar { width: min(300px, 86vw); transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  body.sidebar-open { overflow: hidden; }
  .main { margin-left: 0; }
  .topbar { padding: 0 12px 0 16px; gap: 8px; }
  .topbar-toggle { margin-left: -6px; }
  .topbar-user-name, .topbar-user > .icon { display: none; }
  .topbar-user { padding: 2px; }
  .content { padding: 18px 16px 32px; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 20px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .card { padding: 18px; }
  .card-header.bordered { margin: -18px -18px 16px; padding: 14px 18px; }
  .notif-menu { position: fixed; left: 12px; right: 12px; top: 60px; width: auto; }
}
