/*
 * main.css — Global base styles for BloodSync.
 *
 * Minimal functional styles only — enough for testing.
 * Design pass happens in Phase 4.
 *
 * Covers: reset, body, shared button classes, shared form elements,
 * feedback elements (error, success), toast container, modal overlay.
 */

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

/* ── Base ────────────────────────────────────────────────────────── */
body {
  font-family: sans-serif;
  font-size: 14px;
  color: #111;
  background: #f5f5f5;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── Shared buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  padding: 8px 16px;
  background: #c00;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-block;
  padding: 8px 16px;
  background: #eee;
  color: #111;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

.btn-danger {
  display: inline-block;
  padding: 8px 16px;
  background: #c00;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

.btn-retry {
  display: inline-block;
  padding: 6px 14px;
  background: #eee;
  color: #111;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}

/* Modifier — applied alongside .btn-primary or .btn-secondary */
.btn-full-width {
  width: 100%;
  display: block;
  text-align: center;
}

/* Modifier — applied alongside .btn-primary or .btn-secondary for a
   smaller footprint (e.g. per-card action buttons). notifications.css
   already has its own .btn-xs for the "Mark read" button — this is a
   slightly larger step, added here (not a feature CSS file) since it's
   a generic reusable size, same reasoning as .btn-full-width above. */
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ── Shared form elements ────────────────────────────────────────── */

/* Legacy pattern (.field > label + input) — kept for existing pages */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid #c00;
  outline-offset: 1px;
}

/* Current pattern (.form-group > .form-label + .form-input) */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.form-input:focus {
  outline: 2px solid #c00;
  outline-offset: 1px;
}

/* ── Field errors ────────────────────────────────────────────────── */
/*
 * .field-error is visible by default — pair with .field-error-hidden to hide.
 * JS toggles .field-error-hidden on/off to show/hide errors.
 * Same pattern as .notif-badge / .notif-badge-hidden.
 */
.field-error {
  display: block;
  font-size: 12px;
  color: #c00;
  margin-top: 4px;
}

.field-error-hidden {
  display: none;
}

/* ── Shared modal field patterns ────────────────────────────────── */
/* Used by any feature's reason/confirm modals (Blood Testing, Blood
   Units, Blood Separation, etc.) and detail-view modals. Moved here
   from bloodUnits.css / bloodCollections.css (previously duplicated
   identically in both) — see gochas.md DRY gap note. Any feature CSS
   file must NOT redefine these — extend with a modifier class instead,
   same rule as .btn-primary / .page-header. */
.modal-field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.modal-textarea:focus {
  outline: 2px solid #c00;
  outline-offset: 1px;
}

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
}

.detail-list dt {
  font-size: 0.82rem;
  font-weight: 600;
  color: #666;
}

.detail-list dd {
  font-size: 0.88rem;
  color: #111;
}

/* ── Shared data table ──────────────────────────────────────────── */
/* Moved from pages/admin/bloodDrives.css + pages/staff/bloodDrives.css
   (identical duplicates of each other) — was Blood-Drives-only, but
   Blood Units, Blood Testing, Blood Separation, and Inventory Cleaning
   all render <table class="data-table"> and none of their linked CSS
   files defined it, so those tables rendered completely unstyled.
   Feature/page CSS must not redefine this — extend with a modifier
   class instead, same rule as .btn-primary / .page-header. */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.9rem;
}

.data-table th {
  font-weight: 600;
  background: #f8f8f8;
  color: #444;
}

.data-table tbody tr:hover {
  background: #fafafa;
}

/* ── Page header ─────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: #111;
}

/* Modifier — page header with a right-aligned action button (e.g. "Mark
   all as read"), or just to get the correct h1 size (20px/700) from a
   single shared source. pages/admin/bloodDrives.css, pages/staff/
   bloodDrives.css, pages/staff/bloodUnits.css, and pages/staff/
   bloodCollections.css previously all redefined .page-header directly
   (flex/space-between + h1 sizing) — removed, all four now use this
   modifier. bloodSeparation.html, bloodRequests.html, and
   bloodRequestDetail.html had NO override at all, so their h1 fell
   through to the browser default (~2em) — visibly larger than every
   other page. Adding this modifier fixes both problems in one place. */
.page-header--with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-header--with-action h1 {
  font-size: 20px;
  font-weight: 700;
  color: #111;
}

/* ── Toast (toast.js) ────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 4px;
  border: 1px solid #ccc;
  background: #fff;
  font-size: 13px;
  min-width: 260px;
  max-width: 360px;
}

.toast-success { border-color: #4caf50; }
.toast-error   { border-color: #c00;    }
.toast-warning { border-color: #ff9800; }
.toast-info    { border-color: #2196f3; }

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  flex-shrink: 0;
}

.toast-hiding {
  opacity: 0;
  transition: opacity 0.3s;
}

/* ── Modal (modal.js) ────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.modal-open {
  display: flex;
}

.modal-dialog {
  background: #fff;
  border-radius: 4px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  margin: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
}

.modal-body {
  padding: 20px;
  font-size: 14px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #eee;
}

/* ── Skeleton (skeleton.js) ──────────────────────────────────────── */
.skeleton-item {
  background: #eee;
  border-radius: 4px;
  margin-bottom: 8px;
  padding: 12px;
}

.skeleton-line {
  height: 12px;
  background: #ddd;
  border-radius: 2px;
  margin-bottom: 6px;
}

.skeleton-line-wide   { width: 100%; }
.skeleton-line-medium { width: 65%;  }
.skeleton-line-narrow { width: 40%;  }

.skeleton-table-row {
  display: flex;
  gap: 12px;
  padding: 10px;
}

.skeleton-cell {
  flex: 1;
  height: 14px;
  background: #ddd;
  border-radius: 2px;
}

.skeleton-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  background: #ddd;
  border-radius: 50%;
  flex-shrink: 0;
}

.skeleton-lines { flex: 1; }

/* ── Error boundary (errorBoundary.js) ───────────────────────────── */
.error-boundary {
  padding: 24px;
  text-align: center;
  color: #666;
}

.error-boundary-icon {
  font-size: 24px;
  display: block;
  margin-bottom: 8px;
}

.error-boundary-message {
  font-size: 14px;
  margin-bottom: 8px;
}

/* ── Navbar (navbar.js) ──────────────────────────────────────────── */
/* Identity-only navbar — no feature nav links here. All page navigation
   lives in the sidebar (see sidebarItems.js). Navbar renders: brand,
   notifications link + badge, username, logout button. */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  height: 52px;
}

.navbar-brand a {
  font-weight: 700;
  font-size: 16px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.navbar-notif-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #111;
}

.notif-badge {
  display: inline-block;
  background: #c00;
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: 4px;
}

.notif-badge-hidden {
  display: none;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Wraps avatar + username in a link to the user's own Profile page
   (added this session — navbar.js's avatar/name block is now clickable).
   Reproduces the same 12px gap the avatar/username had as flat siblings
   of .navbar-user before this wrap, so spacing is visually unchanged. */
.navbar-profile-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.navbar-profile-link:hover .navbar-username {
  text-decoration: underline;
}

.navbar-username {
  font-size: 13px;
}

.navbar-username {
  font-size: 13px;
}

.btn-logout {
  padding: 6px 12px;
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Sidebar (sidebar.js) ────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 52px;       /* sits flush below the fixed navbar */
  left: 0;
  bottom: 0;
  width: 200px;
  padding: 16px;
  background: #fff;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  margin-bottom: 8px;
}

.sidebar-links {
  list-style: none;
}

.sidebar-links a {
  display: block;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 4px;
}

.sidebar-links a.sidebar-active {
  font-weight: 700;
  background: #f0f0f0;
}

/* ── Sidebar collapsible groups (field role workflow) ────────────── */
/* Used by Volunteer and Phlebotomist for the Blood Drive Workflow
   section. Rendered via <details>/<summary> in sidebar.js when an
   item has { group: true, children: [] }. Open by default. */

.sidebar-group-item {
  list-style: none;
}

.sidebar-group-label {
  display: block;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  color: #444;
}

/* Remove default disclosure triangle */
.sidebar-group-label::-webkit-details-marker { display: none; }
.sidebar-group-label::marker                 { display: none; }

/* Highlight group label when a child is the active page */
.sidebar-group-active > .sidebar-group-label {
  color: #c00;
}

.sidebar-group-links {
  list-style: none;
  padding-left: 12px;
  margin-top: 2px;
}

.sidebar-group-links a {
  display: block;
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 4px;
  color: #333;
}

.sidebar-group-links a.sidebar-active {
  font-weight: 700;
  background: #f0f0f0;
}

/* ── Page layout shell ───────────────────────────────────────────── */
/* Both navbar (52px tall) and sidebar (200px wide) are fixed.
   page-shell is offset from the top so it starts below the navbar.
   page-content is offset from the left so it starts beside the sidebar. */
.page-shell {
  display: flex;
  padding-top: 52px;   /* clear the fixed navbar */
}

.page-content {
  flex: 1;
  padding: 24px;
  margin-left: 200px;  /* clear the fixed sidebar */
  min-width: 0;        /* prevent flex children from overflowing */
}

/* ── App shell reveal pattern ────────────────────────────────────── */
/* Prevents static HTML (table headers, page buttons, etc.) from flashing
   on screen before JS has rendered the navbar/sidebar shell. Every
   protected page's <body> starts with class="app-loading" in the HTML.
   The entry file adds class="app-ready" to <body> immediately after
   renderNavbar() + renderSidebar() complete (see "Required Page Loading
   Order" in FRONTEND_AI_RULES.md). #navbar, #sidebar, and .page-content
   are invisible (not unrendered — visibility, not display) until then,
   so the user never sees raw, chrome-less HTML before the shell exists. */
body.app-loading #navbar,
body.app-loading #sidebar,
body.app-loading .page-content {
  visibility: hidden;
}

body.app-ready #navbar,
body.app-ready #sidebar,
body.app-ready .page-content {
  visibility: visible;
}

.navbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.navbar-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-light, #fdecea);
  color: var(--color-primary, #c0392b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Generic hidden utility ──────────────────────────────────────── */
/* Added for the Profile redesign (components/editToggle.js and avatar/
   document-link toggling in profileUI.js / profileFieldUI.js). Existing
   single-purpose hidden classes (.field-error-hidden, .notif-badge-hidden,
   .photo-preview-hidden) stay as-is for their own call sites — this is a
   feature-agnostic one for new reusable components going forward. */
.hidden { display: none !important; }