/* ---------------------------------------------------------------------------
 * CHS Alliance brand palette
 * Sampled from the official logo (https://www.chsalliance.org/):
 *   Magenta  #E61457  — primary (CHS wordmark + ring)   → links, buttons, active
 *   Grey     #9D9D9C  — secondary ("Alliance" + ring)   → muted text, borders
 *   Yellow   #F3C91E  — accent (third ring)             → highlights
 * Neutrals chosen to match (dark grey text, not pure black).
 * ------------------------------------------------------------------------- */
:root {
  --brand-magenta: #E61457;
  --brand-magenta-dark: #BC1047;   /* hover / active */
  --brand-grey: #9D9D9C;
  --brand-yellow: #F3C91E;

  --bg: #ffffff;
  --fg: #333333;
  --muted: #6b6b6b;
  --accent: var(--brand-magenta);
  --border: #e2e2e2;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--brand-magenta); }
a:hover { color: var(--brand-magenta-dark); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header */
.site-header {
  border-bottom: 3px solid var(--brand-magenta);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  padding-bottom: 1rem;
}
.brand { display: inline-flex; align-items: center; }
.brand img { height: 40px; width: auto; display: block; }

.nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.nav a { color: var(--fg); text-decoration: none; }
.nav a:hover { color: var(--brand-magenta); }
.nav-user { color: var(--muted); }

.nav-link-btn {
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.nav-link-btn:hover { color: var(--brand-magenta); }
.logout-form { display: inline; margin: 0; }

.lang-switcher { display: inline-flex; gap: .25rem; margin: 0; }
.lang {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .4rem;
  cursor: pointer;
  font: inherit;
  color: var(--muted);
}
.lang.is-active {
  color: #fff;
  background: var(--brand-magenta);
  border-color: var(--brand-magenta);
}

/* Buttons */
.btn {
  display: inline-block;
  background: var(--brand-magenta);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: .5rem 1.1rem;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--brand-magenta-dark); color: #fff; }

/* Flash messages */
.flash {
  padding: .75rem 1rem;
  border-radius: 6px;
  margin: 1rem 0;
  border: 1px solid var(--border);
}
.flash-success { border-color: #7ac07a; background: #eefaee; }
.flash-error   { border-color: #d88; background: #fdeeee; }
.flash-info    { border-color: var(--brand-yellow); background: #fdf7e0; }

/* Import / preview page */
.import-page { padding: 2rem 0; }
.import-page h1 { margin: 0 0 .25rem; }
.import-page .lead { color: var(--muted); margin: 0 0 1.5rem; }

.upload-form { margin-bottom: 2rem; }
.upload-form .field { margin-bottom: 1rem; }
.upload-form label { display: block; font-weight: 600; margin-bottom: .35rem; }
.upload-form .help { display: block; color: var(--muted); margin-top: .35rem; }

.preview-meta { margin-bottom: .75rem; color: var(--fg); }
.preview-meta .muted { color: var(--muted); }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; }
.preview-table { border-collapse: collapse; width: 100%; font-size: .9rem; white-space: nowrap; }
.preview-table th, .preview-table td {
  padding: .4rem .7rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
}
.preview-table thead th {
  position: sticky;
  top: 0;
  background: var(--brand-magenta);
  color: #fff;
  font-weight: 600;
}
.preview-table tbody tr:nth-child(even) { background: #faf7f8; }
.preview-table .rownum { color: var(--muted); background: #f4f4f4; text-align: right; }
.preview-table thead .rownum { color: #fff; background: var(--brand-magenta-dark); }
.muted { color: var(--muted); }

/* Auth / login */
.auth-page { max-width: 380px; padding: 2.5rem 0; }
.auth-page h1 { margin: 0 0 1.25rem; }
.auth-form .field { margin-bottom: 1rem; }
.auth-form label { display: block; font-weight: 600; margin-bottom: .35rem; }
.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}
.auth-form input:focus { outline: 2px solid var(--brand-magenta); border-color: var(--brand-magenta); }

.btn-lg { padding: .6rem 1.4rem; font-size: 1.05rem; }
.btn-outline {
  display: inline-block;
  background: #fff;
  color: var(--brand-magenta);
  border: 1px solid var(--brand-magenta);
  border-radius: 4px;
  padding: .45rem 1rem;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}
.btn-outline:hover { background: var(--brand-magenta); color: #fff; }

.generate {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.generate form { margin: 0; }
/* Let the export buttons sit inline with the other toolbar controls. */
.report-actions .export-form { display: contents; }

/* --- MNC report ---------------------------------------------------------- */
.report-page { padding: 1.5rem 0 3rem; }

/* Overview / summary table (kept compact to save vertical space) */
.summary { margin-bottom: 1.5rem; }
.summary-title { margin: 0 0 .5rem; font-size: 1rem; }
.summary-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.summary-table th, .summary-table td {
  padding: .28rem .55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.summary-table thead th {
  background: #faf7f8;
  color: var(--muted);
  text-transform: uppercase;
  font-size: .66rem;
  letter-spacing: .03em;
  border-bottom: 2px solid var(--border);
}
.summary-row { cursor: pointer; }
.summary-table tbody tr:hover { background: #fdeef3; }
.summary-table .col-num { width: 1.6rem; text-align: right; color: var(--muted); }
.summary-table .muted { font-weight: 400; }
.summary-table .org-link { color: var(--fg); text-decoration: none; font-weight: 600; }
.summary-row:hover .org-link { color: var(--brand-magenta); }
.dd-cell { text-align: center; font-weight: 700; font-size: .7rem; white-space: nowrap; }
.dd-green { background: #1f9d55; color: #fff; }
.dd-amber { background: #e0a800; color: #3a2f00; }
.dd-red   { background: #c0392b; color: #fff; }
.dd-none  { background: #ececec; color: #888; }
.report-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.report-toolbar h1 { margin: 0 0 .2rem; }
.report-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.org-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
  break-inside: avoid;
  scroll-margin-top: 1rem;
}
/* RAG status banner (from column 1 "Comment for MNC") */
.org-banner {
  display: flex;
  gap: .6rem;
  align-items: baseline;
  flex-wrap: wrap;
  padding: .55rem 1.1rem;
  font-size: .88rem;
  border-top: 4px solid transparent;
}
.rag-chip {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .72rem;
  padding: .12rem .55rem;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.rag-text { color: var(--fg); }

.rag-green { background: #e6f4ea; border-top-color: #1f9d55; }
.rag-green .rag-chip { background: #1f9d55; }
.rag-amber { background: #fdf3d3; border-top-color: #e0a800; }
.rag-amber .rag-chip { background: #e0a800; color: #3a2f00; }
.rag-red   { background: #fde5e3; border-top-color: #c0392b; }
.rag-red   .rag-chip { background: #c0392b; }
.rag-none  { background: #f2f2f2; border-top-color: #bbb; }
.rag-none  .rag-chip { background: #999; }

.org-head {
  background: var(--brand-magenta);
  color: #fff;
  padding: .8rem 1.1rem;
}
.org-head h2 { margin: 0; font-size: 1.2rem; }
.org-head .acronym {
  font-size: .8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, .22);
  padding: .1rem .45rem;
  border-radius: 4px;
  vertical-align: middle;
}
.org-meta {
  margin-top: .35rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .3rem 0;
  font-size: .85rem;
  opacity: .95;
}
/* " | " separator between metadata values (country, type, income, ...). */
.org-meta > span + span::before {
  content: "|";
  margin: 0 .5rem;
  color: rgba(255, 255, 255, .55);
}
.org-meta .tag {
  background: var(--brand-yellow);
  color: #333;
  font-weight: 600;
  padding: .05rem .45rem;
  border-radius: 4px;
}
.org-meta .muted { color: rgba(255, 255, 255, .8); }

.org-body { padding: 1.1rem; display: grid; gap: 1.25rem; }
.org-section h3 {
  margin: 0 0 .6rem;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--brand-magenta);
  border-bottom: 2px solid var(--border);
  padding-bottom: .3rem;
}

/* Key/value lists (profile + referee narratives) */
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .25rem .9rem;
  margin: 0;
}
.kv dt { font-weight: 600; color: var(--muted); }
.kv dt::after { content: ":"; }
.kv dd { margin: 0; }

/* Referee assessment: the cards are too narrow for two columns, so stack
   each entry — label then ":" on its own line, value underneath. */
.referee .kv { display: block; }
.referee .kv dt { margin-top: .55rem; }
.referee .kv > dt:first-child { margin-top: 0; }
.referee .kv dd { margin: .15rem 0 0; overflow-wrap: anywhere; }

/* Screening grid: compact labelled cells */
.screening-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .5rem .9rem;
}
.screening-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  padding: .3rem .5rem;
  background: #faf7f8;
  border-radius: 4px;
}
.s-label { color: var(--muted); font-size: .85rem; }
.s-label::after { content: ":"; }
.s-value { font-weight: 600; text-align: right; }

.badge {
  font-size: .78rem;
  font-weight: 700;
  padding: .1rem .5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-yes { background: #e3f4e3; color: #1f7a1f; }
.badge-no  { background: #fde3e3; color: #b21f1f; }
.badge-na  { background: #eee; color: #666; }

/* Referees: up to three compact mini-cards */
.referee-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .9rem;
}
.referee {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .7rem .8rem;
}
.ref-head {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--brand-magenta);
  font-weight: 700;
  margin-bottom: .3rem;
}
.ref-name { font-weight: 600; }
.ref-email { font-size: .85rem; margin-top: .15rem; }

/* Collapsible long text */
details.narrative {
  margin-top: .6rem;
  border-left: 3px solid var(--brand-yellow);
  padding-left: .7rem;
}
details.narrative summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg);
}
details.narrative[open] summary { margin-bottom: .4rem; }
details.narrative p { margin: 0; }
details.narrative .kv { margin-top: .3rem; }

@media print {
  .site-header, .report-toolbar { display: none; }
  .report-page { padding: 0; }
  .org-card { border-color: #999; }
  .org-head, .org-banner, .rag-chip, .badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Landing */
.hero { padding: 4rem 0; text-align: center; }
.hero h1 { font-size: 2rem; margin: 0 0 .5rem; color: var(--fg); }
.hero h1 span { color: var(--brand-magenta); }
.hero p { color: var(--muted); margin: 0; }
