:root {
  --navy: #3e70b6;
  --navy-dark: #16294B;
  --gold: #fcb543;
  --green: #f35821;
  --bg: #F4F6F9;
}

body {
  background: var(--bg);
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
}

/* ---------- Layout ---------- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand i { color: var(--gold); font-size: 1.4rem; }

.sidebar-nav { padding: 10px 0; }

.sidebar-nav .nav-link {
  color: rgba(255,255,255,0.85);
  padding: 10px 22px;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

.sidebar-nav .nav-link i { width: 20px; margin-right: 8px; }

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: rgba(255,255,255,0.12);
  border-left-color: var(--gold);
  color: #fff;
  font-weight: 600;
}

.sidebar-section {
  padding: 14px 22px 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.45);
}

/* ---------- Collapsible sidebar sections ---------- */
.sidebar-group { margin-top: 2px; }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px 12px 22px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.sidebar-section-toggle:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.sidebar-section-toggle .toggle-caret {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-left: 8px;
}

.sidebar-section-toggle[aria-expanded="true"] .toggle-caret {
  transform: rotate(180deg);
}

.sidebar-submenu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-submenu.collapsing {
  transition: height 0.2s ease;
}

.main-content { flex: 1; min-width: 0; }

.topbar {
  background: #fff;
  padding: 14px 24px;
  border-bottom: 1px solid #E3E6EC;
}

/* ---------- KPI cards ---------- */
.kpi-card {
  border: none;
  border-radius: 12px;
  color: #fff;
  padding: 20px;
}

.kpi-card .kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.kpi-card .kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 6px;
}

.kpi-navy { background: #3e70b6; }
.kpi-green { background: #fcb543; }
.kpi-gold { background: #f35821; }
.kpi-red { background: #384447; }
.kpi-teal { background: #1a936f; }
.kpi-purple { background: #6b4ea3; }
.kpi-cyan { background: #2596be; }
.kpi-emerald { background: #198754; }

/* ---------- Cards / tables ---------- */
.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #EEF0F4;
  font-weight: 600;
  color: var(--navy);
}

.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6B7280;
  border-bottom-width: 1px;
}

.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
}
.btn-primary:hover {
  background: var(--navy-dark);
  border-color: var(--navy-dark);
}

.btn-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
}
.btn-gold:hover { color: #fff; opacity: 0.9; }

/* ---------- Activity Log ---------- */
.activity-log-filters .form-label {
  color: #6B7280;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.activity-log-filters .form-select,
.activity-log-filters .form-control {
  border-color: #E5E7EB;
}

/* Defensive, self-contained table rules — don't rely solely on Bootstrap's
   .table cascade for basic readability (borders/padding/wrapping), since
   this table carries long, underscore-heavy values (module/action names,
   descriptions) that can blow out column widths and overflow the page
   if nothing constrains them. */
.activity-log-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
}

.activity-log-table th,
.activity-log-table td {
  display: table-cell;
  padding: 10px 12px;
  border-bottom: 1px solid #EEF0F4;
  vertical-align: middle;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.activity-log-table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.activity-log-table tbody tr {
  border-left: 3px solid transparent;
  transition: background-color 0.12s ease;
}

.activity-log-table tbody tr:hover {
  background: #F8FAFC;
}

/* Fixed column widths so no single value (e.g. a long action or module
   name) can stretch the table wider than its container. */
.activity-log-table th:nth-child(1), .activity-log-table td:nth-child(1) { width: 13%; }
.activity-log-table th:nth-child(2), .activity-log-table td:nth-child(2) { width: 13%; }
.activity-log-table th:nth-child(3), .activity-log-table td:nth-child(3) { width: 11%; }
.activity-log-table th:nth-child(4), .activity-log-table td:nth-child(4) { width: 12%; }
.activity-log-table th:nth-child(5), .activity-log-table td:nth-child(5) { width: 36%; }
.activity-log-table th:nth-child(6), .activity-log-table td:nth-child(6) { width: 8%; }
.activity-log-table th:nth-child(7), .activity-log-table td:nth-child(7) { width: 7%; }

.activity-log-table .log-when {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  color: #6B7280;
}

.activity-log-table .log-desc {
  line-height: 1.4;
}

.activity-log-table .log-ip {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

/* Colored left rail per action, so the eye can scan a long log fast */
.activity-log-table tr.log-create  { border-left-color: #22C55E; }
.activity-log-table tr.log-update  { border-left-color: var(--navy); }
.activity-log-table tr.log-delete  { border-left-color: #EF4444; }
.activity-log-table tr.log-approve { border-left-color: #22C55E; }
.activity-log-table tr.log-reject  { border-left-color: #EF4444; }
.activity-log-table tr.log-pay     { border-left-color: var(--gold); }
.activity-log-table tr.log-assign  { border-left-color: #0EA5E9; }
.activity-log-table tr.log-return  { border-left-color: #9CA3AF; }
.activity-log-table tr.log-login,
.activity-log-table tr.log-logout  { border-left-color: #9CA3AF; }
.activity-log-table tr.log-login_failed { border-left-color: #EF4444; }
.activity-log-table tr.log-password_reset,
.activity-log-table tr.log-password_reset_requested { border-left-color: #A855F7; }

.activity-log-changes .text-danger-emphasis { text-decoration: line-through; }

/* Small screens: drop the fixed layout so the horizontal scroll from
   .table-responsive takes over instead of squeezing every column unreadably. */
@media (max-width: 767px) {
  .activity-log-table { table-layout: auto; min-width: 900px; }
}

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
}

.login-card {
  width: 100%;
  max-width: 380px;
  border-radius: 14px;
  padding: 10px;
}

@media (max-width: 991px) {
  .sidebar { position: fixed; left: -260px; z-index: 1050; transition: left 0.2s; height: 100%; }
  .sidebar.show { left: 0; }
}

/* ------------------------------------------------------------
   Print helper: wrap whatever should print in <div class="print-area">
   and call window.print(). Everything else on the page is hidden.
   Add class "no-print" to anything (inside or outside print-area)
   that should never show up in the printout, e.g. action buttons.

   Every printout is placed on the Tabasamu Foundation letterhead:
   the header strip (includes/header.php) prints directly above the
   page content, in normal document flow. Non-print chrome
   (sidebar, topbar) is removed from the layout entirely so nothing
   pushes the letterhead out of place or creates blank pages.
------------------------------------------------------------- */
.print-letterhead-header {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body { margin: 0; }

  .sidebar, .topbar,
  .no-print, .no-print * {
    display: none !important;
  }

  .app-wrapper { display: block !important; min-height: 0 !important; }
  .main-content { flex: none !important; }
  main { padding: 0 !important; }

  .print-letterhead-header {
    display: block !important;
    width: 100%;
    margin-bottom: 6mm;
  }
  .print-letterhead-header img {
    display: block;
    width: 100%;
  }

  .print-area {
    width: 100%;
    margin: 0;
    padding: 0;
  }
}
