/* =========================================================================
   DESIGN TOKENS
   ========================================================================= */
:root {
  /* surfaces */
  --bg: #FFFFFF;
  --bg-cream: #FAF7F2;
  --bg-subtle: #F7F4EE;
  --bg-hover: #F1ECE1;
  --bg-elevated: #FFFFFF;

  /* text */
  --fg: #0A0A0A;
  --fg-secondary: #3F3F46;
  --fg-muted: #71717A;
  --fg-subtle: #A1A1AA;

  /* borders */
  --border: #E9E3D5;
  --border-soft: #F0EBDD;
  --border-strong: #D4CDBB;

  /* brand (default; overridden per org) */
  --brand: #0A0A0A;
  --brand-fg: #FFFFFF;
  --brand-hover: #27272A;
  --brand-soft: #F4F4F5;

  /* semantic */
  --success: #15803D;
  --success-soft: #DCFCE7;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --warning: #B45309;
  --warning-soft: #FEF3C7;
  --info: #1D4ED8;
  --info-soft: #DBEAFE;

  /* layout */
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* typography */
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* shadows — subtle only */
  --shadow-sm: 0 1px 2px rgba(10, 10, 10, 0.04);
  --shadow: 0 4px 12px rgba(10, 10, 10, 0.06);
  --shadow-lg: 0 12px 40px rgba(10, 10, 10, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Nothing may push the document wider than the screen. `clip` (not `hidden`)
   stops the page-level horizontal scroll without turning the root into a scroll
   container — so the sticky topbar and the fixed off-canvas sidebar keep
   working, and designated `.table-wrap` regions still scroll internally. */
html { overflow-x: clip; max-width: 100%; }
body {
  overflow-x: clip;
  max-width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; padding: 0; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
svg { flex-shrink: 0; }

/* =========================================================================
   TYPOGRAPHY
   ========================================================================= */
.serif { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.01em; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 26px; }
.text-3xl { font-size: 34px; }
.text-4xl { font-size: 44px; }
.text-5xl { font-size: 56px; }

.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.secondary { color: var(--fg-secondary); }
.text-center { text-align: center; }
.text-right { text-align: right; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* =========================================================================
   LAYOUT HELPERS
   ========================================================================= */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none !important; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1; min-width: 0; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.gap-8 { gap: 32px; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-w-0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded { border-radius: var(--radius); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: 999px; }

.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; } .mb-8 { margin-bottom: 32px; }

.p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; }
.p-6 { padding: 24px; } .p-8 { padding: 32px; }
.px-2 { padding-left: 8px; padding-right: 8px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.px-6 { padding-left: 24px; padding-right: 24px; }
.py-1 { padding-top: 4px; padding-bottom: 4px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-3 { padding-top: 12px; padding-bottom: 12px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }

/* =========================================================================
   BUTTONS
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  border: 1px solid transparent;
  transition: background 120ms, border-color 120ms, color 120ms, transform 100ms;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  color: var(--brand-fg);
  border-color: var(--brand);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-secondary {
  background: var(--bg);
  color: var(--fg);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-strong); }

.btn-ghost {
  background: transparent;
  color: var(--fg-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-subtle); color: var(--fg); }

.btn-danger {
  background: var(--bg);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 11px 18px; font-size: 14px; }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; }

/* =========================================================================
   FORM FIELDS
   ========================================================================= */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12px; font-weight: 500; color: var(--fg-secondary); }
.field .hint { font-size: 11px; color: var(--fg-muted); }
.field .error { font-size: 11px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 13px;
  color: var(--fg);
  transition: border-color 120ms, box-shadow 120ms;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.06);
}
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }

.input-group { position: relative; }
.input-group .input-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--fg-muted); pointer-events: none; }
.input-group .input { padding-left: 34px; }

/* Password show/hide eye button */
.pw-field { position: relative; }
.pw-field .input { padding-right: 40px; }
.pw-field .pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: transparent; border: 0; padding: 6px; color: var(--fg-muted); cursor: pointer; display: inline-flex; align-items: center; line-height: 0; border-radius: 4px; }
.pw-field .pw-toggle:hover { color: var(--fg); background: var(--bg-cream); }

/* Checkbox / toggle */
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox input { appearance: none; width: 16px; height: 16px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--bg); transition: 120ms; }
.checkbox input:checked { background: var(--brand); border-color: var(--brand); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E"); background-position: center; background-repeat: no-repeat; background-size: 12px; }

.toggle { position: relative; display: inline-block; width: 32px; height: 18px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: 160ms; cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; height: 14px; width: 14px; left: 2px; top: 2px; background: white; border-radius: 50%; transition: 160ms; }
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(14px); }

/* =========================================================================
   CARDS & CONTAINERS
   ========================================================================= */
.card {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
}
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border-soft); }

/* =========================================================================
   BADGES
   ========================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  border: 1px solid var(--border-soft);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-neutral { background: var(--bg-subtle); color: var(--fg-muted); border-color: transparent; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Stat card (used on project overview + elsewhere) */
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 4px; font-family: 'DM Sans', system-ui; }

/* Description list (used on overview detail panels) */
.dl { margin: 0; display: grid; grid-template-columns: 1fr; gap: 8px; }
.dl > div { display: grid; grid-template-columns: 140px 1fr; gap: 12px; align-items: baseline; }
.dl dt { font-size: 12px; color: var(--fg-muted); margin: 0; }
.dl dd { margin: 0; font-size: 14px; color: var(--fg-primary); }

/* Simple list row (e.g. retention tranches) */
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border-soft); gap: 12px;
}
.list-row:last-child { border-bottom: none; }

/* Plain styled link (distinct from .btn) */
.link { color: var(--brand, var(--fg-primary)); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Search highlight */
mark { background: #FFF3B0; color: inherit; padding: 0 2px; border-radius: 2px; }

/* Chevron affordance on clickable list rows */
.chevron { color: var(--fg-muted); display: inline-flex; align-items: center; }

/* Comms chat layout */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  min-height: calc(100vh - 220px);
}
@media (max-width: 720px) { .chat-layout { grid-template-columns: 1fr; } }
.chat-sidebar {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.chat-sidebar-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-channel-item {
  padding: 10px 16px; cursor: pointer; border-left: 3px solid transparent;
  display: flex; align-items: center; gap: 8px;
}
.chat-channel-item:hover { background: var(--bg-subtle); }
.chat-channel-item.active { background: var(--bg-subtle); border-left-color: var(--brand); font-weight: 500; }
.chat-channel-item .hash { color: var(--fg-muted); }
.chat-main {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-main-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-message { display: flex; gap: 10px; }
.chat-message .avatar { width: 32px; height: 32px; font-size: 12px; flex-shrink: 0; }
.chat-message-body { flex: 1; min-width: 0; }
.chat-message-meta { font-size: 12px; color: var(--fg-muted); margin-bottom: 2px; }
.chat-message-meta strong { color: var(--fg-primary); font-weight: 500; }
.chat-message-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; }
.chat-message-actions { opacity: 0; transition: opacity 0.1s; display: flex; gap: 4px; margin-top: 4px; }
.chat-message:hover .chat-message-actions { opacity: 1; }
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-subtle); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 2px 8px; font-size: 12px; cursor: pointer;
}
.reaction-pill.mine { background: var(--brand); color: var(--brand-fg); border-color: transparent; }
.chat-composer {
  border-top: 1px solid var(--border-soft); padding: 12px 16px;
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-composer textarea {
  flex: 1; min-height: 36px; max-height: 160px; resize: none;
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 8px 12px; font: inherit; font-size: 14px; background: var(--bg);
  color: var(--fg-primary);
}

/* Payslip editor — itemized allowance / deduction / loan rows.
   Classes (not inline styles) so the amount field can go responsive. */
.ps-item-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.ps-item-label { flex: 1; min-width: 0; }
.ps-item-amt { width: 130px; flex: none; }
.ps-loan-name { flex: 1; min-width: 0; font-size: 13px; }
.ps-ded-row { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 8px; margin-bottom: 6px; }
.ps-ded-row .ps-item-row { margin-bottom: 0; }
.ps-ded-reason { width: 100%; margin-top: 6px; font-size: 12px; }

/* Responsive table → cards. Opt a table in with `.table-cards` (+ its wrapper
   `.table-cards-wrap`) and give each <td> a data-label. Below 640px each row
   becomes a stacked label/value card instead of horizontally scrolling. */
@media (max-width: 640px) {
  .table-cards-wrap { overflow: visible; border: none; background: transparent; border-radius: 0; }
  .table-cards thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .table-cards, .table-cards tbody { display: block; }
  .table-cards tbody tr {
    display: block;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    background: var(--bg);
    padding: 4px 14px;
    margin-bottom: 10px;
  }
  .table-cards tbody tr:hover { background: var(--bg); }
  .table-cards tbody tr:last-child td { border-bottom: none; }  /* override base rule scoping */
  .table-cards td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 9px 0;
    text-align: right;
    border-bottom: 1px solid var(--border-soft);
    white-space: normal;
    /* Long unbreakable values (emails, account numbers, codes) wrap to the next
       line instead of forcing the card — and the page — wider than the screen. */
    overflow-wrap: anywhere;
    min-width: 0;
  }
  .table-cards td:last-child { border-bottom: none; }
  .table-cards td::before {
    content: attr(data-label);
    text-align: left;
    flex: 0 0 auto;
    font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--fg-muted);
  }
  /* Cells with no label (chevron, action buttons) span full width, right-aligned. */
  .table-cards td[data-label=""]::before, .table-cards td:not([data-label])::before { content: none; }
  .table-cards td[data-label=""] { justify-content: flex-end; padding-top: 4px; }
  /* When the stacked table sits directly inside a .card (no card-body padding),
     inset the item-cards so they float inside the section border. */
  .card > .table-cards-wrap { padding: 12px 12px 2px; }
  /* Same inset when nested in a padding-0 card-body (e.g. the #/me cards). */
  .card-body > .table-cards-wrap { padding: 4px 12px 10px; }
}

/* =========================================================================
   TABLES
   ========================================================================= */
.table-wrap {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg);
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
.table th {
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  background: var(--bg-subtle);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 100ms; }
.table tbody tr:hover { background: var(--bg-subtle); }
.table .row-actions { opacity: 0; transition: opacity 120ms; }
.table tr:hover .row-actions { opacity: 1; }

/* =========================================================================
   AVATAR
   ========================================================================= */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  border: 1px solid var(--border-soft);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 48px; height: 48px; font-size: 15px; }
.avatar-xl { width: 64px; height: 64px; font-size: 20px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* =========================================================================
   APP SHELL
   ========================================================================= */
#app {
  min-height: 100vh;
  background: var(--bg-cream);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  position: relative;   /* anchors the org-switcher dropdown (position:absolute) */
}
.org-switcher { transition: background 120ms; }
.org-switcher:hover { background: var(--bg-subtle); }
.sidebar-logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--brand);
  color: var(--brand-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 17px;
  overflow: hidden;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.nav-section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-subtle); padding: 12px 10px 6px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 100ms, color 100ms;
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--bg-subtle); color: var(--fg); }
/* "More on Peepu" items — present but visually quieter than focused modules. */
.nav-item-more { opacity: 0.5; }
.nav-item-more:hover { opacity: 1; }
.nav-item-more.active { opacity: 1; }
.nav-item.active { background: var(--fg); color: var(--bg); }
.nav-item.active .nav-icon { color: var(--bg); }
.nav-icon { color: var(--fg-muted); width: 16px; height: 16px; }
.nav-item.active .nav-icon { color: var(--bg); }
.nav-item .nav-badge { margin-left: auto; font-size: 10px; padding: 1px 6px; background: var(--bg-subtle); border-radius: 999px; color: var(--fg-muted); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-soft);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 100ms;
}
.user-chip:hover { background: var(--bg-subtle); }

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-size: 14px; font-weight: 600; color: var(--fg); }
.topbar-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.topbar-search .input { padding-left: 34px; background: var(--bg-cream); border-color: transparent; }
.topbar-search .input:focus { background: var(--bg); border-color: var(--border); }

.page {
  padding: 28px 32px 64px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.page-subtitle { color: var(--fg-muted); font-size: 13px; margin-top: 3px; }

/* =========================================================================
   AUTH (login/signup)
   ========================================================================= */
.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth-panel {
  display: flex;
  flex-direction: column;
  padding: 32px 48px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  justify-content: center;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 48px;
  position: absolute;
  top: 28px;
  left: 48px;
}
.auth-brand-mark {
  width: 32px; height: 32px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 19px;
}
.auth-brand-name { font-family: var(--font-display); font-size: 22px; font-style: italic; }
.auth-heading { font-size: 36px; letter-spacing: -0.03em; font-weight: 500; margin-bottom: 8px; line-height: 1.1; }
.auth-heading .serif { font-style: italic; font-weight: 400; }
.auth-sub { color: var(--fg-muted); font-size: 14px; margin-bottom: 32px; }

.auth-hero {
  background: var(--bg-cream);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
  position: relative;
  overflow: hidden;
}
.auth-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(180, 160, 120, 0.08), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(120, 140, 110, 0.08), transparent 40%);
}
.auth-hero-quote {
  font-family: var(--font-display);
  font-size: 38px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  max-width: 440px;
  position: relative;
}
.auth-hero-quote em { font-style: italic; }
.auth-hero-attribution { color: var(--fg-muted); font-size: 13px; margin-top: 24px; position: relative; }

/* =========================================================================
   MODAL / DRAWER
   ========================================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.35);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  animation: fadeIn 160ms forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  animation: slideUp 180ms forwards;
}
@keyframes slideUp { to { transform: translateY(0); } }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; gap: 8px; justify-content: flex-end; }
.modal-close { color: var(--fg-muted); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg-subtle); color: var(--fg); }

/* Construction 3-phase stepper */
.con-stepper { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.con-step { display: flex; align-items: center; gap: 8px; }
.con-step-dot {
  width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; background: var(--bg-subtle); color: var(--fg-muted);
  border: 1px solid var(--border-soft); flex: none;
}
.con-step-label { font-size: 13px; color: var(--fg-muted); font-weight: 500; }
.con-step.current .con-step-dot { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); }
.con-step.current .con-step-label { color: var(--fg); }
.con-step.done .con-step-dot { background: var(--success, #15803d); color: #fff; border-color: transparent; }
.con-step.done .con-step-label { color: var(--fg-secondary); }
.con-step-bar { flex: 1 1 32px; min-width: 24px; height: 2px; background: var(--border-soft); border-radius: 2px; }
.con-step-bar.done { background: var(--success, #15803d); }
@media (max-width: 640px) { .con-step-label { display: none; } .con-step-bar { min-width: 16px; } }

/* Bill of Quantities (construction) */
.boq-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft); background: var(--bg-subtle);
}
.boq-typechips { display: flex; gap: 10px; flex-wrap: wrap; }
.boq-typechip {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg);
}
.boq-typechip > span { font-size: 16px; }

/* Construction schedule filter bar (Program of Works) */
.con-sched-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Unsaved-draft restore banner (dialog auto-save) */
.draft-restore-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 0 0 16px; padding: 10px 12px;
  background: var(--warning-soft); border: 1px solid var(--warning); border-radius: var(--radius);
}
.draft-restore-text { font-size: 13px; color: var(--warning); font-weight: 500; }

/* Drawer (right-side slide-in) */
.drawer {
  background: var(--bg);
  width: 560px;
  max-width: 95vw;
  height: 100vh;
  margin-left: auto;
  margin-right: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  animation: slideLeft 200ms forwards;
  border-left: 1px solid var(--border);
}
@keyframes slideLeft { to { transform: translateX(0); } }
.overlay.drawer-overlay { padding: 0; justify-content: flex-end; }
.drawer .modal-body { flex: 1; }

/* =========================================================================
   DROPDOWN
   ========================================================================= */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 50;
  animation: fadeIn 100ms;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--fg-secondary);
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover { background: var(--bg-subtle); color: var(--fg); }
.dropdown-divider { height: 1px; background: var(--border-soft); margin: 4px 0; }

/* =========================================================================
   TOAST
   ========================================================================= */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--fg);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 180ms;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 8px;
}
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } }
.toast-success { background: var(--success); }
.toast-danger { background: var(--danger); }

/* =========================================================================
   EMPTY STATE
   ========================================================================= */
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--fg-muted);
}
.empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  background: var(--bg-subtle);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-subtle);
}
.empty-title { color: var(--fg); font-weight: 500; margin-bottom: 4px; }

/* =========================================================================
   SPINNER
   ========================================================================= */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 60px; }

/* =========================================================================
   TABS
   ========================================================================= */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-soft); margin-bottom: 20px; }
/* On narrow screens the tab strip scrolls horizontally instead of bleeding off
   the edge (which html overflow-x:clip would otherwise cut off unreachably). */
@media (max-width: 720px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; }
}

/* Module name is shown by the page <h1>; the topbar copy was a duplicate. */
.topbar-title { display: none; }

/* Collapsible filter panel (employee directory). Desktop: filters sit inline in
   the toolbar. Mobile: they collapse behind a "Filters" button and drop down as
   a stacked panel so they never push the table off-screen. */
@media (min-width: 721px) {
  .filter-collapse { display: contents; }
  .filter-toggle { display: none !important; }
}
@media (max-width: 720px) {
  .filter-collapse { display: none; width: 100%; }
  .filter-collapse.open {
    display: flex; flex-direction: column; gap: 10px; width: 100%;
    background: var(--bg); border: 1px solid var(--border-soft);
    border-radius: var(--radius); padding: 12px; margin-top: 2px;
  }
  .filter-collapse.open .select { max-width: none !important; width: 100%; }
  .filter-toggle { display: inline-flex; }
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 100ms, border-color 100ms;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--fg); }

/* =========================================================================
   STAT CARDS (dashboard)
   ========================================================================= */
.stat {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-label { font-size: 12px; color: var(--fg-muted); margin-bottom: 6px; }
.stat-value { font-family: var(--font-display); font-size: 38px; letter-spacing: -0.02em; line-height: 1; }
.stat-meta { font-size: 11px; color: var(--fg-muted); margin-top: 6px; }

/* ---- Home dashboard ---- */
/* Module stat cards double as a link into the module. */
.home-mod-card { cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease; }
.home-mod-card:hover { border-color: var(--border-strong); }
.home-mod-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.home-mod-reports {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 12px;
  font-size: 13px; font-weight: 500; color: var(--fg-muted); text-decoration: none;
}
.home-mod-reports:hover { color: var(--brand); }
/* Quick-action chips */
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.quick-action {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
  background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: border-color .15s ease, color .15s ease;
}
.quick-action:hover { border-color: var(--brand); color: var(--brand); }
.quick-action svg { color: var(--fg-muted); flex-shrink: 0; }
.quick-action:hover svg { color: var(--brand); }
/* Two-column "set up + recent activity" row; stacks on mobile. */
.home-split { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 768px) { .home-split { grid-template-columns: 1fr; } }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.25);
  z-index: 40;
}

@media (max-width: 900px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-brand { position: static; margin-bottom: 24px; }

  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }

  .topbar { padding: 0 12px; }
  .topbar-menu-btn { display: flex !important; }

  .page { padding: 20px 16px 48px; }
  /* Title + actions stack instead of fighting for one row on a phone. */
  .page-header { flex-wrap: wrap; }
  /* …and the action cluster itself wraps, so multiple buttons (e.g. HR's
     Resolve / Export / Import / Add) don't force the page wider than the
     screen and trigger sideways scroll. */
  .page-header > .flex { flex-wrap: wrap; }

  .drawer { width: 100%; }
  .modal { max-width: 100%; }
  .overlay { padding: 12px; }
  .modal-footer { flex-wrap: wrap; }

  .auth-panel { padding: 32px 24px; }
  .auth-heading { font-size: 28px; }

  /* iOS Safari zooms the page when a focused input's font is < 16px. Bump
     every form control to 16px on mobile to stop the lurch-on-tap. */
  .input, .select, .textarea { font-size: 16px; }

  /* Wide tables: .table-wrap is overflow:hidden for rounded corners, which
     CLIPS content on a phone. Switch to horizontal scroll so nothing is lost. */
  .table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Detail lists stack label over value instead of a fixed 140px column. */
  .dl > div { grid-template-columns: 1fr; gap: 2px; }

  /* Break long unbreakable strings (emails, URLs, account numbers, codes) so
     they wrap inside the frame instead of pushing content off-screen. Scoped to
     content containers — not to .truncate cells, which keep their ellipsis. */
  .dl > div > *, .list-row, .stat-value, .badge, .page-title, .card-body p, .text-sm { overflow-wrap: anywhere; }
}

/* Touch devices have no :hover — reveal hover-gated actions so edit / delete /
   react buttons aren't permanently invisible on a phone. */
@media (hover: none) {
  .table .row-actions,
  .chat-message-actions { opacity: 1; }
}

/* Bigger tap targets on touch pointers (44px is the accessibility guideline). */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .btn-icon, .modal-close { min-width: 40px; min-height: 40px; }
}

/* Very small / older phones (down to 320px). */
@media (max-width: 520px) {
  .page { padding: 16px 12px 40px; }
  .page-title { font-size: 20px; }
  .overlay { padding: 8px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 19px; }
  /* Footer actions stretch + wrap so they never get clipped or squeezed. */
  .modal-footer { gap: 8px; }
  .modal-footer .btn { flex: 1 1 auto; }

  /* Topbar: drop the flex spacer (scoped to topbar) so search uses the row
     instead of splitting it 50/50 with the spacer and shrinking to a sliver. */
  .topbar .flex-1 { display: none; }
  .topbar-search { max-width: none; }
  .topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Payslip rows: shrink the amount field so the label keeps usable width
     on a narrow phone (the fields scroll their own content if needed). */
  .ps-item-amt { width: 104px; }
}

.topbar-menu-btn { display: none; }

/* =========================================================================
   UTILITY: SCROLL
   ========================================================================= */
.scrollable { overflow-y: auto; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* =========================================================================
   COLOR SWATCH GRID (for brand picker)
   ========================================================================= */
.swatch-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 100ms;
  position: relative;
}
.swatch:hover { transform: scale(1.05); }
.swatch.active { border-color: var(--fg); }
.swatch.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* =========================================================================
   PERMISSION GRID (role editor)
   ========================================================================= */
.perm-group {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.perm-group-title { font-weight: 600; font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
}
.perm-row:first-of-type { border-top: none; }
.perm-label { font-size: 13px; }
.perm-desc { font-size: 11px; color: var(--fg-muted); }


/* Progress bar */
.progress-bar { position: relative; width: 100%; height: 6px; background: var(--bg-subtle); border-radius: 999px; overflow: hidden; }
.progress-bar-fill { position: absolute; top: 0; left: 0; height: 100%; background: var(--brand); border-radius: 999px; transition: width 0.3s ease; }

/* Segmented toggle (e.g. Email / Phone on login) */
.seg-toggle { display: inline-flex; background: var(--bg-subtle); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 3px; gap: 3px; }
.seg-btn { padding: 6px 16px; border-radius: calc(var(--radius) - 3px); font-size: 13px; font-weight: 500; color: var(--fg-muted); transition: background 120ms, color 120ms; }
.seg-btn.active { background: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }

/* Platform notifications — bell dropdown panel + banner */
.notif-panel {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 340px; max-width: calc(100vw - 24px);
  background: var(--bg); border: 1px solid var(--border-soft);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 60; overflow: hidden;
}
.notif-panel-head { padding: 10px 14px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--border-soft); }
.notif-panel-body { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-soft); align-items: flex-start; }
.notif-item:last-child { border-bottom: none; }
.notif-item.is-read { opacity: 0.55; }
.notif-panel-foot { display: flex; align-items: center; gap: 6px; justify-content: center; padding: 11px; font-size: 13px; font-weight: 500; color: var(--fg); border-top: 1px solid var(--border-soft); background: var(--bg-subtle); cursor: pointer; }
.notif-panel-foot:hover { background: var(--bg-cream); }
.notif-banner-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 13px; background: #FEF9E7; border-bottom: 1px solid rgba(10,10,10,0.06); }
.notif-banner-item.is-critical { background: #FDECEA; }

/* Public disbursement page: hide action buttons when printing. */
@media print { .dsb-actions { display: none !important; } }

/* Inline alerts (form-level status messages) */
.alert { border-radius: var(--radius); padding: 10px 12px; font-size: 13px; line-height: 1.45; border: 1px solid transparent; }
.alert-danger  { background: rgba(220,38,38,0.08);  border-color: rgba(220,38,38,0.25);  color: var(--danger); }
.alert-success { background: rgba(22,163,74,0.08);  border-color: rgba(22,163,74,0.25);  color: var(--success); }
.alert-info    { background: rgba(37,99,235,0.08);  border-color: rgba(37,99,235,0.22);  color: var(--info); }
/* Warning banner: amber wash + a left accent, but DARK body text so it reads
   cleanly on the cream UI (orange-on-cream was too low-contrast). */
.alert-warning {
  background: rgba(193,128,24,0.10);
  border-color: rgba(193,128,24,0.30);
  border-left: 3px solid rgba(193,128,24,0.75);
  color: var(--fg);
}
.alert-warning strong { color: var(--fg); }
.alert-warning .text-sm { color: var(--fg-secondary); }
.alert-warning .attn-chip {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid rgba(193,128,24,0.45);
  font-weight: 500;
}
.alert-warning .attn-chip:hover { border-color: rgba(193,128,24,0.85); }

/* Text color utilities */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }
