/* EMF Performance Management — PROVISIONAL design tokens.
   No official EMF brand assets were supplied; replace --brand-* values once
   the corporate identity guide is available. */
:root {
  color-scheme: light;
  --brand: #1f3a5f; --brand-dark: #142840; --accent: #c8963e; --accent-soft: #f6eedd;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --line: #dfe3e8; --line-strong: #c7cdd5;
  --ink: #1c2430; --ink-2: #4a5462; --ink-3: #6b7480;
  --self: #2a78d6; --mgr: #eb6834; --seq: #2a78d6; --seq-soft: #cde2fb;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #0b6b0b; --warn-ink: #8a5a00; --critical-ink: #a32525;
  --good-bg: #e3f4e3; --warn-bg: #fdf1d3; --critical-bg: #fbe4e4; --info-bg: #e5effb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Geeza Pro", "Noto Sans Arabic", Tahoma, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #8fb3e0; --brand-dark: #0f1d2e; --accent: #d9a956; --accent-soft: #2e2618;
    --bg: #121417; --surface: #1a1c1f; --surface-2: #202328; --line: #2e3238; --line-strong: #3d424a;
    --ink: #eceef1; --ink-2: #c1c6ce; --ink-3: #959ca6;
    --self: #3987e5; --mgr: #d95926; --seq: #3987e5; --seq-soft: #1c3557;
    --good-ink: #5fd35f; --warn-ink: #f5c451; --critical-ink: #f08a8a;
    --good-bg: #16301a; --warn-bg: #33290f; --critical-bg: #3a1a1a; --info-bg: #17263a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #8fb3e0; --brand-dark: #0f1d2e; --accent: #d9a956; --accent-soft: #2e2618;
  --bg: #121417; --surface: #1a1c1f; --surface-2: #202328; --line: #2e3238; --line-strong: #3d424a;
  --ink: #eceef1; --ink-2: #c1c6ce; --ink-3: #959ca6;
  --self: #3987e5; --mgr: #d95926; --seq: #3987e5; --seq-soft: #1c3557;
  --good-ink: #5fd35f; --warn-ink: #f5c451; --critical-ink: #f08a8a;
  --good-bg: #16301a; --warn-bg: #33290f; --critical-bg: #3a1a1a; --info-bg: #17263a;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.served .file-notice { display: none !important; }
.served .app-shell { display: block !important; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand-dark); color: #fff; display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap; }
:root[data-theme="dark"] .topbar { background: #0b1522; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; border: 1.5px dashed rgba(255,255,255,.55); display: grid; place-items: center; font-size: 10px; font-weight: 700; letter-spacing: .5px; color: rgba(255,255,255,.85); flex: none; }
.brand-name { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand-sub { font-size: 11px; opacity: .75; white-space: nowrap; }
.prov-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
/* Official EMF logo (black lettering) needs a light header in both themes */
.topbar, :root[data-theme="dark"] .topbar { background: #ffffff; color: #1c2430; border-bottom: 3px solid #347C4C; }
.brand-logo { height: 58px; width: auto; display: block; flex: none; }
.topbar .brand-name { color: #285A39; }
.topbar .brand-sub { color: #4a5462; opacity: 1; }
.topbar .prov-badge { color: #285A39; background: #F3E4CD; border-color: #e2d3b8; }
.topbar .search input { background: #f1f3f6; color: #1c2430; }
.topbar .search input::placeholder { color: #6b7480; }
.topbar .search input:focus { background: #ffffff; box-shadow: 0 0 0 2px #347C4C; }
.topbar .icon-btn { background: #f1f3f6; border-color: #d5dae0; color: #1c2430; }
.topbar .icon-btn:hover { background: #e6e9ee; }
.topbar .user-chip { color: #4a5462; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search input { width: 100%; border: 0; border-radius: 8px; padding: 8px 12px; background: rgba(255,255,255,.12); color: #fff; outline: none; }
.search input::placeholder { color: rgba(255,255,255,.65); }
.search input:focus { background: rgba(255,255,255,.2); box-shadow: 0 0 0 2px var(--accent); }
.search-results { position: absolute; inset-inline: 0; top: 40px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; }
.search-results button { display: block; width: 100%; text-align: start; padding: 8px 12px; border: 0; background: none; cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results button:hover, .search-results button:focus { background: var(--surface-2); outline: none; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.icon-btn:hover { background: rgba(255,255,255,.2); }
.user-chip { font-size: 12px; opacity: .9; white-space: nowrap; }

.sample-banner { background: #b42318; color: #fff; text-align: center; font-weight: 700; padding: 6px 12px; letter-spacing: .3px; }
.notice { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ---------- nav ---------- */
.nav { display: flex; gap: 2px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.nav a { padding: 12px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.nav a.active { color: var(--brand); border-bottom-color: var(--accent); }
.nav a:hover { color: var(--ink); }

main { padding: 20px; max-width: 1440px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select, .filters input, .field input, .field select, .field textarea { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; min-width: 150px; }
.filters .reset { background: none; border: 0; color: var(--brand); cursor: pointer; text-decoration: underline; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.charts { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--ink-3); margin-bottom: 6px; min-height: 2.6em; }
.kpi .value { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--accent); }
.kpi.alert .value { color: var(--critical-ink); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.card-head .hint { font-size: 12px; color: var(--ink-3); }
.empty { padding: 28px 12px; text-align: center; color: var(--ink-3); border: 1px dashed var(--line-strong); border-radius: 8px; font-size: 13px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; position: sticky; top: 0; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.pill.good { background: var(--good-bg); color: var(--good-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--critical-bg); color: var(--critical-ink); }
.pill.info { background: var(--info-bg); color: var(--brand); }
.pill.neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.pill.sample { background: #b42318; color: #fff; }

/* ---------- progress / stepper ---------- */
.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.stepper { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 4px; }
.step { text-align: center; font-size: 10.5px; color: var(--ink-3); }
.step .dot { width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 4px; display: grid; place-items: center; font-weight: 700; font-size: 11px; border: 2px solid var(--line-strong); background: var(--surface); color: var(--ink-3); }
.step.done .dot { background: var(--good); border-color: var(--good); color: #fff; }
.step.current .dot { border-color: var(--accent); color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
.step.overdue .dot { border-color: var(--critical); color: var(--critical-ink); }
.step .when { display: block; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mini-steps { display: flex; gap: 2px; }
.mini-steps i { width: 9px; height: 9px; border-radius: 2px; background: var(--line); display: block; }
.mini-steps i.d { background: var(--good); }
.mini-steps i.c { background: var(--accent); }

/* ---------- employee card ---------- */
.profile { display: grid; grid-template-columns: 340px 1fr; gap: 16px; }
.profile-id { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 20px; flex: none; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; margin: 0; }
.dl dt { color: var(--ink-3); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.scorebox { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.scorebox > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.scorebox .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); align-items: center; flex-wrap: wrap; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; vertical-align: -2px; margin-inline-end: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .seg button.on { color: #0b1522; }
.flag-list { margin: 0; padding-inline-start: 18px; }
.flag-list li { margin-bottom: 4px; }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-2); font-size: 11.5px; font-family: var(--font); }
.chart .axis line, .chart .grid line { stroke: var(--line); }
.chart .val { fill: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .mark, .chart .mark.hover { filter: brightness(1.08); }
.tooltip { position: fixed; pointer-events: none; z-index: 50; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 280px; }
.tooltip b { display: block; margin-bottom: 2px; }
details.table-view { margin-top: 8px; font-size: 12px; }
details.table-view summary { cursor: pointer; color: var(--ink-3); }

/* ---------- forms / buttons ---------- */
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
:root[data-theme="dark"] .btn { color: #0b1522; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--ink-3); }
.inline-edit { display: flex; gap: 6px; align-items: center; }
.inline-edit input { padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); min-width: 0; width: 150px; }

.login-wrap { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 400px; }
.toast { position: fixed; inset-inline-end: 20px; bottom: 20px; background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: 420px; }

/* ---------- org chart ---------- */
.org-dept { margin-bottom: 14px; }
.org-dept > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-weight: 700; }
.org-dept > summary::-webkit-details-marker { display: none; }
.org-dept > summary::before { content: "▸"; color: var(--ink-3); transition: transform .15s; }
.org-dept[open] > summary::before { transform: rotate(90deg); }
[dir="rtl"] .org-dept > summary::before { content: "◂"; }
[dir="rtl"] .org-dept[open] > summary::before { transform: rotate(-90deg); }
.org-body { padding: 14px 6px 6px; overflow-x: auto; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-inline-start: 28px; position: relative; }
.tree li { position: relative; padding: 6px 0 6px 0; }
.tree ul > li::before { content: ""; position: absolute; inset-inline-start: -16px; top: 0; height: 26px; width: 16px; border-inline-start: 2px solid var(--line-strong); border-bottom: 2px solid var(--line-strong); }
.tree ul > li:not(:last-child)::after { content: ""; position: absolute; inset-inline-start: -16px; top: 24px; bottom: 0; border-inline-start: 2px solid var(--line-strong); }
.tree li.conflict::before { border-color: var(--serious); border-style: dashed; }
.node { display: inline-flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line-strong); border-inline-start: 4px solid var(--brand); border-radius: 8px; padding: 8px 12px; min-width: 240px; max-width: 420px; }
.node.ghost { border-style: dashed; border-inline-start-style: dashed; border-inline-start-color: var(--ink-3); background: transparent; }
.node.conflict { border-inline-start-color: var(--serious); }
.node.match { box-shadow: 0 0 0 3px var(--accent); }
.node .t { font-weight: 600; }
.node .people { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.node .person { font-size: 12px; background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 1px 10px; text-decoration: none; border: 1px solid transparent; }
.node .person:hover { border-color: var(--accent); }
.org-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 14px; }
.org-legend span { display: inline-flex; align-items: center; gap: 6px; }
.org-legend i { width: 28px; height: 0; border-top: 2px solid var(--line-strong); display: inline-block; }
.org-legend i.dash { border-top: 2px dashed var(--serious); }
.org-legend i.ghost { border-top: 2px dashed var(--ink-3); }

@media (max-width: 900px) {
  .profile { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .stepper { grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 10px; }
}
@media (max-width: 560px) {
  main { padding: 12px 16px; }
  .topbar { padding: 8px 16px; }
  .brand-logo { height: 42px; }
  .nav { padding: 0 8px; }
  .brand-sub, .prov-badge { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dl { grid-template-columns: 1fr; }
  .node { min-width: 0; }
  .filters select, .filters input { min-width: 0; flex: 1 1 140px; }
}
@media print {
  .topbar, .nav, .filters, .btn { display: none !important; }
  body { background: #fff; }
}

/* Primary buttons in OS dark mode: dark text on the light brand fill (contrast) */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.secondary) { color: #0b1522; } }

/* ---------- ⌘K search trigger + command palette ---------- */
.search-trigger { width: 100%; display: flex; align-items: center; gap: 8px; border: 1px solid #d5dae0; border-radius: 8px; padding: 7px 8px 7px 12px; background: #f1f3f6; color: #6b7480; cursor: pointer; font: inherit; text-align: start; }
.search-trigger:hover { background: #e9ecf0; }
.search-trigger:focus-visible { outline: none; box-shadow: 0 0 0 2px #347C4C; }
.search-trigger .st-ico { font-size: 16px; line-height: 1; }
.search-trigger .st-ph { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd { font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 3px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-3, #6b7480); }
.search-trigger kbd { border-color: #c9cfd6; background: #fff; color: #4a5462; }
.cmdk { position: fixed; inset: 0; z-index: 200; background: rgba(15, 22, 18, .45); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk.hidden { display: none; }
.cmdk-panel { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.28); overflow: hidden; }
.cmdk-in { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 18px; color: var(--ink-3, #6b7480); }
.cmdk-in input { flex: 1; border: 0; outline: none; background: transparent; color: var(--ink); font: inherit; font-size: 16px; padding: 4px 0; }
.cmdk-list { overflow: auto; padding: 6px; }
.cmdk-g { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-3, #6b7480); padding: 10px 10px 4px; font-weight: 600; }
.cmdk-it { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.cmdk-it > div { flex: 1; min-width: 0; }
.cmdk-it b { display: block; font-weight: 600; }
.cmdk-it span { display: block; font-size: 12px; color: var(--ink-3, #6b7480); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-it em { font-style: normal; font-size: 11px; font-weight: 600; color: #285A39; background: #F3E4CD; padding: 2px 7px; border-radius: 6px; flex: none; }
.cmdk-it.on { background: color-mix(in srgb, #347C4C 14%, transparent); }
.cmdk-it mark { background: color-mix(in srgb, #F2B01E 45%, transparent); color: inherit; border-radius: 2px; }
.cmdk-empty { padding: 18px; text-align: center; color: var(--ink-3, #6b7480); }
.cmdk-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3, #6b7480); }
.cmdk-foot kbd { margin-inline-end: 3px; }
