@import url('https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Barlow+Condensed:wght@500;600;700&display=swap');

:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-surface-alt: #f4f6f8;
  --color-border: #e6eaee;
  --color-text: #0d0f12;
  --color-text-muted: #5b646d;
  --color-text-faint: #7e8892;

  --color-primary: #12557f;
  --color-primary-hover: #0f4a70;
  --color-primary-soft: #e6eef4;
  --color-accent: #12557f;
  --color-accent-100: #e6eef4;
  --color-accent-200: #c4d8e6;
  --color-accent-700: #0c3b5a;
  --color-accent-800: #092c43;

  --color-accent-2: #1c8a63;
  --color-accent-2-100: #e4f3ed;
  --color-accent-2-200: #bfe3d5;
  --color-accent-2-700: #125f45;
  --color-accent-2-800: #0d4633;

  --color-danger: #9a3324;
  --color-danger-soft: #f7e9e6;
  --color-danger-border: #e3c3ba;
  --color-success: #1c8a63;
  --color-success-soft: #e4f3ed;
  --color-warning: #8a5a00;
  --color-warning-soft: #f8eed9;
  --color-warning-border: #e6d2a0;
  --color-info-soft: #e6eef4;

  --color-neutral-100: #f4f6f8;
  --color-neutral-200: #e6eaee;
  --color-neutral-300: #d2d8de;
  --color-neutral-400: #aab3bc;
  --color-neutral-500: #7e8892;
  --color-neutral-600: #5b646d;
  --color-neutral-700: #3a424a;
  --color-neutral-800: #20262c;
  --color-neutral-900: #0d0f12;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(20, 30, 45, 0.08);
  --shadow-md: 0 4px 14px rgba(20, 30, 45, 0.10);
  --shadow-lg: 0 10px 34px rgba(20, 30, 45, 0.16);

  /* ---------- Glassmorphism tokens — "white morphism" in light mode, "black morphism" once the
     dark overrides near the bottom of this file kick in (system preference or the shell's manual
     toggle — see public/js/shell.js and the inline theme-init script each page's <head> now has). ---------- */
  --glass-bg: rgba(255, 255, 255, 0.6);
  --glass-bg-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-blur: blur(16px);
  color-scheme: light;

  --sidebar-w: 222px;
  --topbar-h: 70px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-heading: "Barlow Condensed", var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(160deg, #f4f7fb 0%, #eef2f7 50%, #f7f5f1 100%);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}
/* Soft, blurred colour blobs fixed behind everything — this is what makes every translucent
   sidebar/card/drawer below actually read as "glass" rather than just plain white/black. */
body::before, body::after {
  content: ''; position: fixed; z-index: -1; border-radius: 50%; filter: blur(90px); pointer-events: none;
}
body::before { width: 480px; height: 480px; top: -140px; left: -120px; background: color-mix(in srgb, var(--color-primary) 26%, transparent); }
body::after { width: 440px; height: 440px; bottom: -160px; right: -120px; background: color-mix(in srgb, var(--color-primary) 18%, transparent); }
a { color: var(--color-primary); text-underline-offset: 3px; }
h1, h2, h3, h4 {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
p { margin: 0 0 8px; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
::selection { background: color-mix(in srgb, var(--color-primary) 25%, transparent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--color-neutral-300); }

/* ---------- App shell ---------- */
#shell-root { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}
.sidebar-brand {
  padding: 14px 18px 16px;
  display: flex; align-items: center; gap: 9px;
}
.sidebar-brand .mark {
  width: 20px; height: 20px; flex: none;
  border: 1.5px solid var(--color-primary);
}
/* Crops just the emblem out of the full lockup logo (549×230, emblem occupies the left ~35–205px)
   for compact spots — sidebar brand, login mark — where the full wordmark won't fit. */
.brand-mark-crop {
  width: 27px; height: 32px; flex: none; overflow: hidden;
  background-image: url('/img/default-logo.png');
  background-repeat: no-repeat;
  background-size: auto 32px;
  background-position: -5px center;
}
.sidebar-brand .brand-text {
  font-family: var(--font-heading); font-weight: 600; font-size: 16px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-primary);
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.sidebar-group-label {
  font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.13em;
  color: var(--color-neutral-500); padding: 14px 9px 5px;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px; border-radius: var(--radius-sm);
  color: var(--color-neutral-700); text-decoration: none; font-size: 13px; font-weight: 500;
  margin: 1px 0;
}
.sidebar-link:hover { background: color-mix(in srgb, var(--color-primary) 8%, transparent); color: var(--color-text); }
.sidebar-link.active { background: var(--color-accent-100); color: var(--color-accent-800); font-weight: 600; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--glass-border); font-size: 10px; line-height: 1.5; color: var(--color-neutral-500); }

.topbar {
  min-height: var(--topbar-h);
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  display: flex; align-items: stretch;
  padding: 0;
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.hamburger {
  display: none;
  border: none; background: none; cursor: pointer;
  width: 44px; flex: none;
  align-items: center; justify-content: center;
  font-size: 18px; color: var(--color-text);
}
.org-lockup {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-right: 1px solid var(--glass-border);
  flex: none;
}
.org-logo { height: 42px; width: auto; display: block; }
.topbar-title {
  align-self: center;
  padding: 10px 18px;
  font-family: var(--font-heading); font-size: 19px; font-weight: 600;
}
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 18px; margin-left: auto; }
.topbar-search { width: 190px; }
.viewing-as { display: flex; align-items: center; gap: 7px; }
.viewing-as-label { font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-neutral-500); }
.viewing-as-role { font-size: 12.5px; font-weight: 600; color: var(--color-text); }
.live-indicator { display: flex; align-items: center; gap: 7px; font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--color-neutral-600); white-space: nowrap; }
.live-dot { width: 8px; height: 8px; background: var(--color-accent-2); display: block; }
.live-clock { color: var(--color-neutral-500); text-transform: none; letter-spacing: 0; font-size: 12px; }
.btn-icon { width: 34px; height: 34px; padding: 0 !important; }

.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; flex: none;
  background: var(--color-neutral-200); border: 1px solid var(--color-neutral-300);
  color: var(--color-text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-weight: 600; font-size: 13px;
}
.avatar-photo { background-size: cover; background-position: center; }
.user-meta { line-height: 1.25; }
.user-meta .name { font-size: 13px; font-weight: 600; }
.user-meta .role { font-size: 11px; color: var(--color-text-muted); letter-spacing: 0.03em; }

.main-col { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.page { padding: 22px 26px 60px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-sub { color: var(--color-text-muted); font-size: 12.5px; letter-spacing: 0.02em; }

.sidebar-scrim { display: none; }

@media (max-width: 1180px) {
  .topbar-search { display: none; }
  .live-indicator .live-clock { display: none; }
}
@media (max-width: 980px) {
  .viewing-as { display: none; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-col { margin-left: 0; }
  .hamburger { display: flex; }
  .org-logo { height: 28px; }
  .org-lockup { padding: 10px 12px; }
  .live-indicator { display: none; }
  .user-meta { display: none; }
  .sidebar-scrim.open {
    display: block; position: fixed; inset: 0; background: rgba(13, 15, 18, 0.45); z-index: 30;
  }
  .page { padding: 16px 14px 50px; }
  .topbar-right { gap: 8px; }
}

/* ---------- Components ---------- */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
@media (min-width: 901px) and (max-width: 1180px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }

/* KPI / "blueprint" stat cards — corner registration marks via layered gradients, no extra markup.
   Shared with .modal (capture dialogs) and .drawer-blueprint (reference panels) for one consistent motif. */
.kpi, .modal, .drawer-corners {
  position: relative;
  background-color: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  background-repeat: no-repeat;
  background-image:
    linear-gradient(var(--color-accent), var(--color-accent)), linear-gradient(var(--color-accent), var(--color-accent)),
    linear-gradient(var(--color-accent), var(--color-accent)), linear-gradient(var(--color-accent), var(--color-accent)),
    linear-gradient(var(--color-accent), var(--color-accent)), linear-gradient(var(--color-accent), var(--color-accent)),
    linear-gradient(var(--color-accent), var(--color-accent)), linear-gradient(var(--color-accent), var(--color-accent));
  background-size: 1.5px 11px, 11px 1.5px, 1.5px 11px, 11px 1.5px, 1.5px 11px, 11px 1.5px, 1.5px 11px, 11px 1.5px;
  background-position: 0 0, 0 0, 100% 0, 100% 0, 0 100%, 0 100%, 100% 100%, 100% 100%;
}
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-primary); }
.kpi .value { font-family: var(--font-heading); font-size: 30px; font-weight: 600; line-height: 1.1; }
.kpi .delta { font-size: 12px; color: var(--color-accent-2); }
.kpi .delta.down { color: var(--color-danger); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border-radius: var(--radius-sm); padding: 9px 15px;
  font-family: var(--font-heading); font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  border: 1px solid transparent; text-decoration: none;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow-md); }
.btn-ghost { background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur); border-color: var(--glass-border); color: var(--color-primary); }
.btn-ghost:hover { background: var(--color-accent-100); }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-sm { padding: 6px 11px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  border: 1px solid transparent;
}
.badge-success { background: var(--color-success-soft); color: var(--color-accent-2-700); border-color: var(--color-accent-2-200); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); border-color: var(--color-warning-border); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); border-color: var(--color-danger-border); }
.badge-info { background: var(--color-accent-100); color: var(--color-accent-800); border-color: var(--color-accent-200); }
.badge-neutral { background: transparent; color: var(--color-neutral-600); border-color: var(--color-neutral-300); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { overflow-x: auto; }
th {
  text-align: left; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--color-neutral-600); background: color-mix(in srgb, var(--color-text) 4%, transparent);
  padding: 10px 12px; border-bottom: 1px solid var(--glass-border); white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid color-mix(in srgb, var(--color-text) 7%, transparent); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-neutral-600); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
input, select, textarea {
  border: 1px solid color-mix(in srgb, var(--color-text) 14%, transparent); border-radius: var(--radius-sm);
  padding: 8px 10px; background: color-mix(in srgb, var(--color-surface) 55%, transparent); color: var(--color-text); width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input:hover, select:hover, textarea:hover { background: color-mix(in srgb, var(--color-surface) 80%, transparent); }
input:focus, select:focus, textarea:focus { outline: none; background: var(--color-surface); border-color: var(--color-primary); }
.field-hint { font-size: 11px; color: var(--color-text-faint); }
.field-error { font-size: 11px; color: var(--color-danger); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  padding: 7px 14px; font-size: 12.5px; font-weight: 500; color: var(--color-neutral-700);
  cursor: pointer; background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: 999px;
  white-space: nowrap;
}
.tab.active { color: #fff; background: var(--color-primary); border-color: var(--color-primary); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.search-input { flex: 1; min-width: 200px; }

@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-scrim { position: fixed; inset: 0; background: rgba(20, 30, 45, 0.3); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 60; overflow-y: auto; }
.modal {
  border-radius: var(--radius-lg); max-width: 640px; width: 100%;
  box-shadow: var(--shadow-lg); animation: tin 0.18s ease-out;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--glass-border); }
.modal-head strong { font-family: var(--font-heading); font-size: 19px; font-weight: 600; line-height: 1.15; display: block; }
.modal-note { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; line-height: 1.5; font-weight: 400; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--glass-border); }
.modal-foot .btn-primary { flex: 1; justify-content: center; }
.modal-close { border: none; background: none; cursor: pointer; font-size: 18px; color: var(--color-text-muted); flex: none; }

/* Wide variant for content that needs real estate — report previews (an iframed formal document). */
.modal-xl { max-width: 1080px; }
.modal-xl .modal-body { max-height: none; padding: 0; }
.report-preview-frame { width: 100%; height: 78vh; border: none; display: block; background: #fff; }
.report-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.report-picker label { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--glass-border); border-radius: var(--radius-sm); background: var(--glass-bg); cursor: pointer; font-size: 12.5px; }
.report-picker input { width: auto; }
.report-picker label.checked { border-color: var(--color-primary); background: var(--color-accent-100); }
.rb-block { border: 1px solid var(--glass-border); border-radius: var(--radius-md); padding: 14px 16px; margin-top: 12px; }
.rb-block h4 { margin: 0 0 2px; font-size: 13.5px; }
.rb-block .rb-desc { font-size: 11.5px; color: var(--color-text-muted); margin-bottom: 10px; }

.section-title { font-family: var(--font-heading); font-size: 15px; font-weight: 600; color: var(--color-primary); text-transform: uppercase; letter-spacing: 0.05em; }
.chart-card h3 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chart-card h3 .chart-total { font-size: 12px; font-weight: 500; color: var(--color-text-muted); text-transform: none; letter-spacing: normal; }
/* Grid items default to min-width:auto, so once Chart.js sizes a canvas to its container's
   initial (desktop) width, that becomes the grid item's shrink floor — the track can't narrow
   it on a smaller viewport and the whole row overflows instead of the chart reflowing down.
   min-width:0 down the chain (grid item -> wrap -> canvas) removes that floor. */
.chart-card, .chart-canvas-wrap { min-width: 0; }
.chart-canvas-wrap { position: relative; height: 240px; margin-top: 6px; }
.chart-canvas-wrap.short { height: 190px; }
.chart-canvas-wrap canvas { max-width: 100%; }
.chart-card .empty-state { padding: 60px 10px; }

.setup-banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--color-warning-soft); border: 1px solid var(--color-warning-border);
  color: var(--color-warning); padding: 10px 22px; font-size: 12.5px;
}
.setup-banner strong { font-weight: 700; }
.setup-banner a { color: var(--color-warning); text-decoration: underline; font-weight: 600; }
.setup-banner .btn { margin-left: auto; }

/* ---------- Side drawer (Teams/prototype-style reference panel) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(20, 30, 45, 0.28); backdrop-filter: blur(2px); z-index: 65; display: flex; justify-content: flex-end; }
.drawer {
  width: min(480px, 100%); height: 100%;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 16px;
  animation: tin 0.18s ease-out;
}
.drawer-head { display: flex; align-items: flex-start; gap: 12px; }
.drawer-title { font-family: var(--font-heading); font-size: 22px; line-height: 1.15; font-weight: 600; }
.drawer-sub { font-size: 12px; color: var(--color-neutral-600); margin-top: 2px; }
.drawer-close { flex: none; }
.drawer-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.drawer-note { font-size: 12.5px; line-height: 1.55; color: var(--color-neutral-700); }
.drawer-group { display: flex; flex-direction: column; gap: 9px; border-top: 1px solid var(--glass-border); padding-top: 14px; }
.drawer-group-label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-primary); font-weight: 600; }
.drawer-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drawer-field-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-neutral-500); }
.drawer-field-value { font-size: 13px; margin-top: 3px; }
.drawer-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.drawer-line { font-size: 12.5px; line-height: 1.55; color: var(--color-neutral-700); padding-left: 12px; border-left: 2px solid var(--color-accent-2); }
.drawer-people-label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-primary); font-weight: 600; margin-bottom: 4px; }
.drawer-person-row {
  display: flex; align-items: center; gap: 11px; padding: 10px 4px;
  border-bottom: 1px solid var(--glass-border); cursor: pointer;
}
.drawer-person-row:hover { background: var(--color-accent-100); }
.drawer-person-avatar { width: 28px; height: 28px; flex: none; background: var(--color-neutral-200); border: 1px solid var(--color-neutral-300); }
.drawer-person-name { font-size: 13px; font-weight: 500; }
.drawer-person-meta { font-size: 11px; color: var(--color-neutral-600); }
.drawer-person-open { font-size: 12px; color: var(--color-primary); flex: none; }
@media (max-width: 560px) { .drawer { width: 100%; } }

/* ---------- Org chart / "works with" cards ---------- */
.org-chart { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0 6px; }
.org-chart-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.org-chart-connector { width: 1.5px; height: 20px; background: var(--color-neutral-300); }
.org-person-card {
  width: 190px;
  background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; cursor: pointer;
}
.org-person-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-accent-200); }
.org-person-card.is-self { border: 1.5px solid var(--color-accent); box-shadow: var(--shadow-md); }
.org-person-avatar { width: 40px; height: 40px; background: var(--color-accent-100); border: 1px solid var(--color-accent-200); color: var(--color-accent-800); display: flex; align-items: center; justify-content: center; font-family: var(--font-heading); font-weight: 600; font-size: 14px; }
.org-person-name { font-size: 13px; font-weight: 600; }
.org-person-title { font-size: 11px; color: var(--color-neutral-600); }
.org-person-dept { font-size: 10px; color: var(--color-neutral-500); letter-spacing: 0.04em; text-transform: uppercase; }
.org-chart-label { font-size: 9.5px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--color-neutral-500); text-align: center; margin-bottom: -2px; }
.org-person-card a[data-profile-link] { color: var(--color-primary); font-size: 10.5px; text-decoration: none; }
.org-person-card a[data-profile-link]:hover { text-decoration: underline; }
.org-worksWith-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; border-top: 1px solid var(--color-neutral-200); padding-top: 16px; margin-top: 6px; width: 100%; }

.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: rgba(13, 15, 18, 0.82); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 12.5px; box-shadow: var(--shadow-lg); min-width: 220px;
}
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-accent-2); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--color-text-muted); }
.faint { color: var(--color-text-faint); font-size: 12px; }
.divider { height: 1px; background: var(--color-border); margin: 14px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-tabs .badge.clickable { cursor: pointer; }

/* ---------- Auth page ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; overflow: hidden; }
.auth-card {
  position: relative; z-index: 1;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 380px; padding: 32px 28px;
}
.auth-logo { margin-bottom: 18px; }
.auth-logo img { height: 54px; width: auto; display: block; }
.auth-title { font-family: var(--font-heading); font-size: 15px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-primary); }
.auth-sub { font-size: 12px; color: var(--color-text-muted); margin-bottom: 20px; letter-spacing: 0.02em; }

/* ---------- VoIP (real WebRTC calling, ported from FLMS/SPTS's own voip-call.js) ---------- */
/* Global call banner — fixed to the top of the viewport so it's visible regardless of which
   screen is currently open, same idea as a phone's own incoming-call UI. */
#voip-overlay { position: fixed; top: 0; left: 0; right: 0; z-index: 90; display: flex; justify-content: center; pointer-events: none; }
.voip-banner {
  pointer-events: auto; margin-top: 10px;
  background: rgba(13, 15, 18, 0.82); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  color: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; font-size: 13px;
}
.voip-banner-info { display: flex; align-items: center; gap: 8px; }
.voip-banner-actions { display: flex; gap: 8px; }
.voip-incoming { background: var(--color-accent-2); }
.voip-active { background: rgba(13, 15, 18, 0.82); }
#voip-timer { font-variant-numeric: tabular-nums; opacity: 0.8; }

/* Floating quick-dial button + popover — present on every authenticated page so a call can be
   placed without leaving whatever screen someone's on. Sits above page content but below the
   incoming-call/active-call banner (z-index 90) so an active call banner always wins. */
.voip-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 85;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--color-primary); color: #fff; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.voip-fab:hover { background: var(--color-primary-hover); transform: scale(1.05); }
.voip-fab .voip-fab-dot {
  position: absolute; top: 3px; right: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-accent-2); border: 2px solid var(--color-surface); display: none;
}
.voip-fab.has-online .voip-fab-dot { display: block; }
.voip-fab .voip-fab-unread {
  position: absolute; top: 1px; left: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--color-danger); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
  border: 2px solid var(--color-surface); display: none;
}
.voip-fab.has-unread .voip-fab-unread { display: block; }

.voip-panel {
  position: fixed; right: 22px; bottom: 86px; z-index: 85;
  width: 300px; max-height: 60vh; display: flex; flex-direction: column;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  animation: tin 0.15s ease-out;
}
.voip-panel-head { padding: 12px 14px; border-bottom: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: space-between; }
.voip-panel-head b { font-family: var(--font-heading); font-size: 14px; }
.voip-panel-list { overflow-y: auto; padding: 6px; }
.voip-panel-row { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: var(--radius-sm); }
.voip-panel-row:hover { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }
.voip-panel-row .name { font-size: 12.5px; font-weight: 600; }
.voip-panel-row .sub { font-size: 10.5px; color: var(--color-text-faint); }
.voip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-neutral-400); flex: none; }
.voip-dot.online { background: var(--color-accent-2); }
.voip-panel-foot { padding: 8px 14px; border-top: 1px solid var(--glass-border); text-align: center; }
.voip-panel-foot a { font-size: 11.5px; }
@media (max-width: 480px) { .voip-panel { right: 10px; width: calc(100vw - 20px); } .voip-fab { right: 14px; bottom: 14px; } }

/* Messages (chat.html / chat.js) — a two-pane chat: conversation list left, active thread right. */
.chat-app {
  display: flex; height: calc(100vh - 210px); min-height: 460px;
  background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden;
}
.chat-sidebar { width: 300px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--glass-border); }
.chat-sidebar-search { padding: 10px; border-bottom: 1px solid var(--glass-border); }
.chat-sidebar-search input { font-size: 12.5px; padding: 7px 10px; }
.chat-thread-list { flex: 1; overflow-y: auto; }
.chat-thread-row { display: flex; align-items: center; gap: 9px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--glass-border); }
.chat-thread-row:hover { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }
.chat-thread-row.active { background: var(--color-accent-100); }
.chat-thread-row .info { min-width: 0; flex: 1; }
.chat-thread-row .name { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.chat-thread-row .preview { font-size: 11.5px; color: var(--color-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-row .meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 10px; color: var(--color-text-faint); }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-main-head { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--glass-border); flex: none; }
.chat-main-head .info { min-width: 0; flex: 1; }
.chat-main-head .name { font-weight: 600; font-size: 13.5px; }
.chat-main-head .sub { font-size: 11px; color: var(--color-text-faint); }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 3px; background: color-mix(in srgb, var(--color-text) 3%, transparent); }
.chat-row { display: flex; }
.chat-row.mine { justify-content: flex-end; }
.chat-bubble-wrap { max-width: 62%; margin: 5px 0; display: flex; flex-direction: column; }
.chat-row.mine .chat-bubble-wrap { align-items: flex-end; }
.chat-bubble { padding: 8px 12px; font-size: 13px; line-height: 1.45; word-break: break-word; box-shadow: var(--shadow-sm); border-radius: var(--radius-md); }
.chat-bubble.theirs { background: var(--glass-bg-strong); border: 1px solid var(--glass-border); }
.chat-bubble.mine { background: var(--color-primary); color: #fff; }
.chat-bubble img { display: block; max-width: 220px; cursor: pointer; }
.chat-bubble audio { max-width: 220px; height: 32px; }
.chat-bubble-time { font-size: 10px; color: var(--color-text-faint); margin-top: 2px; }
.chat-row.mine .chat-bubble-time { text-align: right; }
.chat-call-row { align-self: center; font-size: 11.5px; color: var(--color-text-faint); background: color-mix(in srgb, var(--color-text) 6%, transparent); border-radius: 999px; padding: 4px 12px; margin: 6px 0; }
.chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--glass-border); flex: none; }
.chat-compose textarea { flex: 1; resize: none; font-size: 13px; padding: 9px 12px; max-height: 110px; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--color-text-faint); font-size: 13px; }
.chat-locked-file { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--color-text-faint); }

/* End-to-end encryption setup/unlock (chat-crypto.js) — a blocking centered dialog rather than the
   app's usual right-hand drawer, since this is a security prompt (set/enter a passphrase), not a
   record to edit. z-index above the voip banner (90) so it's never hidden behind an incoming call. */
.cc-modal-backdrop { position: fixed; inset: 0; background: rgba(20, 30, 45, 0.35); backdrop-filter: blur(2px); z-index: 95; display: flex; align-items: center; justify-content: center; padding: 16px; }
.cc-modal {
  width: min(420px, 100%);
  background: var(--glass-bg-strong); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 24px; animation: tin 0.18s ease-out;
}
.cc-modal h3 { margin: 0 0 10px; font-family: var(--font-heading); font-size: 19px; }
.cc-modal p.faint { margin: 0 0 16px; line-height: 1.55; }

/* ================================================================================
   Dark mode — "black morphism". Same glass idea as the light theme above (translucent
   panels + blur over a soft background), just inverted: dark translucent panels with a
   faint light rim, over a near-black gradient with the same blurred colour-blob accents.

   Two ways this activates:
   - Automatically, from the OS/browser's own dark mode (`prefers-color-scheme`), unless
     the user has explicitly picked "light" from the shell's theme toggle.
   - Explicitly, via `data-theme="dark"` on <html> — set by the shell's theme toggle
     (public/js/shell.js) and persisted to localStorage under "hris-theme"; each page's
     <head> has a tiny inline script that applies a saved choice before first paint, so
     there's no flash of the wrong theme.
   Every component above is built on the tokens redefined here, so nothing past this
   point needs touching for dark mode to reach it. ================================= */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-bg: #0a0c0f;
    --color-surface: #15181c;
    --color-surface-alt: #1a1e23;
    --color-border: #2a2f36;
    --color-text: #eef1f4;
    --color-text-muted: #a3abb4;
    --color-text-faint: #7a828b;

    --color-primary: #3f93c4;
    --color-primary-hover: #56a6d4;
    --color-primary-soft: rgba(63, 147, 196, 0.16);
    --color-accent: #3f93c4;
    --color-accent-100: rgba(63, 147, 196, 0.16);
    --color-accent-200: rgba(63, 147, 196, 0.34);
    --color-accent-700: #9ed3ee;
    --color-accent-800: #cfeaf8;

    --color-accent-2: #33b787;
    --color-accent-2-100: rgba(51, 183, 135, 0.16);
    --color-accent-2-200: rgba(51, 183, 135, 0.34);
    --color-accent-2-700: #7fdcb8;
    --color-accent-2-800: #bdf0dc;

    --color-danger: #e0806c;
    --color-danger-soft: rgba(224, 128, 108, 0.15);
    --color-danger-border: rgba(224, 128, 108, 0.38);
    --color-success: #33b787;
    --color-success-soft: rgba(51, 183, 135, 0.15);
    --color-warning: #e0b34d;
    --color-warning-soft: rgba(224, 179, 77, 0.15);
    --color-warning-border: rgba(224, 179, 77, 0.38);
    --color-info-soft: rgba(63, 147, 196, 0.16);

    --color-neutral-100: #1a1e23;
    --color-neutral-200: #262b31;
    --color-neutral-300: #333a42;
    --color-neutral-400: #4c545d;
    --color-neutral-500: #6d7580;
    --color-neutral-600: #8d959e;
    --color-neutral-700: #aeb6bd;
    --color-neutral-800: #d2d8dd;
    --color-neutral-900: #f2f4f6;

    --glass-bg: rgba(24, 28, 33, 0.55);
    --glass-bg-strong: rgba(24, 28, 33, 0.78);
    --glass-border: rgba(255, 255, 255, 0.09);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0a0c0f;
  --color-surface: #15181c;
  --color-surface-alt: #1a1e23;
  --color-border: #2a2f36;
  --color-text: #eef1f4;
  --color-text-muted: #a3abb4;
  --color-text-faint: #7a828b;

  --color-primary: #3f93c4;
  --color-primary-hover: #56a6d4;
  --color-primary-soft: rgba(63, 147, 196, 0.16);
  --color-accent: #3f93c4;
  --color-accent-100: rgba(63, 147, 196, 0.16);
  --color-accent-200: rgba(63, 147, 196, 0.34);
  --color-accent-700: #9ed3ee;
  --color-accent-800: #cfeaf8;

  --color-accent-2: #33b787;
  --color-accent-2-100: rgba(51, 183, 135, 0.16);
  --color-accent-2-200: rgba(51, 183, 135, 0.34);
  --color-accent-2-700: #7fdcb8;
  --color-accent-2-800: #bdf0dc;

  --color-danger: #e0806c;
  --color-danger-soft: rgba(224, 128, 108, 0.15);
  --color-danger-border: rgba(224, 128, 108, 0.38);
  --color-success: #33b787;
  --color-success-soft: rgba(51, 183, 135, 0.15);
  --color-warning: #e0b34d;
  --color-warning-soft: rgba(224, 179, 77, 0.15);
  --color-warning-border: rgba(224, 179, 77, 0.38);
  --color-info-soft: rgba(63, 147, 196, 0.16);

  --color-neutral-100: #1a1e23;
  --color-neutral-200: #262b31;
  --color-neutral-300: #333a42;
  --color-neutral-400: #4c545d;
  --color-neutral-500: #6d7580;
  --color-neutral-600: #8d959e;
  --color-neutral-700: #aeb6bd;
  --color-neutral-800: #d2d8dd;
  --color-neutral-900: #f2f4f6;

  --glass-bg: rgba(24, 28, 33, 0.55);
  --glass-bg-strong: rgba(24, 28, 33, 0.78);
  --glass-border: rgba(255, 255, 255, 0.09);
}

/* Dark-mode body backdrop — deep near-black gradient, same blurred blobs (brighter, since a
   dark ground can carry more saturated colour) as the light theme's body::before/::after. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) body {
    background: linear-gradient(160deg, #0a0c0f 0%, #0d1013 50%, #10151a 100%);
  }
  html:not([data-theme="light"]) body::before { background: color-mix(in srgb, var(--color-primary) 34%, transparent); }
  html:not([data-theme="light"]) body::after { background: color-mix(in srgb, var(--color-primary) 24%, transparent); }
}
html[data-theme="dark"] body {
  background: linear-gradient(160deg, #0a0c0f 0%, #0d1013 50%, #10151a 100%);
}
html[data-theme="dark"] body::before { background: color-mix(in srgb, var(--color-primary) 34%, transparent); }
html[data-theme="dark"] body::after { background: color-mix(in srgb, var(--color-primary) 24%, transparent); }
