/*
 * stakeholder.services — shared dark theme.
 * Colours sampled directly from the brand logo
 * (Stakeholder Services Logo/export/stakeholder-logo-primary-dark.svg):
 *   background #1C2B22, icon ramp #4C8562 -> #6EA980 -> #9FCB9F,
 *   "stakeholder" white #FFFFFF, ".services" #9FCB9F, tagline #8FB89C.
 * Used by every page (login.php, index.php, elections.php, admin.php,
 * users.php) so the system reads as one product, not four different tools.
 */

:root {
  --bg:            #1C2B22;
  --bg-panel:      #223328;
  --bg-panel-raised: #29402F;
  --bg-input:      #16211A;
  --border:        #33483A;
  --border-light:  #445D4D;

  --ink:           #F3F6F1;
  --ink-muted:     #8FB89C;
  --ink-faint:     #6B8577;
  --white:         #FFFFFF;

  --accent:        #9FCB9F;
  --accent-mid:    #6EA980;
  --accent-deep:   #4C8562;

  --error:         #E2836F;
  --error-bg:      #3A2620;
  --error-border:  #6B4136;

  --gold:          #D4B15A;
  --gold-light:    #8C7239;
}

/* Light theme — toggled via a data-theme="light" attribute on <html> (see
   the theme-toggle script in lib/nav.php). Every page builds its palette
   from these custom properties (index.php/elections.php alias their own
   --parchment/--commons-green/etc. names to these — see each file's :root
   block) specifically so this one override switches the whole site,
   without hunting down colours hardcoded per page. */
:root[data-theme="light"] {
  --bg:            #F6F4EC;
  --bg-panel:      #FFFFFF;
  --bg-panel-raised: #EDEAE0;
  --bg-input:      #FBFAF6;
  --border:        #DAD6C8;
  --border-light:  #C7C2AE;

  --ink:           #1C2B22;
  --ink-muted:     #4B6656;
  --ink-faint:     #7E8F82;
  --white:         #14201A;

  --accent:        #2F6B45;
  --accent-mid:    #3F7D57;
  --accent-deep:   #274F36;

  --error:         #B23B2E;
  --error-bg:      #FBEAE6;
  --error-border:  #E8B4A8;

  --gold:          #9C7A2E;
  --gold-light:    #6E5620;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }
a:hover { color: var(--white); }

h1, h2, h3 { font-weight: 800; color: var(--white); margin: 0 0 8px; }

.mono {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
}

.eyebrow {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ── Brand lockup — icon SVG + live text, not the raster logo, so it stays
   crisp at any size/zoom. Reused in the nav and on the login page. ────── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand img { display: block; }
.brand-word {
  font-family: 'Manrope', sans-serif;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -0.01em;
}
.brand-word .accent { color: var(--accent); }
.brand-tag {
  display: block;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* ── Top bar + collapsible left sidebar, shared across every gated page ──
   lib/nav.php renders <header class="topbar">, <aside class="sidebar">,
   a backdrop, and opens <div class="page-shell"> that the including page
   closes just before </body> — everything the page already had
   (<header>, <main>, <footer>) ends up inside that shell, offset clear
   of the fixed top bar and sidebar. Collapse state (html.sidebar-collapsed)
   and theme (html[data-theme]) are both plain attributes on <html> so an
   inline script in <head> can apply the persisted choice before first
   paint — see the anti-flash snippet at the top of each page's <head>. */
:root { --topbar-height: 52px; --sidebar-width: 232px; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.sidebar-toggle, .theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 1.5px solid var(--border-light);
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}
.sidebar-toggle:hover, .theme-toggle:hover { background: var(--bg-panel-raised); }
.topbar-spacer { flex: 1; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-muted);
}
.topbar-user .role-tag {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-panel-raised);
  color: var(--accent);
}

.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 250;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 12px;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
html.sidebar-collapsed .sidebar { transform: translateX(-100%); }

.sidebar-links { display: flex; flex-direction: column; gap: 2px; }
.sidebar-links a {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 7px;
}
.sidebar-links a:hover { color: var(--white); background: var(--bg-panel-raised); }
.sidebar-links a.active { color: var(--white); background: var(--bg-panel-raised); }

.sidebar-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 7px;
  text-align: left;
}
.sidebar-group-toggle:hover { color: var(--white); background: var(--bg-panel-raised); }
.sidebar-group-toggle.active { color: var(--white); }
.sidebar-group-chevron { font-size: 11px; transition: transform 0.15s ease; }
.sidebar-group.open .sidebar-group-chevron { transform: rotate(90deg); }

.sidebar-subnav {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding-left: 14px;
  margin-top: 2px;
}
.sidebar-group.open .sidebar-subnav { display: flex; }
.sidebar-subnav a { font-size: 13px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  z-index: 240;
  background: rgba(0, 0, 0, 0.4);
}

.page-shell {
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}
html.sidebar-collapsed .page-shell { margin-left: 0; }

/* Below ~tablet width the sidebar becomes an overlay (like a mobile nav
   drawer) instead of pushing content — there isn't room to spare. */
@media (max-width: 782px) {
  .page-shell { margin-left: 0 !important; }
  .sidebar { box-shadow: 2px 0 16px rgba(0, 0, 0, 0.3); }
  html:not(.sidebar-collapsed) .sidebar-backdrop { display: block; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar-user span:not(.role-tag) { display: none; }
  .brand-word { display: none; }
}

main, .page-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 36px 24px 100px;
}

/* ── Cards / panels ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.card + .card { margin-top: 20px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-light);
  border-radius: 7px;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-mid);
  box-shadow: 0 0 0 3px rgba(159, 203, 159, 0.15);
}
input::placeholder { color: var(--ink-faint); }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 7px;
  border: 1.5px solid var(--accent-mid);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.btn:hover { background: var(--accent-mid); color: var(--bg); }
.btn-primary { background: var(--accent-mid); color: var(--bg); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-danger { border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error); color: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border-light);
}
.btn-link:hover { color: var(--white); }
.btn-link.danger { color: var(--error); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.flash {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  margin-bottom: 20px;
}
.flash-success { background: rgba(159, 203, 159, 0.12); color: var(--accent); border: 1px solid var(--accent-deep); }
.flash-error, .error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error-border);
}
.flash-error, .flash-success { padding: 10px 14px; border-radius: 7px; font-size: 13.5px; margin-bottom: 20px; }
.hint { font-size: 13px; color: var(--ink-faint); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* ── Tags / badges ───────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 5px;
  margin-right: 4px;
}
.tag-accent { background: rgba(159, 203, 159, 0.15); color: var(--accent); }
.tag-muted { background: var(--bg-panel-raised); color: var(--ink-muted); }
.tag-error { background: var(--error-bg); color: var(--error); }
