/* ============================================================
   SIMS — Main Stylesheet
   ============================================================ */

:root {
  --sidebar-width: 260px;
  --sidebar-collapsed: 68px;
  --primary:    #0d6efd;
  --success:    #198754;
  --danger:     #dc3545;
  --warning:    #ffc107;
  --info:       #0dcaf0;
  --sidebar-bg: #0f172a;
  --sidebar-text: rgba(255,255,255,.75);
  --sidebar-active-bg: rgba(13,110,253,.2);
  --sidebar-active-text: #fff;
  --sidebar-section: rgba(255,255,255,.35);
  --topbar-height: 58px;
  --card-shadow: 0 1px 4px rgba(0,0,0,.08);
  --border-radius: .5rem;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-bs-theme="dark"] {
  --sidebar-bg: #0a0e1a;
  --card-shadow: 0 1px 4px rgba(0,0,0,.3);
}

/* ── Base ──────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  font-family: var(--font);
  font-size: 14px;
  overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease, width .25s ease;
  overflow: hidden;
}

.sidebar-header { background: rgba(255,255,255,.04); flex-shrink: 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-brand { font-weight: 700; font-size: 13px; color: #fff; line-height: 1.2; }
.sidebar-sub { font-size: 10px; opacity: .5; letter-spacing: .5px; text-transform: uppercase; }
.sidebar-logo { width: 38px; height: 38px; background: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.sidebar-body { flex: 1; overflow-y: auto; padding: .5rem 0; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.1) transparent; }
.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.sidebar .nav-link {
  color: var(--sidebar-text);
  padding: .45rem 1rem;
  border-radius: .35rem;
  margin: 1px .5rem;
  font-size: 13px;
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.sidebar .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  width: 3px; height: 24px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}
.sidebar .nav-link { position: relative; }
.sidebar .nav-link i { font-size: 15px; flex-shrink: 0; }

.nav-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sidebar-section);
  padding: .75rem 1.25rem .25rem;
  list-style: none;
  white-space: nowrap;
}

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1039;
}

/* ── Collapsed sidebar ─────────────────────────────────── */
body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .nav-section,
body.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .sidebar-sub,
body.sidebar-collapsed .sidebar-footer .fw-semibold,
body.sidebar-collapsed .sidebar-footer div[style] { display: none; }
body.sidebar-collapsed .sidebar .nav-link { justify-content: center; margin: 1px 6px; padding: .5rem; }
body.sidebar-collapsed .sidebar .nav-link i { margin: 0 !important; }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed); }
body.sidebar-collapsed .sidebar-logo { margin: auto; }
body.sidebar-collapsed .sidebar-header .d-flex { justify-content: center; }

/* ── Main Content ──────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left .25s ease;
  display: flex;
  flex-direction: column;
}

.top-navbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  position: sticky;
  top: 0;
  z-index: 900;
  flex-shrink: 0;
}

.sidebar-toggle { color: var(--bs-body-color); padding: .25rem .5rem; }

.page-content { flex: 1; }

/* ── Avatar ────────────────────────────────────────────── */
.avatar-sm {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.avatar-lg {
  width: 90px; height: 90px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700;
}

/* Prevent flex children from overflowing */
.min-width-0 { min-width: 0; }

/* ── Stat Cards ────────────────────────────────────────── */
.stat-card {
  border-radius: var(--border-radius);
  border: none;
  box-shadow: var(--card-shadow);
  transition: transform .15s, box-shadow .15s;
  overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.1); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

/* ── Data Tables ───────────────────────────────────────── */
.sims-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--bs-tertiary-bg);
  white-space: nowrap;
}
.sims-table td { vertical-align: middle; }
.sims-table tbody tr { transition: background .1s; }
.sims-table tbody tr:hover { background: var(--bs-tertiary-bg); }

/* ── Cards ─────────────────────────────────────────────── */
.card { border-radius: var(--border-radius); box-shadow: var(--card-shadow); }
.card-header { font-weight: 600; }

/* ── Search Bar ─────────────────────────────────────────── */
.search-bar { max-width: 300px; }

/* ── Status indicators ─────────────────────────────────── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.status-dot.admitted { background: var(--danger); animation: pulse 1.5s infinite; }
.status-dot.available { background: var(--success); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ── Notification dropdown ─────────────────────────────── */
.notification-dropdown { max-height: 400px; overflow-y: auto; }
.notification-dropdown .dropdown-header {
  background: var(--bs-tertiary-bg);
  padding: .75rem 1rem;
  font-size: 13px;
  position: sticky; top: 0;
}

/* ── Login Page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0d6efd 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: 420px;
  max-width: calc(100vw - 2rem);
  border-radius: 1rem;
  border: none;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-logo { width: 72px; height: 72px; background: var(--primary); border-radius: 20px; margin: 0 auto 1rem; display: flex; align-items: center; justify-content: center; }

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}
.page-title { font-size: 1.25rem; font-weight: 700; margin: 0; }
.page-subtitle { font-size: 13px; color: var(--bs-secondary-color); margin: 0; }

/* ── Sick Bay Grid ─────────────────────────────────────── */
.bed-card {
  border-radius: .75rem;
  border: 2px solid var(--bs-border-color);
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.bed-card.occupied { border-color: var(--danger); background: rgba(220,53,69,.05); }
.bed-card.available { border-color: var(--success); }
.bed-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }

/* ── Vitals Grid ─────────────────────────────────────────── */
.vital-item { text-align: center; padding: .75rem; background: var(--bs-tertiary-bg); border-radius: .5rem; }
.vital-value { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.vital-label { font-size: 11px; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .5px; }

/* ── Student Profile ─────────────────────────────────────── */
.profile-header { background: linear-gradient(135deg, #0d6efd, #0a58ca); color: #fff; border-radius: var(--border-radius) var(--border-radius) 0 0; padding: 2rem; }
.profile-photo { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; border: 3px solid rgba(255,255,255,.4); }
.profile-photo-placeholder { width: 90px; height: 90px; border-radius: 50%; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; border: 3px solid rgba(255,255,255,.4); }
.info-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--bs-secondary-color); font-weight: 600; margin-bottom: 2px; }
.info-value { font-weight: 500; }

/* ── Timeline ─────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content:''; position: absolute; left: .5rem; top: 0; bottom: 0; width: 2px; background: var(--bs-border-color); }
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-dot { position: absolute; left: -1.75rem; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); border: 2px solid var(--bs-body-bg); top: 4px; }
.timeline-content { background: var(--bs-tertiary-bg); border-radius: .5rem; padding: .75rem 1rem; }

/* ── QR Code ─────────────────────────────────────────────── */
.qr-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: .5rem; padding: 1rem; background: #fff; border-radius: .5rem; }

/* ── Progress Bar Animated ──────────────────────────────── */
.progress-bar { transition: width .6s ease; }

/* ── Mobile Responsive ───────────────────────────────────── */
@media (max-width: 991.98px) {

  /* Sidebar hidden off-screen */
  .sidebar {
    transform: translateX(-100%);
    z-index: 1040;
    width: 280px !important;
    box-shadow: none;
    transition: transform .28s ease;
  }

  /* Sidebar visible when body has sidebar-open class */
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 6px 0 30px rgba(0,0,0,.5);
  }

  /* Overlay hidden by default */
  .sidebar-overlay {
    display: none;
    z-index: 1039;
  }

  /* Overlay visible when sidebar open */
  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  /* Main content full width */
  .main-content {
    margin-left: 0 !important;
    z-index: 1;
    position: relative;
  }

  body.sidebar-collapsed .main-content { margin-left: 0 !important; }

  /* Hamburger always on top */
  #sidebarToggle {
    position: relative;
    z-index: 1050 !important;
  }

  /* Top navbar */
  .top-navbar {
    position: sticky;
    top: 0;
    z-index: 500;
  }
}

@media (max-width: 575.98px) {
  .page-content { padding: .75rem !important; }
  .page-header { margin-bottom: 1rem; }
  .page-title { font-size: 1.1rem; }
}

/* ── Misc ─────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.text-xs { font-size: 11px; }
.fw-medium { font-weight: 500; }

/* ── Extra Responsive Breakpoints ───────────────────────── */

/* Tablet (768px and below) */
@media (max-width: 767.98px) {

  /* Stat cards — 2 per row on mobile */
  .stat-card .card-body { padding: .75rem; }
  .stat-icon { width: 42px; height: 42px; font-size: 18px; }
  .stat-card .fs-3 { font-size: 1.5rem !important; }

  /* Page header — stack vertically */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header > div:last-child { width: 100%; }
  .page-header .btn,
  .page-header .d-flex { width: 100%; justify-content: flex-start; flex-wrap: wrap; }

  /* Dashboard charts — full width on mobile */
  .chart-container { height: 200px !important; }

  /* Tables — horizontal scroll */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--border-radius);
  }

  /* Hide less important table columns on mobile */
  .hide-mobile { display: none !important; }

  /* Table header — no wrapping */
  .sims-table th { white-space: nowrap; font-size: 11px; }
  .sims-table td { font-size: 13px; }

  /* Card body padding reduction */
  .card-body { padding: .875rem; }
  .card-header { padding: .75rem .875rem; font-size: 14px; }

  /* Forms — full width inputs */
  .search-bar { max-width: 100%; width: 100%; }

  /* Top navbar */
  .top-navbar .breadcrumb { display: none !important; }
  .top-navbar { padding: .5rem .75rem !important; }

  /* Profile header on student view */
  .profile-header { padding: 1.25rem; }
  .profile-header h2 { font-size: 1.1rem; }
  .profile-photo, .profile-photo-placeholder { width: 70px; height: 70px; }

  /* Vital items — smaller text */
  .vital-value { font-size: 1.1rem; }
  .vital-item { padding: .5rem; }

  /* Bed grid — 2 columns on mobile */
  .bed-card { padding: .75rem .5rem; }

  /* Timeline */
  .timeline { padding-left: 1.5rem; }

  /* Modal — full screen on mobile */
  .modal-dialog { margin: .5rem; max-width: calc(100vw - 1rem); }
  .modal-body { padding: 1rem; }

  /* Sidebar section labels */
  .nav-section { padding-left: 1rem; }

  /* Filters form — stack on mobile */
  .card-body .row.g-2 > [class*="col-md"] { flex: 0 0 100%; max-width: 100%; }

  /* Avatar */
  .avatar-sm { width: 30px; height: 30px; font-size: 11px; }

  /* Prevent iOS zoom-on-focus: Safari zooms when input font < 16px */
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm,
  input, textarea, select {
    font-size: 16px !important;
  }
}

/* Small mobile (480px and below) */
@media (max-width: 479.98px) {

  /* Stat cards — still 2 per row but smaller */
  .stat-card .fs-3 { font-size: 1.25rem !important; }
  .stat-icon { width: 36px; height: 36px; font-size: 16px; border-radius: 8px; }

  /* Page title smaller */
  .page-title { font-size: 1rem; }

  /* Nav tabs — scrollable horizontally */
  .nav-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-link { white-space: nowrap; padding: .5rem .75rem; font-size: 13px; }

  /* Action buttons in tables — icon only */
  .btn-action-text { display: none; }

  /* Login card padding */
  .login-card .card-body { padding: 1.75rem 1.25rem !important; }

  /* Report type cards */
  .report-type-card .fs-3 { font-size: 1.5rem !important; }
}

/* Large screens — wider sidebar */
@media (min-width: 1400px) {
  :root { --sidebar-width: 280px; }
}

/* Print — hide everything except content */
@media print {
  .sidebar, .top-navbar, .flash-container,
  .no-print, .btn, nav.breadcrumb,
  #sidebarToggle, #darkModeToggle { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
  body { font-size: 12px; }
  .page-header { border-bottom: 2px solid #000; margin-bottom: 1rem; }
  table { font-size: 11px; }
  .badge { border: 1px solid #000 !important; color: #000 !important; background: none !important; }
}

.medical-alert {
  border-left: 4px solid var(--danger);
  background: rgba(220,53,69,.06);
  border-radius: 0 .5rem .5rem 0;
  padding: .75rem 1rem;
}

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 3rem; opacity: .3; }

/* Chart container */
.chart-container { position: relative; }

/* Scrollable table wrapper */
.table-responsive { border-radius: var(--border-radius); }

/* Form section dividers */
.form-section { border-left: 3px solid var(--primary); padding-left: 1rem; margin-bottom: 1.5rem; }
.form-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--primary); margin-bottom: 1rem; }

/* ============================================================
   MOBILE USABILITY — Quick Wins (A)
   ============================================================ */

/* ── 1. Touch targets ─────────────────────────────────────
   On touch devices (phones/tablets), make interactive
   elements large enough to tap reliably (≈44px guideline).
   Uses pointer:coarse so desktops with a mouse are untouched. */
@media (pointer: coarse) {
  .btn,
  .dropdown-item,
  .page-link,
  .nav-link,
  .form-check-input {
    min-height: 42px;
  }

  /* Small icon/action buttons (e.g. in tables) */
  .btn-sm {
    min-height: 38px;
    min-width: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Give space between stacked action buttons so fingers
     don't hit the wrong one */
  .sims-table td .d-flex.gap-1 { gap: .4rem !important; }

  /* Checkboxes & switches a touch larger */
  .form-check-input { width: 1.25em; height: 1.25em; }

  /* Larger tap area for top-bar icon buttons */
  .top-navbar .btn-link { padding: .5rem .6rem; }
}

/* ── 2. Respect reduced-motion preference ─────────────────
   Users who request reduced motion (OS setting) get
   animations/transitions effectively disabled. Helps
   accessibility (vestibular issues) and saves battery. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  /* Stop the login background icons bouncing */
  .floating-icons i { animation: none !important; }
}

/* ============================================================
   STACKED-CARD TABLES (B) — phones only
   Tables tagged `.table-stack` turn each row into a card with
   label:value pairs. Cell labels are injected by JS from the
   column headers. Below 768px only.
   ============================================================ */
@media (max-width: 767.98px) {

  .table-stack { border: none; }

  /* Drop the scroll-wrapper border/frame around stacked cards */
  .table-responsive:has(.table-stack) {
    border: none !important;
    overflow: visible;
  }

  /* Hide the header row — labels move into each cell */
  .table-stack thead { display: none; }

  /* Each row becomes a card */
  .table-stack,
  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
    width: 100%;
  }

  .table-stack tr {
    margin-bottom: .85rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--border-radius);
    padding: .35rem .9rem;
    background: var(--bs-body-bg);
    box-shadow: var(--card-shadow);
  }
  .table-stack tbody tr:hover { background: var(--bs-body-bg); }

  /* Each cell: label on the left, value on the right */
  .table-stack td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .55rem 0;
    border: none;
    border-bottom: 1px solid var(--bs-border-color);
    text-align: right;
    font-size: 13px;
    min-height: 0;
  }
  .table-stack td:last-child { border-bottom: none; }

  /* The injected label */
  .table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 10px;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    text-align: left;
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Reveal columns that are hidden in the scroll-table view —
     in card view there's room to show everything */
  .table-stack .hide-mobile { display: flex !important; }

  /* Actions row: buttons aligned right, full width, no label */
  .table-stack td.td-actions {
    justify-content: flex-end;
    padding-top: .7rem;
  }
  .table-stack td.td-actions::before { display: none; }
  .table-stack td.td-actions .d-flex { width: 100%; justify-content: flex-end; }

  /* Empty-state rows shouldn't look like a card grid */
  .table-stack td[colspan] {
    text-align: center;
    border: none;
  }
  .table-stack td[colspan]::before { display: none; }

  /* Let the primary cell (first one, usually name) read bigger */
  .table-stack td:first-child { font-size: 14px; }

  /* Hide the meaningless row-number cell inside cards */
  .table-stack td[data-label="#"] { display: none !important; }
}
