/* =====================================================================
   Nia MEAL — design system
   Identity matched to Nia Finance (finance.nia-african.org) so staff moving
   between the two systems never meet a different chrome.

   Navy is the identity colour: header, nav, headings, primary buttons,
   progress fills. Green / amber / coral / blue carry status meaning only —
   they are never decorative.

   Direction-sensitive rules use logical properties (start/end, inline-start)
   so the Arabic RTL toggle needs no separate stylesheet.
   ===================================================================== */

:root {
  --brand:        #0B3E6D;
  --brand-light:  #E7EDF3;
  --gray:         #B4B4C1;
  --green:        #0B3E6D;
  --green-light:  #E7EDF3;
  --success:      #2E7D4F;
  --success-light:#E5F2EA;
  --amber:        #BA7517;
  --amber-light:  #FAEEDA;
  --coral:        #993C1D;
  --coral-light:  #FAECE7;
  --blue:         #607997;
  --blue-light:   #E7EDF3;
  --ink:          #333333;
  --border:       #D8DBDF;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
  background: #FAFAF8;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

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

header {
  background: var(--green);
  color: #fff;
  padding: .8rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
header .brand {
  font-weight: bold; font-size: 16px; display: flex; align-items: center; gap: .55rem;
  color: #fff; text-decoration: none;
}
header .brand:hover { opacity: .9; }

/* The logomark variant is already white; height drives the size so the
   artwork can never be stretched out of proportion. 32px is the tallest the
   mark can be without changing the header's existing height. */
header .brand-logo { height: 32px; width: auto; display: block; }

@media (max-width: 600px) {
  header .brand-logo { height: 28px; }
}

nav { display: flex; gap: .3rem; flex-wrap: wrap; margin-inline-start: auto; margin-inline-end: auto; }
nav a {
  color: #fff; text-decoration: none; opacity: .75; font-size: 13px;
  padding: 5.6px 12.8px; border-radius: 6px; cursor: pointer;
}
nav a.active { opacity: 1; font-weight: bold; background: rgba(255,255,255,0.18); }
nav a:hover { opacity: 1; }

.header-right { display: flex; align-items: center; gap: .8rem; font-size: 13px; }
.header-right .user-name { opacity: .85; font-size: 12px; }
.lang-toggle { display: flex; gap: .3rem; cursor: pointer; opacity: .9; user-select: none; }
.lang-toggle span { padding: 2px 4px; }
.lang-toggle span.active { font-weight: bold; text-decoration: underline; }
.role-badge { background: rgba(255,255,255,.15); padding: 3px 10px; border-radius: 20px; font-size: 11px; }
.signout {
  background: var(--coral); color: #fff; border: none; padding: .35rem .9rem;
  border-radius: 7px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.inline-form { display: inline; margin: 0; }

/* ---------- layout ---------- */

main { max-width: 1200px; margin: 1.5rem auto; padding: 0 1rem; }

h1 { font-size: 20px; color: var(--green); font-weight: 700; margin: 0 0 .3rem; }
h1 .sub { display: block; font-size: 13px; color: #777; font-weight: 400; margin-top: .2rem; }
h2 { font-size: 16px; color: var(--green); margin: 0 0 .8rem; }
h3 { font-size: 14px; color: var(--green); margin: 0 0 .6rem; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 1.2rem; flex-wrap: wrap; gap: .6rem;
}
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.grid3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1.2rem; }
.grid4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1.2rem; }
@media (max-width: 900px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr; } }

.card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 1.2rem 1.4rem; margin-bottom: 1.2rem;
}
.card.kpi { text-align: center; padding: 1rem; }
.card.kpi .num { font-size: 30px; font-weight: 700; color: var(--green); }
.card.kpi .label { font-size: 12px; color: #777; margin-top: .2rem; }
.card.kpi .delta { font-size: 11px; margin-top: .3rem; }
.card.kpi .delta.up { color: var(--success); }
.card.kpi .delta.down { color: var(--coral); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--green); color: #fff; padding: 7px 10px; text-align: start; font-weight: 600; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:nth-child(even) td { background: #F8F9F8; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
tr.superseded td { opacity: .55; text-decoration: line-through; }

.indicator-name { font-weight: 600; }
.indicator-meta { font-size: 11px; color: #888; margin-top: 2px; }

/* ---------- badges (status meaning only) ---------- */

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge.on-track,
.badge.approved, .badge.active, .badge.completed,
.badge.verified, .badge.resolved, .badge.accepted,
.badge.published                          { background: var(--success-light); color: var(--success); }
.badge.at-risk,
.badge.pending, .badge.in-preparation,
.badge.in-progress, .badge.submitted,
.badge.new, .badge.under-review,
.badge.open, .badge.deferred              { background: var(--amber-light); color: var(--amber); }
.badge.off-track,
.badge.overdue, .badge.rejected,
.badge.suspended, .badge.sensitive        { background: var(--coral-light); color: var(--coral); }
.badge.not-started,
.badge.closed, .badge.draft, .badge.planned,
.badge.cancelled,
.badge.referred-safeguarding              { background: var(--blue-light); color: var(--blue); }

.badge.sealed { background: var(--brand-light); color: var(--brand); }

/* ---------- buttons ---------- */

.btn {
  display: inline-block; background: var(--green); color: #fff; border: none;
  padding: .45rem 1.1rem; border-radius: 7px; cursor: pointer; text-decoration: none;
  font-size: 13px; font-family: inherit;
}
.btn:hover { opacity: .9; }
.btn.secondary { background: var(--blue); }
.btn.danger { background: var(--coral); }
.btn.small { padding: .25rem .7rem; font-size: 12px; }
.btn[disabled], .btn.disabled { background: var(--gray); cursor: not-allowed; opacity: .7; }

/* ---------- alerts ---------- */

.alert {
  border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: 13px;
  border-inline-start: 4px solid;
}
.alert.success { background: var(--success-light); border-color: var(--success); }
.alert.warning { background: var(--amber-light); border-color: var(--amber); }
.alert.error   { background: var(--coral-light); border-color: var(--coral); }
.alert.info    { background: var(--brand-light); border-color: var(--brand); }

/* ---------- progress ---------- */

.progress { background: #EEE; border-radius: 20px; height: 10px; overflow: hidden; min-width: 70px; }
.progress > div { height: 100%; background: var(--green); }
.progress > div.high { background: var(--amber); }
.progress > div.full { background: var(--coral); }

/* ---------- forms ---------- */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.2rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

label { display: block; font-size: 12px; color: #555; margin-bottom: .25rem; font-weight: 600; }
label .req { color: var(--coral); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 13px;
  background: #fff; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-light); border-color: var(--brand); }
.field-hint { font-size: 11px; color: #888; margin-top: .25rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.2rem; flex-wrap: wrap; }

.filter-bar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input {
  padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px; background: #fff; width: auto;
}

/* ---------- misc ---------- */

.muted { color: #777; font-size: 12px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.small { height: 200px; }
.footer-note { text-align: center; color: #999; font-size: 11px; margin: 2rem 0 1rem; }

.sector-tag { display: inline-flex; align-items: center; gap: .4rem; font-size: 12px; color: #666; margin-bottom: .3rem; }
.sector-dot { width: 8px; height: 8px; border-radius: 50%; }

.meta-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem 1.2rem; }
.meta-list .k { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: .03em; }
.meta-list .v { font-size: 13px; }

.stack { display: flex; flex-direction: column; gap: .3rem; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.back-link { font-size: 12px; color: var(--blue); text-decoration: none; display: inline-block; margin-bottom: .6rem; }
.back-link:hover { text-decoration: underline; }
details.inline-form-block { margin-top: .8rem; }
details.inline-form-block > summary {
  cursor: pointer; font-size: 12px; color: var(--brand); font-weight: 600; user-select: none;
}
details.inline-form-block > div { margin-top: .8rem; padding-top: .8rem; border-top: 1px solid var(--border); }

/* ---------- login ---------- */

body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { width: 100%; max-width: 380px; padding: 1rem; }
.login-box .card { padding: 1.8rem; }
.login-brand { text-align: center; margin-bottom: 1.4rem; }
/* Constrained by height so the artwork keeps its proportions; max-width keeps
   it inside the 380px card on very narrow screens. */
.login-brand .login-logo {
  height: 64px; width: auto; max-width: 100%; display: block; margin: 0 auto .7rem;
}
.login-brand .mark { font-size: 22px; font-weight: 700; color: var(--brand); }
.login-brand .tag { font-size: 12px; color: #777; margin-top: .3rem; }
.login-box .lang-toggle { justify-content: center; color: var(--blue); margin-bottom: 1rem; }
.login-box .btn { width: 100%; text-align: center; padding: .6rem; }

/* ---------- report letterhead ---------- */

.report-letterhead { text-align: center; margin-bottom: 1rem; }
.report-letterhead .report-logo {
  height: 70px; width: auto; display: block; margin: 0 auto .6rem;
}

/* ---------- print / PDF export ---------- */

@media print {
  header, nav, .page-actions, .filter-bar, .btn, .footer-note, .no-print { display: none !important; }

  /* The letterhead is inside <main>, not the site header, so it survives the
     rule above — but images still need colour printing forced on, or the
     logo drops out of the saved PDF in some browsers. */
  .report-letterhead .report-logo {
    height: 62px;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  body { background: #fff; font-size: 11pt; }
  main { max-width: none; margin: 0; padding: 0; }
  .card { border: 1px solid #bbb; break-inside: avoid; page-break-inside: avoid; margin-bottom: .8rem; }
  th { background: #0B3E6D !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge, .progress > div { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page-break { break-before: page; page-break-before: always; }
}

.print-only { display: none; }
@media print { .print-only { display: block; } }
