/*
 * NPCP theme - layered on top of Bootstrap 5.3's dark mode.
 *
 * Bootstrap supplies the grid, components, and reset. Everything here is a
 * deliberate override: the dark green surface palette, a denser data-table
 * rhythm, and the sidebar shell. This previously lived inline in the page
 * header, which meant it was re-sent on every request and could not be cached.
 */

:root {
  /*
   * Dark green. The surfaces are near-black with a green cast rather than a
   * saturated green: a corrections officer reads dense tables here for hours,
   * and a strongly coloured background would fight the data. Saturation is
   * spent on the accent and on status badges, where it carries meaning.
   */
  --npcp-bg: #08120d;
  --npcp-surface: #0e1b15;
  --npcp-surface-raised: #15271e;
  --npcp-border: rgba(134, 199, 163, 0.14);
  --npcp-border-strong: rgba(134, 199, 163, 0.26);

  --npcp-text: #e4f0e8;
  --npcp-text-muted: #8fab9c;
  --npcp-text-faint: #6b8878;

  --npcp-accent: #2f9e5e;
  --npcp-accent-strong: #38b76d;
  --npcp-accent-soft: rgba(47, 158, 94, 0.15);
  --npcp-accent-text: #6fd39b;

  /*
   * The gold from the Somali Correctional Services emblem. Reserved for the
   * brand lockup only: promoting it to the interactive accent would put it in
   * direct competition with the amber "warning" badges, where the colour
   * carries meaning.
   */
  --npcp-gold: #f5c542;
  --npcp-gold-soft: rgba(245, 197, 66, 0.13);

  --npcp-sidebar-width: 240px;
  --npcp-topbar-height: 56px;
  --npcp-radius: 10px;

  /* Bootstrap variable overrides. */
  --bs-body-bg: var(--npcp-bg);
  --bs-body-color: var(--npcp-text);
  --bs-border-color: var(--npcp-border);
  --bs-secondary-color: var(--npcp-text-muted);
  --bs-link-color-rgb: 111, 211, 155;
  --bs-link-hover-color-rgb: 154, 231, 187;
  --bs-primary: var(--npcp-accent);
  --bs-primary-rgb: 47, 158, 94;
  --bs-focus-ring-color: var(--npcp-accent-soft);
}

body {
  background: var(--npcp-bg);
  color: var(--npcp-text);
  font-size: 0.9375rem;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout shell ------------------------------------------------------- */

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--npcp-sidebar-width);
  background: var(--npcp-surface);
  border-right: 1px solid var(--npcp-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.25s ease;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--npcp-border);
  color: var(--npcp-text);
  text-decoration: none;
}

.app-brand:hover { color: var(--npcp-text); }

/*
 * The emblem carries its own green field, so it is rendered as a tile rather
 * than floated on the sidebar: a hairline separates its green from the
 * slightly different sidebar green, which would otherwise blur the wreath edge.
 */
.app-brand__logo {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--npcp-border);
  object-fit: cover;
}

/* Shown when no emblem file has been supplied. */
.app-brand__mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--npcp-gold-soft);
  color: var(--npcp-gold);
  font-size: 1.15rem;
  flex-shrink: 0;
}

.app-brand__name {
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.app-brand__tagline {
  font-size: 0.7rem;
  color: var(--npcp-text-faint);
  line-height: 1.15;
}

.app-nav {
  padding: 0.75rem 0.6rem;
  overflow-y: auto;
  flex: 1;
}

.app-nav__section {
  padding: 0.9rem 0.65rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--npcp-text-faint);
}

.app-nav__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.1rem;
  border-radius: 7px;
  color: var(--npcp-text-muted);
  font-size: 0.875rem;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-nav__link i { width: 1.1rem; font-size: 1rem; text-align: center; }

.app-nav__link:hover {
  background: rgba(134, 199, 163, 0.08);
  color: var(--npcp-text);
}

/* The left rail marks the active item without shifting the label. */
.app-nav__link.is-active {
  background: var(--npcp-accent-soft);
  color: var(--npcp-accent-text);
  font-weight: 500;
  box-shadow: inset 2px 0 0 var(--npcp-accent);
}

.app-sidebar__footer {
  border-top: 1px solid var(--npcp-border);
  padding: 0.75rem;
}

/* --- Language switch ----------------------------------------------------- */

.lang-switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin-bottom: 0.6rem;
  border: 1px solid var(--npcp-border);
  border-radius: 7px;
  background: var(--npcp-bg);
}

.lang-switch__option {
  flex: 1;
  text-align: center;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--npcp-text-muted);
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.lang-switch__option:hover { color: var(--npcp-text); }

.lang-switch__option.is-active {
  background: var(--npcp-accent-soft);
  color: var(--npcp-accent-text);
}

/* On the sign-in card the switch sits inline under the form. */
.lang-switch--auth {
  max-width: 220px;
  margin-inline: auto;
  margin-bottom: 0;
}

.app-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.4rem 0.6rem;
}

.app-user__avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--npcp-surface-raised);
  border: 1px solid var(--npcp-border-strong);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--npcp-accent-text);
  flex-shrink: 0;
}

.app-user__name {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user__role {
  font-size: 0.7rem;
  color: var(--npcp-text-faint);
  line-height: 1.2;
}

.app-main {
  margin-left: var(--npcp-sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  height: var(--npcp-topbar-height);
  padding: 0 1rem;
  background: var(--npcp-surface);
  border-bottom: 1px solid var(--npcp-border);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.app-content {
  padding: 1.75rem 2rem 3rem;
  flex: 1;
  width: 100%;
  max-width: 1600px;
}

/* --- Page header -------------------------------------------------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header__title {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.page-header__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--npcp-text-muted);
}

.page-header__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--npcp-surface);
  border: 1px solid var(--npcp-border);
  border-radius: var(--npcp-radius);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--npcp-border);
  padding: 0.85rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-header h2,
.card-header h6 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.card-body { padding: 1.15rem; }

/* --- Statistic tiles ---------------------------------------------------- */

.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem;
  height: 100%;
}

.stat-card__value {
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-card__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--npcp-text-faint);
  margin-bottom: 0.45rem;
}

.stat-card__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-card__icon--primary { background: var(--npcp-accent-soft);      color: var(--npcp-accent-text); }
.stat-card__icon--success { background: rgba(34, 197, 94, 0.14);      color: #4ade80; }
.stat-card__icon--info    { background: rgba(20, 184, 166, 0.14);     color: #2dd4bf; }
.stat-card__icon--warning { background: rgba(217, 160, 30, 0.16);     color: #e3b341; }
.stat-card__icon--danger  { background: rgba(239, 68, 68, 0.14);      color: #f87171; }

/* --- Tables ------------------------------------------------------------- */

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--npcp-text);
  --bs-table-border-color: var(--npcp-border);
  --bs-table-hover-bg: rgba(134, 199, 163, 0.06);
  --bs-table-hover-color: var(--npcp-text);
  margin-bottom: 0;
  font-size: 0.85rem;
}

.table > thead > tr > th {
  background: rgba(134, 199, 163, 0.05);
  border-bottom: 1px solid var(--npcp-border);
  color: var(--npcp-text-faint);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.65rem 0.9rem;
  white-space: nowrap;
}

.table > tbody > tr > td {
  padding: 0.7rem 0.9rem;
  vertical-align: middle;
  border-bottom: 1px solid rgba(134, 199, 163, 0.07);
}

.table > tbody > tr:last-child > td { border-bottom: 0; }

.table-numeric { font-variant-numeric: tabular-nums; text-align: right; }

/*
 * Monospace identifiers so numbers of equal length align down the column.
 * Never wrapped: a reference number broken across two lines is unreadable and
 * cannot be copied cleanly. Narrow screens scroll the table instead.
 */
.identifier {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--npcp-text-muted);
  white-space: nowrap;
}

.table-card .card-body { padding: 0; }
.table-card .table-responsive { border-radius: 0 0 var(--npcp-radius) var(--npcp-radius); }

/* --- Badges ------------------------------------------------------------- */

/*
 * Tinted rather than solid: a table row can carry three or four of these at
 * once, and saturated blocks at that density fight the data for attention.
 */
.badge-soft {
  display: inline-block;
  padding: 0.24rem 0.55rem;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.35;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-soft--primary   { background: var(--npcp-accent-soft);     color: var(--npcp-accent-text); border-color: rgba(47, 158, 94, 0.32); }
.badge-soft--success   { background: rgba(34, 197, 94, 0.14);     color: #5fd68b; border-color: rgba(34, 197, 94, 0.3); }
.badge-soft--warning   { background: rgba(217, 160, 30, 0.16);    color: #e3b341; border-color: rgba(217, 160, 30, 0.34); }
.badge-soft--danger    { background: rgba(239, 68, 68, 0.14);     color: #f5817f; border-color: rgba(239, 68, 68, 0.32); }
.badge-soft--info      { background: rgba(20, 184, 166, 0.14);    color: #3fcbdf; border-color: rgba(20, 184, 166, 0.32); }
.badge-soft--secondary { background: rgba(134, 199, 163, 0.12);   color: #9db3a7; border-color: rgba(134, 199, 163, 0.24); }
.badge-soft--purple    { background: rgba(139, 92, 246, 0.15);    color: #a68bf7; border-color: rgba(139, 92, 246, 0.32); }
.badge-soft--orange    { background: rgba(249, 115, 22, 0.15);    color: #f59356; border-color: rgba(249, 115, 22, 0.32); }
.badge-soft--dark      { background: rgba(8, 18, 13, 0.7);        color: #8fab9c; border-color: rgba(134, 199, 163, 0.2); }

/* --- Forms -------------------------------------------------------------- */

.form-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--npcp-text-muted);
  margin-bottom: 0.3rem;
}

.form-control,
.form-select {
  background: var(--npcp-bg);
  border: 1px solid var(--npcp-border-strong);
  color: var(--npcp-text);
  border-radius: 7px;
  font-size: 0.875rem;
}

.form-control:focus,
.form-select:focus {
  background: var(--npcp-bg);
  border-color: var(--npcp-accent);
  color: var(--npcp-text);
  box-shadow: 0 0 0 3px var(--npcp-accent-soft);
}

.form-control::placeholder { color: var(--npcp-text-faint); }

.form-check-input:checked {
  background-color: var(--npcp-accent);
  border-color: var(--npcp-accent);
}

.form-check-input:focus {
  border-color: var(--npcp-accent);
  box-shadow: 0 0 0 3px var(--npcp-accent-soft);
}

/* Section divider inside long forms. */
.form-section {
  margin: 1.75rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--npcp-border);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--npcp-accent-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-section:first-of-type { margin-top: 0; }

.filter-bar {
  background: var(--npcp-surface);
  border: 1px solid var(--npcp-border);
  border-radius: var(--npcp-radius);
  padding: 0.85rem;
  margin-bottom: 1.15rem;
}

/* --- Buttons ------------------------------------------------------------ */

.btn { border-radius: 7px; font-size: 0.85rem; font-weight: 500; }
.btn-sm { font-size: 0.8rem; }

/*
 * Bootstrap 5.3 resolves button colours through per-component --bs-btn-*
 * variables, so overriding --bs-primary alone would leave these blue.
 */
.btn-primary {
  --bs-btn-bg: var(--npcp-accent);
  --bs-btn-border-color: var(--npcp-accent);
  --bs-btn-hover-bg: var(--npcp-accent-strong);
  --bs-btn-hover-border-color: var(--npcp-accent-strong);
  --bs-btn-active-bg: #278a50;
  --bs-btn-active-border-color: #278a50;
  --bs-btn-disabled-bg: var(--npcp-accent);
  --bs-btn-disabled-border-color: var(--npcp-accent);
  --bs-btn-color: #06180e;
  --bs-btn-hover-color: #06180e;
  --bs-btn-active-color: #06180e;
  --bs-btn-disabled-color: #06180e;
  font-weight: 600;
}

.btn-outline-primary {
  --bs-btn-color: var(--npcp-accent-text);
  --bs-btn-border-color: rgba(47, 158, 94, 0.5);
  --bs-btn-hover-bg: var(--npcp-accent-soft);
  --bs-btn-hover-border-color: var(--npcp-accent);
  --bs-btn-hover-color: var(--npcp-accent-text);
}

.btn-outline-secondary {
  border-color: var(--npcp-border-strong);
  color: var(--npcp-text-muted);
}

.btn-outline-secondary:hover {
  background: rgba(134, 199, 163, 0.1);
  border-color: var(--npcp-border-strong);
  color: var(--npcp-text);
}

.btn:focus-visible { box-shadow: 0 0 0 3px var(--npcp-accent-soft); }

/* --- Progress ----------------------------------------------------------- */

.progress {
  background: rgba(134, 199, 163, 0.12);
  border-radius: 3px;
  height: 6px;
}

.capacity-row { margin-bottom: 0.85rem; }
.capacity-row:last-child { margin-bottom: 0; }

.capacity-row__head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
}

.capacity-row__count {
  color: var(--npcp-text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- Key/value lists on detail pages ------------------------------------ */

.detail-list { display: grid; gap: 0.55rem; }

.detail-list__row {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.75rem;
  font-size: 0.83rem;
  align-items: baseline;
}

.detail-list__label { color: var(--npcp-text-faint); }
.detail-list__value { color: var(--npcp-text); word-break: break-word; }

/* --- Empty states ------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 2.75rem 1.5rem;
  color: var(--npcp-text-muted);
}

.empty-state i {
  font-size: 2rem;
  color: var(--npcp-text-faint);
  display: block;
  margin-bottom: 0.6rem;
}

.empty-state p { margin: 0; font-size: 0.875rem; }

/* --- Profile header on the inmate record -------------------------------- */

.profile-photo {
  width: 116px;
  height: 116px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--npcp-border-strong);
}

.profile-photo--placeholder {
  display: grid;
  place-items: center;
  background: var(--npcp-surface-raised);
  color: var(--npcp-text-faint);
  font-size: 2.5rem;
  margin-inline: auto;
}

.avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  object-fit: cover;
}

.avatar-sm--placeholder {
  display: grid;
  place-items: center;
  background: var(--npcp-surface-raised);
  border: 1px solid var(--npcp-border);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--npcp-text-faint);
}

/* --- Auth screen -------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(47, 158, 94, 0.18), transparent 62%),
    var(--npcp-bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--npcp-surface);
  border: 1px solid var(--npcp-border);
  border-radius: 14px;
  padding: 2rem;
}

.auth-card__logo {
  width: 96px;
  height: 96px;
  margin: 0 auto 1rem;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--npcp-border);
  object-fit: cover;
}

.auth-card__mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 0.9rem;
  border-radius: 14px;
  background: var(--npcp-gold-soft);
  color: var(--npcp-gold);
  font-size: 1.6rem;
}

/* --- Alerts ------------------------------------------------------------- */

.alert { border-radius: 8px; font-size: 0.85rem; border-width: 1px; }

.alert-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f5817f;
}

.alert-success {
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.3);
  color: #5fd68b;
}

.alert-info {
  background: rgba(47, 158, 94, 0.12);
  border-color: rgba(47, 158, 94, 0.32);
  color: var(--npcp-accent-text);
}

.alert code { color: inherit; font-weight: 600; }

/* --- Utilities ---------------------------------------------------------- */

.text-muted-soft { color: var(--npcp-text-muted) !important; }
.text-faint { color: var(--npcp-text-faint) !important; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 9, 6, 0.65);
  z-index: 1035;
  display: none;
}

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.is-open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-topbar { display: flex; }
  .app-content { padding: 1.15rem 1rem 2.5rem; }
  .sidebar-backdrop.is-visible { display: block; }
  .detail-list__row { grid-template-columns: 7rem 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-nav__link { transition: none; }
}

@media print {
  .app-sidebar,
  .app-topbar,
  .page-header__actions,
  .filter-bar { display: none !important; }
  .app-main { margin-left: 0; }
  body { background: #fff; color: #000; }
}
