/* ============================================
   Base Styles - Reset, Typography, Layout
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-stack);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

button {
  font-family: var(--font-stack);
  cursor: pointer;
  border: none;
  background: none;
  font-size: inherit;
  color: inherit;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

input, select, textarea {
  font-family: var(--font-stack);
  font-size: 0.875rem;
}

/* --- App Layout --- */
#app {
  width: 100%;
}

.app-layout {
  display: flex;
  width: 100%;
  height: 100vh;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header {
  position: relative;
  z-index: 100;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  flex-shrink: 0;
  overflow: visible;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

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

.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1-5) var(--space-3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}

.header-user:hover { background: var(--color-accent-light); }

.header-user-name {
  font-size: 0.875rem;
  font-weight: 500;
}

.header-user-role {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: capitalize;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}

/* --- Notifications Bell --- */
.header-notif-btn {
  position: relative;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.header-notif-btn:hover {
  background: var(--color-accent-light);
  color: var(--color-text);
}

.header-notif-btn.has-unread {
  color: var(--color-accent);
  background: var(--color-accent-light);
  animation: bellPulse 2s ease-in-out infinite;
}

@keyframes bellPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-accent) 15%, transparent); }
}

.header-notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-error);
  border: 2px solid var(--color-surface);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

.header-notif-wrap {
  position: relative;
}

.dropdown-menu.notif-dropdown {
  right: 0;
  left: auto;
  min-width: 480px;
  max-height: 440px;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.notif-dropdown-header {
  padding: var(--space-3-5) 18px var(--space-2-5);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 18px;
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition-fast);
}

.notif-item:hover { background: var(--color-accent-light); }

.notif-item.unread {
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}

.notif-item.unread .notif-title::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
  margin-right: var(--space-1-5);
  vertical-align: middle;
}

.notif-icon {
  flex-shrink: 0;
  margin-top: 2px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border-radius: 50%;
}

.notif-content { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; line-height: 1.3; }
.notif-body { font-size: 12px; color: var(--color-text-secondary); margin-top: 2px; line-height: 1.4; }
.notif-time { font-size: 11px; color: var(--color-text-muted); margin-top: var(--space-1); }

.notif-mark-all, .notif-view-all {
  display: block;
  width: 100%;
  padding: var(--space-3) 18px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-accent);
  cursor: pointer;
  text-align: center;
}

.notif-mark-all:hover, .notif-view-all:hover { background: var(--color-accent-light); }
.notif-view-all { border-top: 1px solid var(--color-border); }

/* --- Notifications Page --- */
.notif-list { display: flex; flex-direction: column; gap: 0; }

.notif-list-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3-5);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.notif-list-item:hover { background: var(--color-surface); }
.notif-list-item.unread { background: color-mix(in srgb, var(--color-accent) 6%, transparent); }
.notif-list-icon { flex-shrink: 0; margin-top: 2px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; color: var(--color-text-secondary); }
.notif-list-body { flex: 1; }
.notif-list-title { font-weight: 600; margin-bottom: var(--space-1); }
.notif-list-message { font-size: 13px; color: var(--color-text-secondary); line-height: 1.4; }
.notif-list-time { font-size: 12px; color: var(--color-text-secondary); margin-top: var(--space-1-5); }

/* --- Main Content --- */
#content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.page-header {
  margin-bottom: var(--space-6);
}

.page-header:has(.page-header-actions) {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.page-header-actions {
  flex-shrink: 0;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.page-header p {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* --- Login Page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: var(--color-bg);
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px; /* login card: intentional large value */
  width: 100%;
  max-width: 400px;
}

.login-logo {
  width: 180px;
  height: 52px;
  margin: 0 auto var(--space-4);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 80'%3E%3Crect width='300' height='80' rx='8' fill='black'/%3E%3Ctext x='150' y='55' font-size='42' font-weight='bold' fill='white' text-anchor='middle' font-family='Arial,sans-serif'%3EManabu%3C/text%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
  text-align: center;
}

.login-card p {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  margin-bottom: var(--space-6);
  text-align: center;
}

.login-error {
  background: var(--color-error-light);
  color: var(--color-error);
  padding: var(--space-2-5) var(--space-3-5);
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: var(--space-4);
  display: none;
}

/* --- Utility --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

/* --- Header Brand Logo --- */
.header-brand-logo {
  max-height: 28px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.header-default-logo {
  width: 90px;
  height: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 80'%3E%3Crect width='300' height='80' rx='8' fill='black'/%3E%3Ctext x='150' y='55' font-size='42' font-weight='bold' fill='white' text-anchor='middle' font-family='Arial,sans-serif'%3EManabu%3C/text%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* --- Header Left/Right (equal width for centered search) --- */
.header-left,
.header-right {
  flex: 1;
  min-width: 0;
}

.header-right {
  justify-content: flex-end;
}

/* --- Header Search --- */
.header-search {
  position: absolute;
  left: calc(50vw - var(--sidebar-width));
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
}

/* When sidebar is collapsed (learner dashboard), center relative to full viewport */
.sidebar-collapsed .header-search {
  left: 50vw;
}

.header-search .search-bar {
  max-width: 100%;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  display: none;
  max-height: 300px;
  overflow-y: auto;
  margin-top: var(--space-1);
}

.search-results.open { display: block; }

.search-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--transition-fast);
}

.search-result-item:hover,
.search-result-item.active { background: var(--color-accent-light); }

.search-result-title { font-weight: 500; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; z-index: 100; }
  #content { padding: var(--space-4); }
  .header { padding: 0 var(--space-4); }

  /* Search stays available on small screens — it just stops being absolutely
     centred and flexes into whatever space is left between the hamburger and
     the avatar. */
  .header-search {
    position: static;
    left: auto;
    transform: none;
    flex: 1;
    min-width: 0;
    max-width: none;
  }
  .header-left,
  .header-right { flex: 0 0 auto; }
  .header-brand-logo { display: none; }
  .header-user-name,
  .header-user-role { display: none; }
}
