/*
  topbar.css — the PALM top bar on every application page (see /js/topbar.js).

  Upgrades the existing page headers without changing their content:
  - header.page-header (most pages): sticky glass gradient bar, logo, date,
    avatar, rounded glass buttons; on phones the buttons scroll sideways
    instead of wrapping;
  - .header-bar (student dashboard, teacher timetable): keeps its own fixed
    layout and mobile menu, gets the logo and the button style only;
  - header.tb-injected: the bar added to pages that had none.
  Selectors are more specific than the pages' own header rules, so they win
  without !important; nothing outside the header is touched.
*/

body header.page-header.tb-enhanced {
  position: sticky;
  top: 0;
  z-index: 1030;
  color: #fff;
  padding: 0.65rem 1.25rem;
  background: linear-gradient(120deg, #1e293b 0%, #2c3e50 45%, #3b82f6 100%);
  box-shadow: 0 6px 24px -14px rgba(15, 23, 42, 0.7);
  transition: padding 0.25s ease, box-shadow 0.25s ease;
  isolation: isolate;
}

/* drifting light, painted inside the bar (no overflow clipping: dropdowns stay visible) */
/* the page's header was fixed: it stays fixed (the page pads its body for it) */
body header.page-header.tb-enhanced.tb-fixed { position: fixed; }

body header.page-header.tb-enhanced::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(30% 120% at 15% 40%, rgba(255, 255, 255, 0.10), transparent 70%),
    radial-gradient(25% 140% at 80% 30%, rgba(147, 197, 253, 0.18), transparent 70%);
  background-size: 140% 140%;
  animation: tb-drift 14s ease-in-out infinite alternate;
}

@keyframes tb-drift {
  from { background-position: 0% 0%; }
  to { background-position: 100% 100%; }
}

body header.page-header.tb-enhanced.scrolled {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  box-shadow: 0 10px 28px -12px rgba(15, 23, 42, 0.75);
}

body header.page-header.tb-enhanced h1,
body header.page-header.tb-enhanced h2,
body header.page-header.tb-enhanced h3,
body header.page-header.tb-enhanced h4,
body header.page-header.tb-enhanced h5 {
  color: #fff;
}

/* brand: logo + title + date */
.tb-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.tb-logo {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.95);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.45);
  transition: transform 0.3s ease;
}

.tb-logo:hover { transform: rotate(-6deg) scale(1.05); }
.tb-logo img { max-width: 32px; max-height: 32px; }

.tb-titles { display: flex; flex-direction: column; min-width: 0; }

body header.page-header.tb-enhanced .tb-titles > :is(h1, h2, h3, h4, h5) {
  margin: 0;
  font-weight: 800;
  font-size: clamp(1rem, 1.6vw + 0.4rem, 1.25rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-date { font-size: 0.74rem; opacity: 0.8; white-space: nowrap; }

/* buttons */
body header.page-header.tb-enhanced .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: none;
  transition: background 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
}

body header.page-header.tb-enhanced :is(.btn-light, .btn-primary, .btn-info, .btn-success) {
  background: rgba(255, 255, 255, 0.22);
}

body header.page-header.tb-enhanced .btn:hover,
body header.page-header.tb-enhanced .btn:focus-visible {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  transform: translateY(-1px);
}

body header.page-header.tb-enhanced .btn:active { transform: scale(0.97); }
body header.page-header.tb-enhanced .btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
body header.page-header.tb-enhanced .btn:disabled { opacity: 0.55; transform: none; }

body header.page-header.tb-enhanced :is(#logoutBtn, .btn-outline-danger, .btn-danger, .btn-outline-warning):hover {
  background: #dc3545;
  border-color: #dc3545;
}

/* the page's own text inside the bar (establishment line, etc.) */
body header.page-header.tb-enhanced :is(.text-white, small, .small) { color: rgba(255, 255, 255, 0.85); }

/* avatar */
.tb-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.82rem;
  color: #fff;
  text-transform: uppercase;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
  cursor: default;
}
a.tb-avatar { cursor: pointer; text-decoration: none; transition: transform 0.15s ease, box-shadow 0.15s ease; }
a.tb-avatar:hover, a.tb-avatar:focus-visible { color: #fff; transform: translateY(-1px); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9); }

/* pages that had no header */
body header.page-header.tb-injected { margin-bottom: 1.25rem; }

header.tb-injected .tb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

header.tb-injected .tb-inj-actions { display: flex; align-items: center; gap: 0.45rem; }

/* a page's floating language button moved into the bar */
body header.page-header.tb-enhanced .tb-moved {
  position: static;
  inset: auto;
  transform: none;
  margin: 0;
  box-shadow: none;
}

/* phones: title first, then the buttons in one row that scrolls sideways */
@media (max-width: 768px) {
  body header.page-header.tb-enhanced { padding: 0.55rem 0.75rem; }
  .tb-actions-auto {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 2px 0;
  }
  .tb-actions-auto::-webkit-scrollbar { display: none; }
  .tb-actions-auto > * { flex-shrink: 0; }
  .tb-logo { width: 36px; height: 36px; border-radius: 11px; }
  .tb-logo img { max-width: 27px; max-height: 27px; }
}

@media (max-width: 576px) {
  .tb-date { display: none; }
}

/* fixed bars (the page pads its body for a fixed height): on narrow phones everything must
   stay on one line, otherwise the second line falls outside the bar over the content */
@media (max-width: 576px) {
  body header.page-header.tb-enhanced.tb-fixed .header-actions,
  body header.page-header.tb-enhanced.tb-fixed .container-fluid { flex-wrap: nowrap; min-width: 0; }
  body header.page-header.tb-enhanced.tb-fixed .container-fluid > :first-child { flex: 1 1 auto; min-width: 0; }
  body header.page-header.tb-enhanced.tb-fixed .container-fluid > :last-child:not(:first-child) { flex: 0 0 auto; }
  body header.page-header.tb-enhanced.tb-fixed .tb-brand { min-width: 0; }
}
@media (max-width: 420px) {
  body header.page-header.tb-enhanced.tb-fixed .tb-avatar { display: none; }
  /* the logout button keeps its icon only (its label stays for screen readers) */
  body header.page-header.tb-enhanced.tb-fixed #logoutBtn:has(i) span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

/* .header-bar pages: logo and button style only (their layout and menu stay) */
.header-bar.tb-bar .tb-logo { width: 34px; height: 34px; border-radius: 10px; margin-inline-end: 0.5rem; }
.header-bar.tb-bar .tb-logo img { max-width: 26px; max-height: 26px; }
.header-bar.tb-bar .header-title { display: flex; flex-direction: row; align-items: center; }
.header-bar.tb-bar .tb-bar-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.header-bar.tb-bar .header-actions .btn { border-radius: 10px; transition: background 0.2s ease, transform 0.15s ease; }
.header-bar.tb-bar .header-actions .btn:hover { transform: translateY(-1px); }

/* notifications bell and its panel (attached to <body>, fixed under the bell) */
.tb-notif-btn { position: relative; align-items: center; justify-content: center; }
.tb-notif-count {
  position: absolute; top: -6px; inset-inline-end: -6px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.35);
}
.tb-notif-count[hidden] { display: none; }
.tb-notif-panel {
  position: fixed; z-index: 1080; max-height: min(70vh, 520px); display: flex; flex-direction: column;
  background: var(--ui-surface, #fff); color: var(--ui-text, #0f172a);
  border: 1px solid var(--ui-border, rgba(15, 23, 42, 0.08)); border-radius: 14px;
  box-shadow: 0 18px 40px -18px rgba(15, 23, 42, 0.45); overflow: hidden; font-size: 0.9rem;
}
.tb-notif-panel[hidden] { display: none; }
.tb-notif-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--ui-border, #e5e7eb); }
.tb-notif-readall { border: 0; background: none; padding: 0; color: var(--ui-primary, #4f46e5); font-size: 0.8rem; cursor: pointer; }
.tb-notif-readall:hover { text-decoration: underline; }
.tb-notif-readall[hidden] { display: none; }
.tb-notif-list { overflow-y: auto; flex: 1 1 auto; }
.tb-notif-item { display: block; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--ui-border, #e5e7eb); color: inherit; text-decoration: none; position: relative; }
.tb-notif-item:hover, .tb-notif-item:focus-visible { background: var(--ui-surface-2, #f8fafc); color: inherit; }
.tb-notif-item.unread { padding-inline-start: 1.6rem; }
.tb-notif-item.unread::before { content: ""; position: absolute; inset-inline-start: 0.7rem; top: 1.05rem; width: 8px; height: 8px; border-radius: 50%; background: var(--ui-primary, #4f46e5); }
.tb-notif-title { font-weight: 600; line-height: 1.35; }
.tb-notif-item:not(.unread) .tb-notif-title { font-weight: 500; }
.tb-notif-body { color: var(--ui-muted, #64748b); font-size: 0.82rem; margin-top: 0.15rem; white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tb-notif-time { color: var(--ui-muted, #64748b); font-size: 0.72rem; margin-top: 0.25rem; }
.tb-notif-empty { padding: 1.4rem 0.9rem; text-align: center; color: var(--ui-muted, #64748b); }
.tb-notif-all { display: block; padding: 0.6rem 0.9rem; text-align: center; font-weight: 600; text-decoration: none; color: var(--ui-primary, #4f46e5); }
.tb-notif-all:hover { background: var(--ui-surface-2, #f8fafc); }

@media print {
  .tb-notif-btn, .tb-notif-panel { display: none !important; }
  body header.page-header.tb-enhanced { position: static; box-shadow: none; }
  body header.page-header.tb-enhanced::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  body header.page-header.tb-enhanced::before { animation: none; }
  body header.page-header.tb-enhanced, .tb-logo, body header.page-header.tb-enhanced .btn { transition: none; }
}
