/* ==========================================================================
   Nyakasura DMIS theme
   Brand red is used for identity and primary actions; text stays dark and
   status colours keep their meaning (green = ok, amber = warning, red = danger).
   ========================================================================== */
:root {
  --brand: #c8102e;
  --brand-rgb: 200, 16, 46;
  --brand-dark: #9e0b23;
  --brand-darker: #7a0819;
  --brand-soft: #fdecef;

  --ink: #1d2330;
  --ink-muted: #5b6472;
  --line: #e6e8ed;
  --surface: #ffffff;
  --canvas: #f4f5f8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
  --sidebar-w: 260px;

  /* Bootstrap hooks: make "primary" the school red */
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
  --bs-link-color: var(--brand);
  --bs-link-color-rgb: var(--brand-rgb);
  --bs-link-hover-color: var(--brand-dark);
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--canvas);
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--ink-muted);
  --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--bs-font-sans-serif);
  font-size: .95rem;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { letter-spacing: -.01em; }
.text-muted { color: var(--ink-muted) !important; }
a { text-decoration-thickness: 1px; text-underline-offset: 2px; }
:focus-visible { outline: 3px solid rgba(var(--brand-rgb), .35); outline-offset: 2px; }

/* ---------- Layout ---------- */
#wrapper { display: flex; min-height: 100vh; }
#page-content-wrapper { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.page-body { padding: 1.75rem; flex: 1; }
@media (max-width: 575.98px) { .page-body { padding: 1rem; } }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 60%, var(--brand-darker) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: margin-left .25s ease;
  z-index: 1040;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .15);
}
.sidebar-brand img {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255, 255, 255, .9); background: #fff;
}
.sidebar-brand strong { display: block; font-size: 1.05rem; line-height: 1.2; }
.sidebar-brand small { display: block; opacity: .8; font-size: .75rem; }

.sidebar-nav { padding: .75rem; flex: 1; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: .75rem;
  color: rgba(255, 255, 255, .88);
  padding: .6rem .8rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: .92rem;
  text-decoration: none;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.sidebar .nav-link i { opacity: .9; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.sidebar .nav-link.active { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }
.sidebar .nav-link.active i { opacity: 1; }
.sidebar-label {
  margin: 1.25rem .8rem .4rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: rgba(255, 255, 255, .6);
}
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255, 255, 255, .15); }
.sidebar-motto { font-style: italic; font-size: .75rem; opacity: .75; margin: .25rem .8rem .5rem; }

.sidebar-backdrop { display: none; }

/* Desktop: toggle collapses the sidebar */
#wrapper.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

/* Tablet/phone: sidebar slides over the content */
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; margin-left: calc(-1 * var(--sidebar-w)); box-shadow: var(--shadow-md); }
  #wrapper.sidebar-open .sidebar { margin-left: 0; }
  #wrapper.sidebar-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(15, 18, 25, .45); z-index: 1030;
  }
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: .75rem;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  padding: .65rem 1.75rem;
  min-height: 64px;
}
.topbar-title { font-weight: 600; font-size: 1.05rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.btn-icon {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-muted); background: transparent; border: 0;
}
.btn-icon:hover { background: var(--canvas); color: var(--ink); }
.notif-dot {
  position: absolute; top: 4px; right: 2px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: .68rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}
.user-chip {
  display: flex; align-items: center; gap: .6rem;
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  padding: .25rem .6rem .25rem .25rem; color: var(--ink-muted);
}
.user-chip:hover, .user-chip[aria-expanded="true"] { background: var(--canvas); border-color: var(--line); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem;
}
.user-meta { display: flex; flex-direction: column; text-align: left; line-height: 1.15; }
.user-meta strong { color: var(--ink); font-size: .88rem; }
.user-meta small { font-size: .74rem; }
@media (max-width: 575.98px) {
  .topbar { padding: .5rem 1rem; }
  .user-meta, .user-chip .fa-chevron-down { display: none; }
}

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card.border-0 { border: 1px solid var(--line) !important; }
.card-header { background: var(--surface); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-header:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card-footer { background: var(--surface); border-top: 1px solid var(--line); }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }

/* ---------- Buttons ---------- */
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-darker); --bs-btn-active-border-color: var(--brand-darker);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-focus-shadow-rgb: var(--brand-rgb);
}
.btn-danger {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-darker); --bs-btn-active-border-color: var(--brand-darker);
}
.btn-outline-primary, .btn-outline-danger {
  --bs-btn-color: var(--brand); --bs-btn-border-color: rgba(var(--brand-rgb), .45);
  --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark);
}
.btn-outline-secondary { --bs-btn-color: var(--ink-muted); --bs-btn-border-color: var(--line); --bs-btn-hover-bg: var(--canvas); --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: #cfd3da; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; color: var(--ink); }
.form-control, .form-select { border-color: #d6dae1; border-radius: var(--radius-sm); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.input-group-text { background: var(--canvas); border-color: #d6dae1; color: var(--ink-muted); }

/* ---------- Tables ---------- */
.table { --bs-table-color: var(--ink); --bs-table-hover-bg: #fafbfc; margin-bottom: 0; }
.table > thead th, .table-light th {
  background: #f8f9fb !important;
  color: var(--ink-muted) !important;
  font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 1px solid var(--line) !important;
  white-space: nowrap;
}
.table td { border-color: var(--line); vertical-align: middle; }
.table td:first-child { white-space: nowrap; }

/* DataTables */
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid #d6dae1; border-radius: var(--radius-sm); padding: .4rem .75rem; margin-left: 0; min-width: 220px;
}
.dataTables_wrapper .dataTables_length select { border-radius: var(--radius-sm); }
.dataTables_wrapper .dataTables_info { color: var(--ink-muted); font-size: .85rem; }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }
.page-link { color: var(--brand); }

/* ---------- Badges & status ---------- */
.badge { font-weight: 600; border-radius: 6px; padding: .38em .6em; }
.badge-soft { background: var(--canvas); color: var(--ink-muted); border: 1px solid var(--line); }
.bg-orange { background-color: #e8590c !important; color: #fff !important; }
.badge-minor    { background: #fff4d6; color: #8a5a00; }
.badge-moderate { background: #ffe5cc; color: #a24a00; }
.badge-serious  { background: #fdd8dc; color: var(--brand-dark); }
.badge-critical { background: var(--brand); color: #fff; }

/* Brand helpers used by existing views */
.bg-nyakasura-red { background-color: var(--brand) !important; color: #fff !important; }
.text-nyakasura-red { color: var(--brand) !important; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius-sm); border-width: 1px; }
.alert .btn-close { margin-left: auto; padding: .9rem; }
.alert-dismissible { padding-right: 1rem; }
.alert-dismissible .btn-close { position: static; }

/* ---------- Page headers ---------- */
.back-link { color: var(--ink-muted); text-decoration: none; font-size: .88rem; }
.back-link:hover { color: var(--brand); }

/* ---------- Error page ---------- */
.error-page { max-width: 460px; }
.error-icon {
  width: 72px; height: 72px; margin: 0 auto; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 1.75rem;
}
.error-code { font-weight: 800; letter-spacing: .1em; color: var(--brand); }
body > .error-page { margin-top: 12vh !important; }

/* ---------- Login ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background:
  radial-gradient(1200px 600px at 0% 0%, rgba(var(--brand-rgb), .08), transparent 60%), var(--canvas); }
.auth-shell {
  width: 100%; max-width: 920px; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: 0 20px 50px rgba(16, 24, 40, .12);
}
.auth-brand {
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 70%, var(--brand-darker) 100%);
  color: #fff; padding: 3rem 2.5rem; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
}
.auth-brand h1 { color: #fff; font-size: 1.9rem; font-weight: 700; margin: 1.25rem 0 .25rem; }
.auth-logo { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; background: #fff; }
.auth-system { opacity: .9; margin-bottom: 2rem; }
.auth-motto { font-style: italic; opacity: .85; margin: 0; padding-left: .9rem; border-left: 3px solid rgba(255, 255, 255, .5); }
.auth-form { padding: 3rem 2.5rem; }
.auth-form h2 { font-weight: 700; font-size: 1.6rem; margin-bottom: .25rem; }
.auth-help { margin: 1.5rem 0 0; font-size: .85rem; color: var(--ink-muted); text-align: center; }
@media (max-width: 767.98px) {
  .auth-shell { grid-template-columns: 1fr; max-width: 440px; }
  .auth-brand { padding: 2rem; align-items: center; text-align: center; }
  .auth-brand h1 { font-size: 1.5rem; margin-top: .75rem; }
  .auth-system { margin-bottom: 1rem; }
  .auth-motto { border-left: 0; padding-left: 0; }
  .auth-form { padding: 2rem 1.5rem; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .sidebar-backdrop, .btn, .alert { display: none !important; }
  .page-body { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; }
}

/* ---------- Avatars & profile ---------- */
.avatar { flex-shrink: 0; }
.avatar-img { border-radius: 50%; object-fit: cover; background: var(--canvas); border: 1px solid var(--line); display: inline-block; }
.photo-preview .avatar { box-shadow: var(--shadow-sm); }
.profile-details dt { font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.profile-details dd { margin-bottom: .85rem; word-break: break-word; }
