/* =========================================================================
   HR Dashboard — Workforce Performance Analysis KPI Dashboard
   Blue corporate theme to match the reference dashboard design.
   Accessible, high-contrast option, print/PDF ready.
   ========================================================================= */
:root {
  --brand: #1f4e96;          /* primary navy-blue (rings, headers) */
  --brand-2: #2f6ac0;        /* medium blue */
  --brand-dark: #14315e;     /* deep navy */
  --brand-soft: #eaf1fb;     /* pale blue tint */
  --ink: #10233f;
  --ink-soft: #33456a;
  --muted: #5a6a86;
  --line: #ccd7e8;
  --bg: #eef2f8;
  --panel: #ffffff;
  --panel-2: #f6f9fe;
  --good: #1a7f45;
  --warn: #b8860b;
  --bad: #c0392b;
  --group: #14315e;   /* Vodafone Group series  (navy)   */
  --egypt: #e08a1e;   /* Vodafone Egypt series  (amber)  */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 49, 94, .08), 0 6px 18px rgba(20, 49, 94, .07);
  --user-scale: 1;
  --focus: #ff8c00;
}

/* High-contrast mode */
body.contrast {
  --ink: #000; --ink-soft: #0a0a0a; --muted: #141414;
  --line: #000; --bg: #fff; --panel: #fff; --panel-2: #fff;
  --brand: #0b2f6b; --brand-2: #0b2f6b; --brand-dark: #000;
  --group: #0b2f6b; --egypt: #8a4b00; --brand-soft: #fff;
  --shadow: none;
}
body.contrast .panel, body.contrast .kpi-card,
body.contrast .card, body.contrast .gauge-card { border-width: 2px; }

* { box-sizing: border-box; }
html { font-size: calc(112.5% * var(--user-scale)); }
body {
  margin: 0; color: var(--ink); background: var(--bg); line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: .2px; }
h2 { font-size: 1.15rem; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--brand-dark); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(180deg, #ffffff, #f4f8fe);
  border-bottom: 3px solid var(--brand);
  padding: 1rem clamp(1rem, 3vw, 2rem) .75rem;
  position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .85rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 9px; flex: none;
  background: linear-gradient(160deg, var(--brand-2), var(--brand-dark));
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px var(--brand);
}
h1 { color: var(--brand-dark); }
.subtitle { margin: .1rem 0 0; color: var(--muted); font-size: .82rem; }

.controls {
  display: flex; flex-wrap: wrap; gap: 1rem 1.5rem;
  align-items: center; justify-content: space-between; margin-top: .9rem;
}
.entity-switch {
  display: flex; gap: .25rem; border: 1px solid var(--line);
  border-radius: 999px; padding: .25rem; margin: 0; background: var(--panel-2);
}
.entity-switch legend { padding: 0; }
.entity-switch label {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .35rem .8rem; border-radius: 999px; cursor: pointer;
  font-size: .85rem; font-weight: 600; color: var(--ink-soft);
}
.entity-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.entity-switch label:has(input:checked) { background: var(--brand); color: #fff; }
.entity-switch label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

.control-buttons { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btn {
  font: inherit; font-size: .85rem; font-weight: 600;
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.btn:hover { background: var(--brand-soft); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-icon { padding: .5rem .6rem; }
.btn[aria-pressed="true"] { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }
.text-size { display: inline-flex; gap: .25rem; }
.switch { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; font-weight: 600; }
.switch input { width: 1.1rem; height: 1.1rem; accent-color: var(--brand); }

.status-bar { margin-top: .6rem; font-size: .8rem; color: var(--muted); }
.status-bar .live-dot {
  display: inline-block; width: .6rem; height: .6rem; border-radius: 50%;
  background: var(--good); margin-right: .35rem; vertical-align: middle;
}
.status-bar .live-dot.flash { animation: flash .8s ease; }
@keyframes flash { 0% { transform: scale(1); } 50% { transform: scale(2.2); } 100% { transform: scale(1); } }

/* ---------- Layout ---------- */
main { padding: clamp(1rem, 3vw, 2rem); max-width: 1400px; margin: 0 auto; }
.error-banner {
  background: #fdece9; border: 2px solid var(--bad); color: var(--bad);
  padding: 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 600;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.3rem; box-shadow: var(--shadow); margin-bottom: 1.4rem;
}
.panel > h2 {
  display: flex; align-items: center; gap: .5rem; color: var(--brand-dark);
  padding-bottom: .6rem; margin-bottom: 1rem; border-bottom: 2px solid var(--line);
}
.panel > h2::before { content: ""; width: .35rem; height: 1.1rem; background: var(--brand); border-radius: 2px; }

/* ---------- Hero gauges (top band, reference style) ---------- */
.hero { background: linear-gradient(180deg, #ffffff, var(--brand-soft)); border-color: var(--brand); }
.gauge-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.gauge-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem .8rem; text-align: center; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
}
.gauge-card h3 {
  font-size: .82rem; color: var(--brand-dark); font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
}
.gauge-svg { width: 130px; height: 130px; }
.gauge-value { font-size: 1.5rem; font-weight: 800; fill: var(--brand-dark); }
.gauge-sub { font-size: .72rem; fill: var(--muted); }
.gauge-compare { font-size: .78rem; color: var(--muted); }
.gauge-compare strong { color: var(--ink); }
.delta { font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }

/* ---------- KPI card grid (Image-1 signature cards) ---------- */
.kpi-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.kpi-card {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel); display: flex; flex-direction: column;
}
.kpi-card .kpi-head {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff; font-size: .78rem; font-weight: 700; letter-spacing: .3px;
  padding: .5rem .7rem; text-align: center;
}
.kpi-card .kpi-body { padding: .7rem .8rem 1rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .35rem; }
.kpi-card .kpi-value { font-size: 1.9rem; font-weight: 800; color: var(--brand-dark); line-height: 1.05; }
.kpi-spark { width: 130px; height: 36px; }
.kpi-foot { font-size: .74rem; color: var(--muted); }
.kpi-foot .delta { margin-right: .2rem; }
.kpi-entity { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

/* ---------- Generic cards / bars ---------- */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; background: var(--panel-2); }
.card h3 { font-size: .85rem; color: var(--brand-dark); margin-bottom: .5rem; }
.kpi-big { font-size: 1.6rem; font-weight: 800; color: var(--brand-dark); }
.kpi-row { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.kpi-row .lab { color: var(--muted); font-size: .78rem; }

.dual-bars { display: grid; gap: .35rem; }
.bar-item .bar-label { display: flex; justify-content: space-between; font-size: .82rem; margin-bottom: .25rem; }
.bar-track { background: #dfe7f3; border-radius: 6px; height: 12px; overflow: hidden; }
body.contrast .bar-track { border: 1px solid #000; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-fill.group { background: var(--group); }
.bar-fill.egypt { background: var(--egypt); }

/* ---------- Horizontal grouped bar chart ---------- */
.hbar { margin-top: .4rem; --catw: 190px; --valw: 52px; }
.hbar.counts { --valw: 72px; }
.hbar-head, .hbar-item {
  display: grid; grid-template-columns: var(--catw) 1fr; gap: .1rem 1rem; align-items: center;
}
.hbar-item { padding: .55rem 0; border-top: 1px solid var(--line); }
.hbar-item:first-of-type { border-top: 0; }
.hbar-axis {
  display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted);
  border-bottom: 2px solid var(--line); padding: 0 var(--valw) .25rem 72px; margin-bottom: .2rem;
}
.hbar-axis span { transform: translateX(50%); }
.hbar-axis span:first-child { transform: none; }
.hbar-axis span:last-child { transform: translateX(0); }
.hbar-catlabel { text-align: right; font-weight: 700; font-size: .88rem; color: var(--brand-dark); }
.hbar-plot { display: flex; flex-direction: column; gap: .35rem; }
.hbar-line { display: grid; grid-template-columns: 66px 1fr var(--valw); align-items: center; gap: .5rem; }
.hbar-series-lab { font-size: .74rem; color: var(--muted); }
.hbar-track {
  height: 16px; border-radius: 8px; overflow: hidden;
  background-color: #dfe7f3;
  background-image: linear-gradient(90deg, rgba(255,255,255,.75) 1px, transparent 1px);
  background-size: 25% 100%;
}
body.contrast .hbar-track { border: 1px solid #000; }
.hbar-fill { height: 100%; border-radius: 8px; }
.hbar-fill.group { background: var(--group); }
.hbar-fill.egypt { background: var(--egypt); }
.hbar-val { text-align: right; font-weight: 700; font-size: .82rem; color: var(--ink); }
@media (max-width: 620px) {
  .hbar { --catw: 110px; }
  .hbar-line { grid-template-columns: 52px 1fr 44px; }
  .hbar-axis { padding-left: 52px; }
}

.legend { display: flex; gap: 1rem; font-size: .78rem; color: var(--muted); margin: .2rem 0 .8rem; flex-wrap: wrap; }
.legend .swatch { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; vertical-align: middle; margin-right: .3rem; }
.swatch.group { background: var(--group); }
.swatch.egypt { background: var(--egypt); }

/* Data tables */
.table-wrap { overflow-x: auto; margin-top: 1rem; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data caption { text-align: left; font-weight: 700; color: var(--brand-dark); padding: .3rem 0 .5rem; font-size: .85rem; }
table.data th, table.data td { border: 1px solid var(--line); padding: .5rem .6rem; text-align: right; }
table.data th[scope="row"], table.data td:first-child { text-align: left; }
table.data thead th { background: var(--brand-soft); color: var(--brand-dark); }
table.data tbody tr:nth-child(even) td { background: #f7faff; }
body.contrast table.data tbody tr:nth-child(even) td { background: #fff; }
.num { font-variant-numeric: tabular-nums; }

details.table-toggle > summary { cursor: pointer; font-size: .82rem; font-weight: 600; color: var(--brand-2); padding: .3rem 0; list-style: none; }
details.table-toggle > summary::before { content: "▸ "; }
details.table-toggle[open] > summary::before { content: "▾ "; }
.section-note { font-size: .78rem; color: var(--muted); margin-top: .6rem; }

/* Flight-risk scorecard */
.scorecard { display: grid; gap: 1.2rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.risk-bar-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.risk-bar-row .rlab { font-size: .8rem; }
.risk-track { grid-column: 1 / -1; background: #dfe7f3; height: 10px; border-radius: 5px; overflow: hidden; }
body.contrast .risk-track { border: 1px solid #000; }
.risk-fill { height: 100%; }
.risk-total { display: flex; align-items: center; justify-content: space-between; border-top: 2px solid var(--line); margin-top: .6rem; padding-top: .6rem; font-weight: 800; font-size: 1.05rem; color: var(--brand-dark); }
.risk-totals {
  display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: center;
  margin-top: .9rem; padding-top: .8rem; border-top: 2px solid var(--line);
}
.risk-total-item { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--brand-dark); font-size: 1.02rem; }
.risk-total-item .rt-name { font-weight: 700; color: var(--ink-soft); font-size: .82rem; text-transform: uppercase; letter-spacing: .4px; }
.badge { padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; color: #fff; }
.badge.low { background: var(--good); }
.badge.med { background: var(--warn); }
.badge.high { background: var(--bad); }

/* ---------- Print / PDF ---------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  html { font-size: 90%; }
  body { background: #fff; }
  .app-header { position: static; box-shadow: none; }
  .controls, .skip-link, #btn-print { display: none !important; }
  .status-bar { color: #000; }
  .panel, .card, .kpi-card, .gauge-card { box-shadow: none; break-inside: avoid; }
  .panel { border: 1px solid #999; }
  section, .scorecard > div, .card, .kpi-card { break-inside: avoid; }
  details.table-toggle > summary { display: none; }
  details.table-toggle > *:not(summary) { display: block !important; }
  a[href]::after { content: ""; }
  /* keep header gradients in print */
  .kpi-card .kpi-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
