/* ============================================================
   Karibu Forum — design system
   Brand: Tanzania green + warm cream, serif display + clean sans
   ============================================================ */

/* Global guard: the `hidden` attribute must always win, even over
   elements whose own rule sets display:grid/flex (login screen, modal
   backdrop, etc.). Without this, hidden overlays stay visible and dim
   the whole page. */
[hidden] { display: none !important; }

:root {
  --green: #0a5f3a;
  --green-700: #084a2d;
  --green-300: #3f9e72;
  --green-50: #e9f3ee;
  --cream: #f5f1e8;
  --cream-deep: #ece4d3;
  --ink: #1a1d1b;
  --muted: #5d6b63;
  --line: #e2e0d8;
  --white: #ffffff;
  --amber: #b4791a;
  --red: #b4453a;
  --blue: #2f6f9e;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20,30,25,.04), 0 8px 24px rgba(20,30,25,.06);
  --shadow-lg: 0 12px 40px rgba(20,30,25,.16);
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--green);
  color: #dceee4;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
  position: relative;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(135deg, #fff, #d8efe2);
  color: var(--green-700);
  font-family: var(--serif); font-weight: 700; font-size: 18px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.brand-name { font-family: var(--serif); font-weight: 600; font-size: 18px; color: #fff; letter-spacing: -.2px; }
.brand-sub { font-size: 11px; color: #9ec9b3; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: 0; cursor: pointer;
  color: #bfe0cf; font-family: var(--sans); font-size: 14px; font-weight: 500;
  padding: 10px 12px; border-radius: 10px; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-ico { font-size: 15px; width: 18px; display: inline-block; text-align: center; opacity: .9; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.api-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #9ec9b3; }
.api-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #f0c000; transition: background .2s; }
.api-status.ok .dot { background: #58d68d; box-shadow: 0 0 0 3px rgba(88,214,141,.2); }
.api-status.down .dot { background: #e8857a; }
.docs-link { color: #9ec9b3; font-size: 12px; text-decoration: none; }
.docs-link:hover { color: #fff; text-decoration: underline; }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 30px; border-bottom: 1px solid var(--line);
  background: rgba(245,241,232,.8); backdrop-filter: blur(6px);
  min-height: 64px;
}
.crumbs { font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--ink); letter-spacing: -.3px; }
.crumbs .crumb-sep { color: var(--muted); font-family: var(--sans); font-weight: 400; margin: 0 8px; }
.crumbs .crumb-link { color: var(--green); cursor: pointer; }
.crumbs .crumb-link:hover { text-decoration: underline; }
.topbar-actions { display: flex; gap: 10px; }

.content { padding: 28px 30px; overflow-y: auto; flex: 1; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 7px;
  white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-ghost { background: transparent; color: var(--green); border-color: var(--line); }
.btn-ghost:hover { background: var(--green-50); border-color: var(--green-300); }
.btn-subtle { background: var(--white); color: var(--ink); border-color: var(--line); }
.btn-subtle:hover { border-color: var(--green-300); color: var(--green); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-forums { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--green-300); }

.forum-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.forum-flags { font-size: 22px; letter-spacing: -2px; }
.forum-corridor { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }
.forum-name { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 10px 0 4px; line-height: 1.25; letter-spacing: -.2px; }
.forum-meta { font-size: 13px; color: var(--muted); }
.forum-card-foot { display: flex; gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.forum-stat { display: flex; flex-direction: column; }
.forum-stat b { font-family: var(--serif); font-size: 18px; color: var(--green); }
.forum-stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  letter-spacing: .3px; text-transform: uppercase;
}
.badge-draft { background: #efece3; color: var(--muted); }
.badge-published { background: #e5eef6; color: var(--blue); }
.badge-live { background: #e7f6ed; color: var(--green); }
.badge-live .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 1.6s infinite; }
.badge-concluded { background: #efece3; color: var(--muted); }
.badge-approved { background: #e7f6ed; color: var(--green); }
.badge-pending { background: #fbf2dd; color: var(--amber); }
.badge-rejected { background: #f8e7e4; color: var(--red); }
.badge-b2b { background: #e5eef6; color: var(--blue); }
.badge-b2g { background: #efe7f6; color: #6b4d9e; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ---------- KPI row ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi b { display: block; font-family: var(--serif); font-size: 28px; color: var(--ink); line-height: 1; }
.kpi span { font-size: 12px; color: var(--muted); margin-top: 6px; display: block; }
.kpi.accent b { color: var(--green); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: 10px 16px; font-family: var(--sans); font-size: 14px; font-weight: 500;
  color: var(--muted); cursor: pointer; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 12px 16px; background: var(--cream); border-bottom: 1px solid var(--line); font-weight: 600; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.row-hover:hover td { background: var(--cream); }
.cell-strong { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 12px; color: var(--muted); }
.tag-chip { display: inline-block; background: var(--green-50); color: var(--green-700); font-size: 11px; padding: 2px 8px; border-radius: 12px; margin: 1px 2px 1px 0; }

/* ---------- Match cards ---------- */
.match { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 14px; }
.match-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.match-pair { display: flex; align-items: center; gap: 14px; flex: 1; }
.match-party { flex: 1; }
.match-party .name { font-weight: 600; }
.match-party .org { font-size: 12px; color: var(--muted); }
.match-vs { font-family: var(--serif); color: var(--green-300); font-size: 16px; }
.match-score { text-align: right; min-width: 92px; }
.score-bar { height: 7px; border-radius: 6px; background: var(--cream-deep); overflow: hidden; margin-top: 5px; }
.score-fill { height: 100%; background: linear-gradient(90deg, var(--green-300), var(--green)); border-radius: 6px; }
.score-num { font-family: var(--serif); font-weight: 600; font-size: 16px; color: var(--green); }
.match-rationale { font-size: 13px; color: var(--muted); margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); line-height: 1.55; }
.match-foot { display: flex; gap: 8px; margin-top: 12px; align-items: center; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; font-family: var(--sans); font-size: 14px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--white); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 0; border-color: var(--green-300); box-shadow: 0 0 0 3px rgba(63,158,114,.15);
}
.field textarea { resize: vertical; min-height: 64px; }
.field label.check { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; color: var(--muted); margin: 0 10px 4px 0; }
.field input[type="checkbox"] { width: auto; padding: 0; margin: 0; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Approval mini ---------- */
.appr-stages { display: flex; gap: 6px; }
.appr-stage { font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 6px; letter-spacing: .3px; }
.appr-PENDING { background: #fbf2dd; color: var(--amber); }
.appr-APPROVED { background: #e7f6ed; color: var(--green); }
.appr-REJECTED { background: #f8e7e4; color: var(--red); }
.appr-WAIVED { background: #efece3; color: var(--muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-family: var(--serif); font-size: 20px; color: var(--ink); margin-bottom: 8px; }
.empty .ico { font-size: 40px; opacity: .25; margin-bottom: 14px; }

/* ---------- Section header ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h3 { font-family: var(--serif); font-size: 17px; font-weight: 600; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,25,.4); backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal { background: var(--white); border-radius: 18px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px 8px; }
.modal-head h2 { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.modal-x { background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 12px 24px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); background: var(--cream); border-radius: 0 0 18px 18px; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .25s ease;
  max-width: 340px; display: flex; align-items: center; gap: 9px;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- Bars (approval/matchmaking summary) ---------- */
.barline { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.barline .lbl { width: 130px; font-size: 12px; color: var(--muted); }
.barline .track { flex: 1; height: 10px; background: var(--cream-deep); border-radius: 6px; overflow: hidden; }
.barline .fill { height: 100%; border-radius: 6px; background: var(--green); }
.barline .val { width: 36px; text-align: right; font-size: 12px; font-weight: 600; }

.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.mt-20 { margin-top: 20px; }
.muted { color: var(--muted); }

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 300;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-700) 100%);
  display: grid; place-items: center; padding: 20px;
}
/* Critical: the `hidden` attribute must win over display:grid above,
   otherwise hideLogin() can't dismiss the screen after a successful login. */
.login-screen[hidden] { display: none !important; }
.login-card {
  background: var(--white); border-radius: 20px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 34px 32px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login-title { font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--ink); letter-spacing: -.3px; }
.login-sub { font-size: 12px; color: var(--muted); }
.login-lead { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.login-err { background: #f8e7e4; color: var(--red); font-size: 13px; padding: 9px 12px; border-radius: 9px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: transparent; border: 0; color: var(--green); font-size: 12px; font-weight: 600; cursor: pointer; padding: 6px 8px; }
.pw-toggle:hover { text-decoration: underline; }
.login-foot { margin-top: 22px; font-size: 11px; color: var(--muted); text-align: center; letter-spacing: .2px; }
.logout-btn { background: transparent; border: 0; color: #9ec9b3; font-size: 12px; cursor: pointer; padding: 0; text-align: left; }
.logout-btn:hover { color: #fff; text-decoration: underline; }

/* ---------- Role switcher ---------- */
.role-switch { padding: 0 16px 14px; }
.role-switch label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: #9ec9b3; margin-bottom: 5px; }
.role-switch select { width: 100%; padding: 8px 10px; border-radius: 9px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #fff; font-size: 13px; font-family: inherit; cursor: pointer; }
.role-switch select option { color: #1a1a1a; }
#delegatePicker { margin-top: 7px; }

/* ---------- Schedule ---------- */
.sched-controls { display: flex; align-items: center; gap: 8px; }
.ctrl-label { font-size: 12px; color: var(--muted); }
.mini-select { padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--white); font-size: 13px; font-family: inherit; cursor: pointer; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--white); font-size: 13px; cursor: pointer; color: var(--ink); transition: all .15s; }
.chip:hover { border-color: var(--green-300); }
.chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.day-head { font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--green); margin: 18px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.sess { display: flex; gap: 16px; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; align-items: flex-start; }
.sess-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); font-size: 14px; min-width: 64px; }
.sess-time span { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.sess-body { flex: 1; }
.sess-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sess-aud { font-size: 12px; color: var(--muted); }
.sess-title { font-weight: 600; font-size: 15px; color: var(--ink); }
.sess-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.sess-actions { display: flex; align-items: center; }
.sess-cancelled { opacity: .55; }
.sess-cancelled .sess-title { text-decoration: line-through; }
.badge-b2b { background: #e3eef9; color: #1d5fa8; }
.badge-b2g { background: #f3e9f7; color: #7a3d96; }

/* ---------- Notices ---------- */
.notice { display: flex; align-items: center; gap: 12px; background: #fcf6e6; border: 1px solid #ecdca6; color: #7a5d12; padding: 11px 14px; border-radius: 11px; font-size: 13.5px; margin-bottom: 10px; }
.notice span { flex: 1; }

/* ---------- Delegate view ---------- */
.dlg-card { margin-bottom: 16px; }
.dlg-top { display: flex; align-items: center; gap: 14px; }
.dlg-avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; font-family: var(--serif); }
.dlg-name { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.dlg-badges { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dlg-section { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 12px; }
.dlg-section h3 { font-family: var(--serif); font-size: 17px; font-weight: 600; color: var(--ink); }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form-row { grid-template-columns: 1fr; }
}
