/* StudyBuddy — Global layout, variables, sidebar, header */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-soft: #DBEAFE;
  --sidebar-bg: #0F1E3D;
  --sidebar-active: #1E3A6E;
  --page-bg: #F4F7FB;
  --card-bg: #FFFFFF;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --text-heading: #0F172A;
  --text-body: #475569;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --success: #16A34A;
  --success-bg: #DCFCE7;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --info: #2563EB;
  --info-bg: #DBEAFE;
  --math: #2563EB;
  --science: #16A34A;
  --english: #7C3AED;
  --cs: #EA580C;
  --filipino: #0D9488;
  --history: #E11D48;
  --ias: #2563EB;
  --iaslab: #16A34A;
  --sysad: #7C3AED;
  --capstone: #EA580C;
  --sia: #0D9488;
  --xplat: #E11D48;
  --sidebar-width: 250px;
  --right-col: 320px;
  --header-height: 72px;
  --transition: 180ms ease;
  --font: 'Inter', system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --sidebar-bg: #070B14;
  --sidebar-active: #111B2D;
  --primary-soft: #172554;
  --page-bg: #080B12;
  --card-bg: #111722;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.65);
  --text-heading: #F1F5F9;
  --text-body: #CBD5E1;
  --text-muted: #94A3B8;
  --border: #252E3D;
  --success-bg: #052E1A;
  --warning-bg: #3B2608;
  --danger-bg: #450A0A;
  --info-bg: #10244C;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; scrollbar-gutter: stable; }

body {
  font-family: var(--font);
  color: var(--text-body);
  background: var(--page-bg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
ul, ol { list-style: none; }
h1, h2, h3, h4 { color: var(--text-heading); font-weight: 700; line-height: 1.25; }

/* ========== App Shell ========== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition), width var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
}

.sidebar-brand img,
.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sidebar-brand .brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border-radius: 10px;
  color: #fff;
}

.sidebar-brand span {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  color: rgba(255, 255, 255, 0.72);
  border-radius: 10px;
  font-weight: 500;
  font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-nav a i,
.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 1.75;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 12px 14px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition);
}

.user-card:hover { background: rgba(255, 255, 255, 0.06); }

.user-card .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 13px;
}

.user-card .meta { flex: 1; min-width: 0; }
.user-card .meta .name {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-card .meta .role {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
}

.user-card .chevron { color: rgba(255, 255, 255, 0.4); width: 16px; height: 16px; }

/* ========== Main Area ========== */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-heading);
  padding: 8px;
  border-radius: 8px;
}
.menu-toggle:hover { background: var(--page-bg); }

.header-search {
  flex: 1;
  max-width: 520px;
  position: relative;
}

.global-search-results {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

.global-search-results[hidden] { display: none; }

.global-search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--text-heading);
  text-decoration: none;
}

.global-search-result:hover,
.global-search-result:focus-visible {
  outline: none;
  background: var(--page-bg);
}

.global-search-result-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.global-search-result-title,
.global-search-result-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-search-result-title {
  font-size: 13px;
  font-weight: 600;
}

.global-search-result-detail {
  color: var(--text-muted);
  font-size: 11px;
}

.global-search-result-type {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.global-search-empty {
  padding: 14px 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.header-search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 16px 0 42px;
  background: var(--page-bg);
  color: var(--text-heading);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.header-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  background: var(--card-bg);
}

.header-search input::placeholder { color: var(--text-muted); }

.header-search .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-body);
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--page-bg); }
.icon-btn .badge-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--card-bg);
}

.notification-wrap { position: relative; }
.notification-panel[hidden] { display: none; }
.notification-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 100;
  width: min(360px, calc(100vw - 24px));
  max-height: min(460px, calc(100vh - var(--header-height) - 24px));
  overflow: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .16);
}
.notification-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.notification-panel-header h2 {
  margin: 0;
  color: var(--text-heading);
  font-size: 15px;
}
.notification-panel-header button {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.notification-panel-header button[hidden] { display: none; }
.notification-list { padding: 6px; }
.notification-empty {
  margin: 0;
  padding: 24px 12px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}
.notification-item {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-body);
  text-align: left;
  cursor: pointer;
}
.notification-item:hover { background: var(--page-bg); }
.notification-item.unread { background: var(--primary-soft); }
.notification-item-title { color: var(--text-heading); font-size: 13px; font-weight: 600; }
.notification-item-body { font-size: 12px; line-height: 1.4; }
.notification-item time { color: var(--text-muted); font-size: 11px; }

.header-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px 4px 4px;
  border-radius: 999px;
  transition: background var(--transition);
}
.header-user:hover { background: var(--page-bg); }

.header-user .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

.header-user .name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-heading);
}
.header-user .role-label {
  font-size: 11px;
  color: var(--text-muted);
}
.header-user .chevron { color: var(--text-muted); width: 16px; height: 16px; }

/* ========== Page Content ========== */
.page-content {
  padding: 28px;
  flex: 1;
  min-width: 0;
}

.page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--right-col));
  gap: 24px;
  align-items: start;
}

.page-main { min-width: 0; }
.page-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: calc(var(--header-height) + 16px);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-heading);
}

.page-title .title-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.page-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13.5px;
  margin-left: 52px;
}

.greeting {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.greeting-sub {
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ========== Overlay / Mobile ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 61, 0.45);
  z-index: 90;
}

body.sidebar-open .sidebar-overlay { display: block; }

@media (max-width: 1200px) {
  :root { --right-col: 280px; }
  .page-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 260px); }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: flex; }
  .page-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .page-aside {
    position: static;
  }
  .header-user .name,
  .header-user .role-label { display: none; }
  .page-content { padding: 16px; }
}

@media (max-width: 640px) {
  .top-header {
    height: auto;
    min-height: var(--header-height);
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }
  .menu-toggle { flex: 0 0 40px; justify-content: center; }
  .header-search {
    order: 2;
    flex: 0 0 100%;
    max-width: none;
    min-width: 0;
  }
  .header-actions { order: 1; gap: 6px; }
  .header-divider { display: none; }
  .header-user { padding: 2px; }
  .page-content { padding: 14px 12px; }
  .page-header {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
  }
  .page-header > .btn { align-self: flex-start; }
  .page-title { gap: 8px; font-size: 20px; }
  .page-title .title-icon { width: 36px; height: 36px; }
  .page-subtitle { margin-left: 0; font-size: 12.5px; }
  .page-layout { gap: 16px; }
  .page-aside { gap: 12px; }
  .greeting { font-size: 22px; }
}
