/* Aramco brand (Brand Guidelines 2021): primary palette for external use, secondary only to highlight.
   Fonts: the guidelines' "general business" digital set (Trebuchet headlines, Segoe UI body), since the
   proprietary Manifa/Ghawar fonts are not licensed for this site. */
:root {
  color-scheme: light;
  --aramco-green: #84BD00;
  --dark-green: #00843D;
  --aramco-blue: #00A3E0;
  --dark-blue: #0033A0;
  --aramco-gray: #5F6369;
  --dark-gray: #323232;
  --neutral-gray: #C0C0C0;
  --light-gray: #DADADA;
  --brand-red: #F05F41; /* secondary palette: errors only */

  --page: #F2F2F2;
  --surface: #FFFFFF;
  --text: var(--dark-gray);
  --text-secondary: var(--aramco-gray);
  --text-muted: var(--aramco-gray);
  --heading: var(--dark-gray);
  --border: var(--light-gray);
  --grid: #E6E6E6;
  --axis: var(--neutral-gray);
  --series-1: var(--aramco-blue);
  --accent: var(--dark-blue);
  --accent-text: #FFFFFF;
  --link: var(--dark-blue);
  --hover: rgba(50, 50, 50, 0.05);
  --land: #E6E6E6;
  /* Status colours: one per invitation status, used in the table, KPI tiles and charts. */
  --st-accepted: var(--aramco-green);
  --st-pending: var(--aramco-blue);
  --st-delegated: #FFC846; /* brand Yellow (secondary palette, small category highlight) */
  --st-declined: var(--dark-blue);
  --st-cancelled: var(--aramco-gray);
  --st-noresp: var(--neutral-gray);
  /* Channel lines and the region/sector donuts (brand hues; 4 named groups + grey "Others"). */
  --ch-email: var(--aramco-blue);
  --ch-toplink: var(--dark-green);
  --cat-1: var(--aramco-green);
  --cat-2: var(--dark-green);
  --cat-3: var(--dark-blue);
  --cat-4: var(--aramco-blue);
  --cat-other: var(--aramco-gray);
  --error-bg: #FDE7E2;
  --error-text: #A33A24;
  --radius: 10px;
  --font-body: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-head: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-family: var(--font-body);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #262626;
    --surface: var(--dark-gray);
    --text: #FFFFFF;
    --text-secondary: var(--light-gray);
    --text-muted: var(--neutral-gray);
    --heading: #FFFFFF;
    --border: rgba(255, 255, 255, 0.12);
    --grid: #444444;
    --axis: var(--aramco-gray);
    --hover: rgba(255, 255, 255, 0.06);
    --link: var(--aramco-blue);
    --land: #4A4A4A;
    --st-pending: var(--dark-green);
    --st-declined: var(--aramco-blue);
    --st-cancelled: var(--neutral-gray);
    --st-noresp: var(--aramco-gray);
    --ch-toplink: var(--aramco-green);
    --cat-3: var(--aramco-blue);
    --cat-4: #FFC846;
    --cat-other: var(--neutral-gray);
    --error-bg: #4A2A22;
    --error-text: #F9B4A5;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
h1, h2, figcaption { margin: 0; font-family: var(--font-head); font-weight: 400; color: var(--heading); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

/* The brand gradient line: Aramco Green to Aramco Blue, left to right, used once per page. */
.energy-line { height: 4px; background: linear-gradient(90deg, var(--aramco-green) 0%, var(--aramco-green) 10%, var(--aramco-blue) 90%, var(--aramco-blue) 100%); }
.muted { color: var(--text-muted); margin: 0; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer; border: 1px solid transparent; border-radius: 8px;
  padding: 0.5rem 0.9rem; background: var(--accent); color: var(--accent-text); font-weight: 500;
}
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover, button.ghost:hover { background: var(--hover); }
button.ghost { background: transparent; color: var(--text-secondary); }
input, select {
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  padding: 0.5rem 0.7rem; min-width: 0;
}
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin: 0; }
.loading { text-align: center; padding: 4rem 1rem; color: var(--text-muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 0.75rem; padding: 0 2rem 2rem; overflow: hidden; }
.login-card .energy-line { margin: 0 -2rem 1.25rem; }
.login-card label { font-weight: 500; margin-top: 0.5rem; }
.error { color: var(--error-text); margin: 0; min-height: 1.2em; }

/* Dashboard */
.topbar {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1.25rem max(1rem, calc((100vw - 1200px) / 2)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.content { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.banner { margin: 0; padding: 0.75rem 1rem; border-radius: 8px; background: var(--error-bg); color: var(--error-text); }

/* Header tiles: icon + label, figure with its share of Invited, and a thin meter in the tile's colour (--c). */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.75rem; } /* 10 tiles: two rows of five */
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 0.9rem; display: flex; flex-direction: column; gap: 0.35rem; }
.kpi .label { color: var(--text-secondary); font-size: 0.8rem; display: flex; align-items: center; gap: 0.45rem; line-height: 1.2; }
.kpi .icon {
  flex: none; display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 8px;
  color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent);
}
.kpi .icon svg { width: 1.05rem; height: 1.05rem; }
.kpi .value {
  font-family: var(--font-head); font-size: 1.7rem; font-weight: 400; color: var(--heading); line-height: 1.1;
  margin-top: auto; /* numbers line up when a label wraps */ display: flex; align-items: baseline; justify-content: space-between; gap: 0.4rem;
}
.kpi .share { font-family: var(--font-body); font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kpi .meter { height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.kpi .meter span { display: block; height: 100%; border-radius: 2px; background: var(--c); }
.kpi.rate { border-color: color-mix(in srgb, var(--series-1) 35%, var(--border)); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 1.25rem; }
.span-full { grid-column: 1 / -1; }
.charts h3 { margin-bottom: 0.25rem; }
/* Donut + its figures side by side (stacked on narrow screens). */
.donut-panel { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1rem; align-items: center; }
.donut-box { position: relative; height: 230px; }
.channel-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1.25rem 2rem; }
.mini { width: auto; border-collapse: collapse; font-size: 0.85rem; }
.mini th, .mini td { border: 0; padding: 0.22rem 0.5rem 0.22rem 0; font-weight: 400; }
.mini th { color: var(--text-secondary); display: flex; align-items: center; gap: 0.4rem; }
.mini td { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.mini td:last-child { color: var(--text-muted); font-weight: 400; min-width: 2.8rem; }
.mini tr.total th, .mini tr.total td { color: var(--heading); font-weight: 600; border-bottom: 1px solid var(--grid); padding-bottom: 0.35rem; }
.mini tr.extra th { padding-left: 1rem; font-style: italic; }
.swatch { flex: none; width: 0.6rem; height: 0.6rem; border-radius: 2px; display: inline-block; }
@media (max-width: 480px) { .donut-panel { grid-template-columns: minmax(0, 1fr); } }
figcaption { font-size: 1rem; margin-bottom: 0.75rem; }
.chart-box { position: relative; height: 260px; }
.timeline-box { height: 320px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; }

h3 { font-size: 0.9rem; font-weight: 600; margin: 0 0 0.5rem; color: var(--text-secondary); }
.hint { margin: 0.25rem 0 1rem; font-size: 0.85rem; }
.note-line { margin: 0.75rem 0 0; font-size: 0.8rem; }
.credits { font-size: 0.75rem; text-align: center; }

/* Section nav: pinned at the top; the filter bar pins just below it. Sections leave room for both when jumped to. */
:root { --nav-h: 2.6rem; }
.section-nav {
  position: sticky; top: 0; z-index: 6; min-height: var(--nav-h);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.25rem 0.5rem;
  padding: 0.3rem max(1rem, calc((100vw - 1200px) / 2)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.section-nav a {
  padding: 0.3rem 0.7rem; border-radius: 6px; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); text-decoration: none;
}
.section-nav a:hover { background: var(--hover); color: var(--text); }
.section-nav a[aria-current="true"] { color: var(--heading); box-shadow: inset 0 -2px 0 var(--series-1); border-radius: 6px 6px 0 0; }
#kpis, #charts, #distribution { scroll-margin-top: calc(var(--nav-h) + 1rem); }
#guests { scroll-margin-top: calc(var(--nav-h) + 5rem); } /* below the pinned filter bar */

/* Shared filter bar: stays visible while scrolling to the table */
.filter-bar {
  position: sticky; top: var(--nav-h); z-index: 5;
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; padding: 0.75rem;
  box-shadow: 0 4px 12px -8px rgba(0, 0, 0, 0.25);
}
.filter-bar input { flex: 1 1 14rem; }
.filter-bar select { flex: 0 1 12rem; }

/* Distribution */
.geo { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 820px) {
  .geo { grid-template-columns: minmax(0, 1fr); }
  .filter-bar { position: static; } /* stacked controls would cover too much of a small screen */
  .filter-bar select { flex: 1 1 100%; }
}
.map { position: relative; border-radius: 8px; overflow: hidden; background: var(--page); }
.map svg { display: block; width: 100%; height: auto; cursor: grab; touch-action: none; }
.map svg:active { cursor: grabbing; }
.map-msg { padding: 2rem; text-align: center; }
.land { fill: var(--land); stroke: var(--surface); stroke-width: 0.5px; }
.land.selected { fill: color-mix(in srgb, var(--series-1) 25%, var(--land)); }
.bubble { cursor: pointer; outline: none; }
.bubble circle { fill: var(--series-1); fill-opacity: 0.75; stroke: var(--surface); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.bubble:hover circle, .bubble:focus-visible circle { fill-opacity: 1; stroke: var(--text); }
.bubble.selected circle { fill-opacity: 1; stroke: var(--text); stroke-width: 2px; }
.bubble.dimmed { opacity: 0.35; }
.bubble text { fill: #fff; font-size: 11px; font-weight: 600; text-anchor: middle; pointer-events: none; }
.zoom { position: absolute; right: 0.5rem; top: 0.5rem; display: flex; flex-direction: column; gap: 0.25rem; z-index: 2; }
.zoom button { width: 2rem; height: 2rem; padding: 0; line-height: 1; }
.tip {
  position: absolute; z-index: 3; pointer-events: none; min-width: 10rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem;
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.35); font-size: 0.8rem;
}
.tip div { display: flex; justify-content: space-between; gap: 1rem; color: var(--text-secondary); }
.tip b { color: var(--text); font-variant-numeric: tabular-nums; }
.tip .tip-sub { color: var(--text-muted); margin-bottom: 0.3rem; }
.breakdowns { display: grid; gap: 1.25rem; }
.pie-box { position: relative; height: 180px; margin-bottom: 0.5rem; }
.legend-list { display: grid; gap: 0.1rem; max-height: 14rem; overflow-y: auto; }
.legend-item {
  all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto 2.8rem; align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.45rem; border-radius: 6px; font-size: 0.85rem;
}
.legend-item:hover { background: var(--hover); }
.legend-item:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.legend-item.dimmed { opacity: 0.45; }
.legend-item.selected { background: var(--hover); font-weight: 600; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--text); text-align: right; }
.bar-pct { font-variant-numeric: tabular-nums; color: var(--text-muted); text-align: right; }

.table-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; }
.count { margin: 0.75rem 0 0.5rem; font-size: 0.85rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td.date { font-variant-numeric: tabular-nums; }
th { font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; }
th button {
  all: unset; cursor: pointer; display: inline-flex; gap: 0.3rem; align-items: center;
}
th button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }
th button::after { content: "↕"; opacity: 0.35; font-size: 0.8em; }
th[aria-sort="ascending"] button::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] button::after { content: "↓"; opacity: 1; }
tbody tr:hover { background: var(--hover); }

.action-link {
  display: inline-block; padding: 0.3rem 0.7rem; border-radius: 6px; font-size: 0.8rem; font-weight: 500;
  background: var(--accent); color: var(--accent-text); text-decoration: none; white-space: nowrap;
}
.action-link:hover { filter: brightness(1.15); }
button.action-link { border: 0; cursor: pointer; }
.copy-cell { display: inline-flex; align-items: center; gap: 0.6rem; white-space: nowrap; }
.ghost-link { font-size: 0.8rem; color: var(--link); }
td.link a { color: var(--link); word-break: break-all; display: inline-block; min-width: 18rem; }
.action-link:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
/* Guest views as folder tabs: the active tab is raised and joins the panel; the others sit flat on the line. */
.tabbed { padding-top: 0.9rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: 0 -1.1rem 1rem; padding: 0 1.1rem; }
.tabs [role="tab"] {
  all: unset; box-sizing: border-box; cursor: pointer; white-space: nowrap;
  padding: 0.6rem 1.1rem; margin-bottom: -1px; border: 1px solid transparent; border-radius: 8px 8px 0 0;
  font-family: var(--font-head); font-size: 1rem; color: var(--text-muted);
}
.tabs [role="tab"]:hover { color: var(--text); background: var(--hover); }
.tabs [role="tab"][aria-selected="true"] {
  color: var(--heading); background: var(--surface); border-color: var(--border); border-bottom-color: var(--surface);
  box-shadow: inset 0 3px 0 var(--series-1);
}
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }
.tab-panel .table-head .count, .tab-panel .table-head .hint { margin: 0; }

/* Toplink invitations: one row per guest, details left, actions right (wraps on narrow screens, no side scroll). */
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-secondary); cursor: pointer; }
.template-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.75rem 0; }
.template-bar label { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.template-bar select { flex: 0 1 16rem; }
.template-bar .muted { font-size: 0.8rem; }
.message-preview { border: 1px dashed var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; background: var(--page); }
.message-label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.2rem; }
.message-preview p { margin: 0; white-space: pre-line; color: var(--text-secondary); font-size: 0.85rem; }
.message-preview mark { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--text); border-radius: 3px; padding: 0 0.2rem; }
.invite-list { list-style: none; margin: 0; padding: 0; max-height: 32rem; overflow-y: auto; }
.invite-list li {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem;
  padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--grid);
}
.invite-list li:hover { background: var(--hover); }
.invite-who { min-width: 0; display: grid; gap: 0.1rem; }
.invite-who strong { font-weight: 600; color: var(--text); }
.invite-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: 0.8rem; color: var(--text-muted); overflow-wrap: anywhere; }
.invite-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.invite-actions button.secondary { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.no-link { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.tag { font-size: 0.7rem; padding: 0.05rem 0.4rem; border-radius: 4px; border: 1px solid var(--border); color: var(--text-secondary); }
.status { display: inline-flex; align-items: center; gap: 0.4rem; }
.status::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 2px; background: var(--st-noresp); }
.status.accepted::before { background: var(--st-accepted); }
.status.pending::before { background: var(--st-pending); }
.status.delegated::before { background: var(--st-delegated); }
.status.declined::before { background: var(--st-declined); }
.status.cancelled::before { background: var(--st-cancelled); }
