:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #4b5563;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #dbeafe;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --sidebar: #0b1220;
  --sidebar-text: #94a3b8;
  --radius: 12px;
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { display: flex; min-height: 100vh; }

/* ---------------- sidebar ---------------- */
#sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; gap: 10px; align-items: center;
  padding: 20px 16px 16px;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff; font-weight: 800; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { color: #fff; font-weight: 700; letter-spacing: .3px; }
.brand-sub { font-size: 11px; }
#nav { flex: 1; padding: 8px; overflow-y: auto; }
#nav a {
  display: block; padding: 10px 12px; margin: 2px 0;
  color: var(--sidebar-text); text-decoration: none;
  border-radius: 8px; font-size: 14px;
}
#nav a:hover { background: #16213a; color: #e2e8f0; }
#nav a.active { background: var(--primary); color: #fff; }
.nav-divider { height: 1px; background: #1e293b; margin: 10px 12px; }
.sidebar-footer { padding: 14px 16px; font-size: 11px; line-height: 1.6; color: #475569; }

/* ---------------- main ---------------- */
#main { flex: 1; padding: 24px 28px; min-width: 0; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 22px; }
.page-header p { color: var(--muted); font-size: 13px; margin-top: 3px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin-bottom: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat .num { font-size: 26px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.primary .num { color: var(--primary); }
.stat.green .num { color: var(--green); }
.stat.amber .num { color: var(--amber); }
.stat.red .num { color: var(--red); }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 9px 10px; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:hover td { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px !important; }

/* ---------------- badges ---------------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.gray { background: #e2e8f0; color: #475569; }

/* ---------------- buttons & forms ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: #fff; border: none;
  padding: 9px 16px; border-radius: 8px; font-size: 13.5px;
  cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f8fafc; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn.approve { background: var(--green); }
.btn.approve:hover { background: #047857; }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13.5px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 3px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.toolbar input { min-width: 220px; }

/* ---------------- modal ---------------- */
#modal-root {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 720px;
  padding: 24px; box-shadow: 0 25px 60px rgba(0,0,0,.25);
}
.modal h3 { margin-bottom: 16px; font-size: 17px; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.toast.err { background: var(--red); }
.toast-dismiss { background: none; border: none; color: inherit; opacity: .75; cursor: pointer; font-size: 17px; line-height: 1; padding: 0 0 0 10px; vertical-align: middle; }
.toast-dismiss:hover { opacity: 1; }
.hidden { display: none !important; }

/* ---------------- keyboard focus & loading state ---------------- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.page-loading { display: flex; align-items: center; justify-content: center; gap: 7px; height: 200px; }
.page-loading span { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); animation: pl-pulse 1s ease-in-out infinite; }
.page-loading span:nth-child(2) { animation-delay: .15s; }
.page-loading span:nth-child(3) { animation-delay: .3s; }
@keyframes pl-pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

/* ---------------- policies ---------------- */
.policy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.policy-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.policy-card h3 { font-size: 15px; margin-bottom: 6px; }
.policy-card .desc { color: var(--muted); font-size: 13px; line-height: 1.55; margin-bottom: 12px; }
.policy-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: #f1f5f9; border-radius: 6px; padding: 4px 8px; font-size: 11.5px; color: #334155; }
.tag b { color: var(--primary); }

/* ---------------- letters ---------------- */
.letter-preview {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 34px 40px; font-family: Georgia, 'Times New Roman', serif;
  font-size: 14px; line-height: 1.7; white-space: pre-wrap; max-width: 820px; margin: 0 auto;
}
.letterhead {
  text-align: center; border-bottom: 3px double #1e3a8a;
  padding-bottom: 12px; margin-bottom: 24px;
}
.letterhead .co-name { font-size: 20px; font-weight: 700; color: #1e3a8a; letter-spacing: 1px; }
.letterhead .co-sub { font-size: 11.5px; color: #475569; margin-top: 2px; }
.balance-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.bar { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; flex: 1; margin: 0 14px; }
.bar > div { height: 100%; background: var(--primary); border-radius: 999px; }
.bar > div.low { background: var(--red); }

@media (max-width: 900px) {
  #sidebar { width: 64px; }
  .brand-name, .brand-sub, #nav a, .sidebar-footer { font-size: 0; }
  #nav a { text-align: center; font-size: 16px; }
  .brand-name::after, .sidebar-footer { display: none; }
  #main { padding: 16px; }
}

/* ---------------- auth (sign in / password change) ---------------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 0%, #1e3a8a 0%, #0b1220 55%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 430px; background: var(--card);
  border-radius: 16px; padding: 32px; box-shadow: 0 24px 60px rgba(2, 6, 23, .45);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13px; line-height: 1.55; margin-bottom: 22px; }
.auth-field { margin-bottom: 16px; }
.auth-card label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 6px; }
.auth-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 9px; font-size: 14px; font-family: inherit; background: #fff;
}
.auth-card input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.auth-card .btn { width: 100%; justify-content: center; }
.auth-error {
  background: var(--red-soft); color: #991b1b; border: 1px solid #fecaca;
  padding: 10px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 16px;
}
.auth-hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 18px; text-align: center; }

/* ---------------- signed-in user block ---------------- */
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(148, 163, 184, .15); }
.who { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.who b { color: #e2e8f0; font-size: 13px; }
.role-chip {
  align-self: flex-start; background: rgba(29, 78, 216, .3); color: #93c5fd;
  border-radius: 999px; padding: 2px 9px; font-size: 11px; text-transform: capitalize;
}
.btn.block { width: 100%; justify-content: center; }
.build { margin-top: 10px; font-size: 11px; color: #475569; }

/* ---------------- print ---------------- */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    position: absolute; inset: 0; margin: 0; padding: 24px 30px;
    max-width: none; border: none; box-shadow: none;
  }
  .no-print { display: none !important; }
}

/* checkboxes inside form fields */
.field label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin: 22px 0 0; cursor: pointer; }
.field label.check input { width: auto; margin: 0; }
.field label.check.inline { display: inline-flex; margin: 4px 12px 0 0; }

/* role × permission matrix */
.perm-grid td, .perm-grid th { text-align: center; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; }
.perm-grid .perm-cat { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f8fafc; }
.sidebar-footer .btn.block + .btn.block { margin-top: 6px; }

/* ---------------- workplace modules ---------------- */
.side-search { padding: 0 12px 6px; }
.side-search input {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #1e293b;
  background: #111a2e; color: #e2e8f0; font-size: 13px;
}
.side-search input::placeholder { color: #64748b; }
.nav-count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px;
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 14px; font-size: 13.5px; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
}
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }
.notif { display: flex; gap: 12px; padding: 12px 6px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.notif:hover { background: #f8fafc; }
.notif.unread { background: #f8fbff; }
.notif.unread .notif-title { font-weight: 700; }
.notif .dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; flex-shrink: 0; }
.notif.unread .dot { background: var(--primary); }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; margin: 10px 0; }
.thread .msg { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; }
.thread .msg.internal { background: var(--amber-soft); border-color: #fde68a; }
.thread .msg .msg-who { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.timeline { list-style: none; border-left: 2px solid var(--border); margin: 8px 0 0 6px; padding-left: 14px; font-size: 12.5px; }
.timeline li { margin-bottom: 8px; }
.doc-body { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 14px; font-size: 13.5px; line-height: 1.6; max-height: 360px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }

/* ------------------------------------------------ two-factor sign-in */
.enrol-steps { padding-left: 18px; font-size: 13.5px; line-height: 1.5; }
.enrol-steps li { margin-bottom: 10px; }
.setup-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; letter-spacing: 0.5px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin: 8px 0 4px; user-select: all; word-break: break-all;
}
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 10px 0 16px; user-select: all; }
.recovery-codes code { font-size: 14px; padding: 6px 8px; background: var(--bg); border-radius: 6px; text-align: center; }

/* ------------------------------------------------------- org chart */
.org-tree, .org-tree ul { list-style: none; margin: 0; padding-left: 22px; }
.org-tree { padding-left: 0; }
.org-tree ul { border-left: 2px solid var(--border); margin-left: 10px; }
.org-tree li { margin: 8px 0; position: relative; }
.org-tree ul > li::before {
  content: ''; position: absolute; left: -22px; top: 18px; width: 18px; border-top: 2px solid var(--border);
}
.org-node {
  display: inline-block; background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; min-width: 200px; font-size: 13px;
}

/* ---------------------------------------------------------- roster */
.roster td, .roster th { text-align: center; white-space: nowrap; }
.roster td:first-child, .roster th:first-child { text-align: left; }
.roster-cell { display: inline-block; font-size: 11.5px; padding: 2px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.roster-cell.shift { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.roster-cell.off { background: transparent; }
.roster-cell.holiday { background: var(--amber-soft); color: var(--amber); }
.roster-cell.leave { background: var(--green-soft); color: var(--green); }

/* ---------------------------------------------------- people picker */
.people-picker { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.picker-group { margin-bottom: 8px; }
.picker-group > .check:not(:first-child) { display: block; margin-left: 22px; font-weight: 400; }

/* ------------------------------------------------------- email preview */
.email-preview { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
.email-preview pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; margin: 4px 0 0; }

/* ------------------------------------------------------- workflows */
.wf-steps { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.wf-step { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 180px; font-size: 13px; background: var(--card); }
.wf-chain { margin: 6px 0 0; padding-left: 20px; font-size: 13.5px; line-height: 1.7; }
.wf-design input, .wf-design select { font-size: 12.5px; }
/* The designers need room for every column. */
.modal:has(.wf-design), .modal:has(#ff-rows) { max-width: min(1150px, 96vw); width: 96vw; }

/* New-joiner registration: lifecycle steps, form sections, document checklist. */
.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 0; margin: 4px 0 16px; padding: 0; font-size: 12.5px; color: var(--muted); }
.stepper li { display: flex; align-items: center; gap: 6px; padding-right: 22px; position: relative; }
.stepper li:not(:last-child)::after { content: ''; position: absolute; right: 6px; top: 50%; width: 10px; border-top: 2px solid var(--border); }
.stepper .dot { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--border); color: var(--muted); font-weight: 700; font-size: 11px; }
.stepper li.done .dot { background: var(--green-soft); color: var(--green); }
.stepper li.current { color: var(--text); font-weight: 600; }
.stepper li.current .dot { background: var(--primary); color: #fff; }
.stepper.stopped { display: block; color: var(--red); font-weight: 600; }
.form-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 12px; }
.form-section legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.doc-checklist { list-style: none; padding: 0; margin: 6px 0 10px; font-size: 13px; }
.doc-checklist li { margin: 3px 0; color: var(--muted); }
.doc-checklist li.ok { color: var(--green); }
.notice { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; background: var(--amber-soft); color: #78350f; }
.notice.info { background: var(--primary-soft); color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card { margin-top: 16px; }
