/* ═══════════════════════════════════════════════════════════
   Revbuild CRM — Brand Stylesheet
   Brand colours: Crimson #B71C1C · Charcoal #1E1E2D · White
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* Brand */
  --rb-red:        #B71C1C;
  --rb-red-dark:   #7F0000;
  --rb-red-light:  #D32F2F;
  --rb-red-glow:   rgba(183,28,28,0.15);
  --rb-charcoal:   #1E1E2D;
  --rb-charcoal-2: #16161F;
  --rb-charcoal-3: #2A2A3D;

  /* UI */
  --primary:       var(--rb-red);
  --primary-dark:  var(--rb-red-dark);
  --primary-light: var(--rb-red-light);
  --accent:        var(--rb-red);
  --accent-hover:  var(--rb-red-dark);
  --success:       #2E7D32;
  --warning:       #E65100;
  --danger:        #C62828;
  --info:          #1565C0;

  --bg:            #F4F5F7;
  --card:          #FFFFFF;
  --border:        #E0E3E8;
  --text:          #1A1A2E;
  --text-muted:    #6B7280;
  --text-light:    #9CA3AF;

  --sidebar-width: 250px;
  --header-height: 64px;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--rb-red); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--rb-red-dark); }

/* ── Layout ─────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--rb-charcoal);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.page-body { padding: 28px; flex: 1; }

.mobile-menu-toggle,
.sidebar-backdrop { display: none; }

/* ── Sidebar Brand ───────────────────────────────────────── */
.sidebar-logo {
  padding: 20px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.sidebar-logo-text .brand-name {
  font-size: 16px;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: 1.5px;
}

.sidebar-logo-text .brand-sub {
  font-size: 9px;
  font-weight: 500;
  color: rgba(255,255,255,0.45);
  letter-spacing: 1.8px;
  text-transform: uppercase;
  margin-top: 1px;
}

/* ── Sidebar Nav ─────────────────────────────────────────── */
.sidebar-nav { padding: 10px 0; flex: 1; }

.nav-section-title {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.3);
  padding: 14px 20px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.65);
  transition: all 0.15s;
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
  border-left-color: rgba(183,28,28,0.5);
}

.nav-item.active {
  background: rgba(183,28,28,0.15);
  color: #fff;
  border-left-color: var(--rb-red-light);
}

.nav-item.active .nav-icon { color: var(--rb-red-light); }
.nav-icon {
  width: 28px;
  min-width: 28px;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.sidebar-user {
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  margin-bottom: 10px;
}

.sidebar-user strong {
  display: block;
  color: rgba(255,255,255,0.9);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.btn-signout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-signout:hover {
  background: rgba(183,28,28,0.2);
  border-color: var(--rb-red);
  color: #fff;
  text-decoration: none;
}

/* ── Topbar ──────────────────────────────────────────────── */
.page-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px 5px 8px;
}

.user-avatar {
  width: 28px; height: 28px;
  background: var(--rb-red);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar-img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.user-chip-name { font-size: 13px; font-weight: 600; color: var(--text); }

.role-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.role-admin     { background: #FEE2E2; color: #991B1B; }
.role-manager   { background: #DBEAFE; color: #1E40AF; }
.role-staff     { background: #DCFCE7; color: #166534; }
.role-accountant  { background: #F3E8FF; color: #6B21A8; }
.role-chief_accountant { background: #EDE9FE; color: #5B21B6; }
.role-leader      { background: #FEF3C7; color: #92400E; }
.role-hr          { background: #CCFBF1; color: #0F766E; }
.role-senior_staff{ background: #E0E7FF; color: #3730A3; }

/* ── Report page ─────────────────────────────────────────── */
.report-tabs {
  display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap;
}
.report-tab {
  padding: 8px 18px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--card);
  color: var(--text-muted); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.report-tab:hover { border-color: var(--rb-red); color: var(--rb-red); }
.report-tab.active {
  background: var(--rb-red); color: #fff; border-color: var(--rb-red);
}
.tab-panel { }
.report-controls {
  display: flex; gap: 16px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  flex-wrap: wrap;
}
.report-ctrl-group { display: flex; flex-direction: column; gap: 4px; }
.report-ctrl-group label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.report-ctrl-group select { padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--bg); }
.view-switcher { display: flex; gap: 4px; margin-left: auto; }
.view-btn {
  padding: 7px 14px; border-radius: 6px;
  border: 1.5px solid var(--border); background: var(--card);
  color: var(--text-muted); font-weight: 600; font-size: 12px;
  cursor: pointer; transition: all 0.15s;
}
.view-btn:hover { border-color: var(--rb-red); color: var(--rb-red); }
.view-btn.active { background: var(--rb-charcoal); color: #fff; border-color: var(--rb-charcoal); }
.mt-4 { margin-top: 24px; }
.mb-4 { margin-bottom: 24px; }

/* ── User switcher dropdown ──────────────────────────────── */
.user-chip-clickable { cursor: pointer; user-select: none; }
.user-chip-clickable:hover { background: var(--border); }
.user-switcher-wrap { position: relative; }
.switcher-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  width: 260px; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.13);
  z-index: 999; overflow: hidden;
}
.switcher-dropdown.open { display: block; }
.switcher-header {
  padding: 10px 14px; font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.switcher-loading { padding: 16px 14px; color: var(--text-muted); font-size: 13px; }
.switcher-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; text-decoration: none; color: var(--text);
  transition: background .12s;
}
.switcher-item:hover { background: var(--bg); }
.switcher-item.current { background: #EFF6FF; }
.switcher-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--rb-red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.switcher-item.current .switcher-avatar { background: var(--info); }
.switcher-info { flex: 1; min-width: 0; }
.switcher-name { display: block; font-weight: 600; font-size: 13px; }
.switcher-role { display: block; font-size: 11px; color: var(--text-muted); }
.switcher-check { color: var(--info); font-weight: 700; font-size: 14px; }

/* ── Dashboard grouped projects ──────────────────────────── */
.group-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
}
.group-tab {
  padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--text-muted);
  font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.group-tab:hover { border-color: var(--rb-red); color: var(--rb-red); }
.group-tab.active { background: var(--rb-charcoal); color: #fff; border-color: var(--rb-charcoal); }
.group-list { display: flex; flex-direction: column; gap: 6px; }
.group-row {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.group-row-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--bg); cursor: pointer; user-select: none;
  font-weight: 600; font-size: 13px; transition: background .12s;
}
.group-row-header:hover { background: #EAECF0; }
.group-badge {
  background: var(--rb-charcoal); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; margin-left: auto;
}
.group-chevron { font-size: 10px; color: var(--text-muted); transition: transform .2s; }
.group-row.open .group-chevron { transform: rotate(90deg); }
.group-projects {
  display: none; border-top: 1px solid var(--border);
}
.group-row.open .group-projects { display: block; }
.group-projects table { margin: 0; }
.group-projects th, .group-projects td { font-size: 12px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--rb-red);
  opacity: 0;
  transition: opacity 0.2s;
}

.stat-card:hover::before { opacity: 1; }
.stat-card.danger::before  { background: var(--danger); opacity: 1; }
.stat-card.warning::before { background: var(--warning); opacity: 1; }
.stat-card.success::before { background: var(--success); opacity: 1; }

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.card-value {
  font-size: 34px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.02em;
}

.card-value.success { color: var(--success); }
.card-value.warning { color: var(--warning); }
.card-value.danger  { color: var(--danger);  }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* ── Widget ──────────────────────────────────────────────── */
.widget {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.widget:has(.table-wrapper) {
  overflow: visible;
}

.widget-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #FAFBFC;
}

.widget-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  overflow-y: visible;
}

/* Frozen table header: give the table its own scroll area so the (already
   sticky) thead stays pinned while the body scrolls. Opt-in via "freeze-head"
   so other tables are unaffected. */
.table-wrapper.freeze-head {
  max-height: calc(100vh - 220px);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; }

th {
  background: #F8F9FB;
  text-align: left;
  padding: 10px 16px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #F8F9FB;
  background-clip: padding-box;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid #F0F2F5;
  color: var(--text);
  vertical-align: middle;
  font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFBFD; }
.td-actions { display: flex; gap: 5px; align-items: center; }

/* ── Status Badges ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge-new              { background: #EFF6FF; color: #1D4ED8; }
.badge-in-progress      { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.badge-checking         { background: #EDE9FE; color: #5B21B6; }
.badge-revision         { background: #FFF7ED; color: #C2410C; border: 1px solid #FED7AA; }
.badge-completed        { background: #F3F4F6; color: #6B7280; border: 1px solid #D1D5DB; }
.badge-invoiced         { background: #F5F3FF; color: #4C1D95; }
.badge-paid             { background: #D1FAE5; color: #064E3B; }

.badge-urgent           { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.badge-high             { background: #FFEDD5; color: #9A3412; }
.badge-medium           { background: #FEF9C3; color: #713F12; }
.badge-low              { background: #F0FDF4; color: #166534; }

.badge-active           { background: #D1FAE5; color: #065F46; }
.badge-pending          { background: #FFFBEB; color: #92400E; }
.badge-on-hold          { background: #F1F5F9; color: #475569; }
.badge-on-leave         { background: #FFFBEB; color: #92400E; }
.badge-resigned         { background: #F1F5F9; color: #6B7280; }
.badge-overdue          { background: #FEE2E2; color: #991B1B; }
.badge-unpaid           { background: #FEE2E2; color: #991B1B; }
.badge-partial          { background: #FFF7ED; color: #C2410C; }
.badge-approved         { background: #D1FAE5; color: #065F46; }
.badge-rejected         { background: #FEE2E2; color: #991B1B; }
.badge-sent             { background: #EFF6FF; color: #1D4ED8; }
.badge-not-quoted       { background: #F1F5F9; color: #475569; }
.badge-quoted           { background: #EFF6FF; color: #1D4ED8; }
.badge-default          { background: #F1F5F9; color: #475569; }

/* ── Forms ───────────────────────────────────────────────── */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-full   { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control {
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--rb-red);
  box-shadow: 0 0 0 3px var(--rb-red-glow);
}

textarea.form-control { min-height: 82px; resize: vertical; }
.form-hint { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.4; }
.form-actions { display: flex; gap: 10px; padding-top: 6px; }

/* Reports-to chain in employee detail */
.reports-chain { margin-top: 5px; display: flex; flex-direction: column; gap: 2px; }
.chain-step { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.chain-step a { color: var(--text-muted); text-decoration: underline dotted; }
.chain-step a:hover { color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
  letter-spacing: 0.01em;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--rb-charcoal);
  color: #fff;
}
.btn-primary:hover { background: var(--rb-charcoal-2); color: #fff; text-decoration: none; }

.btn-accent {
  background: var(--rb-red);
  color: #fff;
  box-shadow: 0 1px 3px rgba(183,28,28,0.3);
}
.btn-accent:hover { background: var(--rb-red-dark); color: #fff; text-decoration: none; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #1B5E20; color: #fff; text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B71C1C; color: #fff; text-decoration: none; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover { border-color: #B0B8C4; background: #F8F9FB; color: var(--text); text-decoration: none; }

.btn-outline-red {
  background: transparent;
  border: 1.5px solid var(--rb-red);
  color: var(--rb-red);
}
.btn-outline-red:hover { background: var(--rb-red-glow); text-decoration: none; }

.btn-sm  { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── Filters Bar ─────────────────────────────────────────── */
.filters-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }

.filter-group label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group select,
.filter-group input {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--rb-red);
  box-shadow: 0 0 0 3px var(--rb-red-glow);
}

.search-input { min-width: 220px; }

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}
.page-header h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.page-header p  { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 18px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: #F0FDF4; color: #166534; border: 1px solid #BBF7D0; }
.alert-danger  { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.alert-info    { background: #EFF6FF; color: #1E40AF; border: 1px solid #BFDBFE; }
.alert-warning { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }

/* ── Toast popup notifications ───────────────────────────── */
.toast {
  position: fixed;
  top: 24px; right: 24px;
  z-index: 9999;
  min-width: 300px; max-width: 420px;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
  font-size: 13px;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}
.toast-success {
  background: #F0FDF4;
  border: 1.5px solid #86EFAC;
  color: #14532D;
}
.toast-error {
  background: #FFF1F1;
  border: 1.5px solid #FCA5A5;
  color: #7F1D1D;
}
.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}
.toast-success .toast-icon { color: #16A34A; }
.toast-error   .toast-icon { color: #DC2626; }
.toast-body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.toast-title { font-weight: 700; font-size: 13px; display: block; }
.toast-msg { font-size: 13px; line-height: 1.45; }
.toast-close {
  background: none; border: none; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0; margin-left: auto;
  color: inherit; opacity: 0.5; flex-shrink: 0;
  align-self: flex-start;
}
.toast-close:hover { opacity: 1; }

/* ── Detail View ─────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.detail-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.detail-section h3 {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}

.detail-section h3::before {
  content: '';
  display: block;
  width: 3px;
  height: 12px;
  background: var(--rb-red);
  border-radius: 2px;
}

.detail-row { display: flex; margin-bottom: 11px; }
.detail-label {
  width: 155px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  padding-top: 1px;
}
.detail-value { flex: 1; font-size: 13.5px; color: var(--text); }

/* ── Progress / Workload ─────────────────────────────────── */
.progress-bar {
  background: #E5E7EB;
  border-radius: 4px;
  height: 7px;
  overflow: hidden;
}
.progress-fill        { height: 100%; border-radius: 4px; background: var(--rb-red); transition: width 0.4s; }
.progress-fill.over   { background: #DC2626; }
.progress-fill.warn   { background: #D97706; }
.progress-fill.good   { background: #16A34A; }
.workload-bar-wrap    { display: flex; align-items: center; gap: 10px; }
.workload-bar-wrap .progress-bar { flex: 1; }
.workload-pct         { font-size: 12px; font-weight: 700; width: 38px; text-align: right; }

/* ── Checklist ───────────────────────────────────────────── */
.checklist { list-style: none; }
.checklist li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid #F0F2F5;
  font-size: 13px;
}
.checklist li:last-child { border-bottom: none; }
.check-done { color: var(--success); font-size: 12px; font-weight: 700; }
.check-todo { color: #9CA3AF; font-size: 12px; font-weight: 700; }
.checklist-editable li { align-items: center; }
.checklist-label { flex: 1; min-width: 0; }
.checklist-actions { display: inline-flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.checklist-actions form { display: inline-flex; }
.checklist-actions-row { flex-direction: row; flex-wrap: nowrap; align-items: center; }
.inline-add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.employee-profile-photo {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}
.employee-profile-photo img,
.employee-profile-placeholder {
  width: 82px;
  height: 82px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.employee-profile-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rb-charcoal);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}
.employee-profile-photo form {
  display: grid;
  gap: 8px;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border-radius: 10px;
  padding: 30px;
  max-width: 420px;
  width: 100%;
  margin: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.modal p  { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Login Page ──────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  background: var(--rb-charcoal);
}

.login-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: linear-gradient(135deg, var(--rb-charcoal) 0%, var(--rb-charcoal-2) 100%);
  position: relative;
  overflow: hidden;
}

.login-left::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -20%;
  width: 80%;
  height: 80%;
  background: radial-gradient(circle, rgba(183,28,28,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.login-brand {
  text-align: center;
  color: #fff;
  position: relative;
  z-index: 1;
}

.login-brand-icon {
  width: 90px;
  height: 90px;
  margin: 0 auto 24px;
}

.login-brand h1 {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #fff;
  margin-bottom: 6px;
}

.login-brand h1 span { color: var(--rb-red-light); }

.login-brand p {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 2.5px;
  text-transform: uppercase;
}

.login-brand-tagline {
  margin-top: 40px;
  font-size: 13px;
  color: rgba(255,255,255,0.35);
  line-height: 1.7;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.login-right {
  width: 420px;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.login-box {
  width: 100%;
  max-width: 360px;
}

.login-box h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}

.login-box .login-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ── Divider ─────────────────────────────────────────────── */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ── Misc Helpers ────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.flex  { display: flex; }
.gap-2 { gap: 8px; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 42px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

.breadcrumb { font-size: 12.5px; color: var(--text-muted); margin-bottom: 18px; display: flex; align-items: center; gap: 6px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--rb-red); text-decoration: none; }
.breadcrumb::before { content: ''; display: inline-block; width: 3px; height: 13px; background: var(--rb-red); border-radius: 2px; margin-right: 4px; }

/* Password strength indicator */
.pw-strength { height: 4px; border-radius: 2px; margin-top: 6px; background: #E5E7EB; overflow: hidden; }
.pw-strength-bar { height: 100%; border-radius: 2px; transition: width 0.3s, background 0.3s; }
.pw-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Permission table */
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-yes { color: var(--success); font-size: 16px; font-weight: 700; }
.perm-no  { color: #D1D5DB; font-size: 16px; }

/* ── Org / Company Chart ─────────────────────────────────── */
.org-chart { display: flex; flex-direction: column; gap: 32px; }

.org-dept-header {
  display: flex; align-items: center; gap: 10px;
  padding: 0 0 12px;
  border-bottom: 2px solid var(--rb-red);
  margin-bottom: 16px;
}
.org-dept-name {
  font-size: 15px; font-weight: 700; color: var(--text); text-transform: uppercase;
  letter-spacing: 0.05em;
}

.org-cards {
  display: flex; flex-wrap: wrap; gap: 14px;
}

.org-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  width: 220px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
  box-shadow: var(--shadow);
}
.org-card:hover {
  border-color: var(--rb-red-light);
  box-shadow: 0 4px 12px rgba(183,28,28,0.12);
  transform: translateY(-2px);
  text-decoration: none;
  color: inherit;
}

.org-avatar {
  width: 46px; height: 46px; flex-shrink: 0;
  border-radius: 50%; overflow: hidden;
  border: 2px solid var(--border);
}
.org-avatar img { width: 100%; height: 100%; object-fit: cover; }
.org-avatar-initials {
  width: 100%; height: 100%;
  background: var(--rb-red);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
}

.org-card-info {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.org-card-name {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.org-card-role {
  font-size: 11.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.org-card-status {
  font-size: 11px; font-weight: 600; margin-top: 2px;
}
.status-dot-active { color: var(--success); }
.status-dot-on-leave { color: var(--warning); }
.status-dot-inactive, .status-dot-terminated { color: var(--danger); }
.status-dot-unknown { color: var(--text-muted); }
.perm-partial { color: var(--warning); font-size: 16px; }

/* ── Org Chart Tree ──────────────────────────────────────── */
/* ── Org Chart Tree ─────────────────────────────────────── */
.oc-tree-scroll { overflow-x: auto; padding-bottom: 24px; }
.oc-tree { display: inline-flex; min-width: 100%; justify-content: center; }

/* Universal connector list — works at every depth */
.oc-root-ul,
.oc-children {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: nowrap;
  padding: 28px 4px 0;
  margin: 0;
  list-style: none;
  position: relative;
}
/* Vertical stem descending from parent into the row */
.oc-root-ul::before,
.oc-children::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  border-left: 2px solid var(--oc-line, #CBD5E1);
  height: 28px; width: 0;
}
/* Each child <li> */
.oc-root-ul > li,
.oc-children > li {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px;
  position: relative;
  list-style: none;
}
/* Horizontal connector arms */
.oc-root-ul > li::before, .oc-root-ul > li::after,
.oc-children > li::before, .oc-children > li::after {
  content: '';
  position: absolute;
  top: 0;
  border-top: 2px solid var(--oc-line, #CBD5E1);
  width: 50%; height: 28px;
}
.oc-root-ul > li::before, .oc-children > li::before { right: 50%; }
.oc-root-ul > li::after,  .oc-children > li::after  { left: 50%; border-left: 2px solid var(--oc-line, #CBD5E1); }
/* Only child — hide horizontal arms, keep vertical stem (::after border-left) */
.oc-root-ul > li:only-child::before,
.oc-children > li:only-child::before { display: none; }
.oc-root-ul > li:only-child::after,
.oc-children > li:only-child::after  { border-top: none; }
/* First child — erase left half */
.oc-root-ul > li:first-child:not(:only-child)::before,
.oc-children > li:first-child:not(:only-child)::before { border: none; }
/* Last child — erase right horizontal arm only; keep border-left (vertical stem) */
.oc-root-ul > li:last-child:not(:only-child)::after,
.oc-children > li:last-child:not(:only-child)::after   { border-top: none; }

/* ── Org node card ───────────────────────────────────────── */
.oc-node {
  display: inline-flex;
  align-items: stretch;
  border-radius: 8px;
  overflow: hidden;
  min-width: 170px;
  max-width: 220px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.13);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 28px;
  border: 1px solid rgba(0,0,0,0.07);
  background: var(--bg-card, #fff);
}
.oc-node:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.20);
  text-decoration: none;
  color: inherit;
}
.oc-photo-col {
  width: 52px; min-width: 52px;
  display: flex; align-items: center; justify-content: center;
  background: #546E7A; overflow: hidden; flex-shrink: 0;
}
.oc-photo-col img { width: 52px; height: 100%; object-fit: cover; display: block; }
.oc-initials-sm {
  font-size: 20px; font-weight: 700; color: rgba(255,255,255,0.9);
  line-height: 1;
}
.oc-info-col {
  flex: 1; padding: 9px 10px;
  background: var(--bg-card, #fff);
  text-align: left; min-width: 0;
}
.oc-name         { font-size: 12px; font-weight: 700; color: var(--text); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oc-english-name { font-size: 10px; color: var(--text-muted); margin-top: 1px; }
.oc-role         { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oc-dept-badge   { display: inline-block; font-size: 9px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; background: var(--border); color: var(--text-muted); padding: 1px 5px; border-radius: 3px; margin-top: 4px; }

/* Department accent colours — left photo strip */
.oc-dept-drafting        .oc-photo-col { background: #1565C0; }
.oc-dept-estimating      .oc-photo-col { background: #2E7D32; }
.oc-dept-design          .oc-photo-col { background: #6A1B9A; }
.oc-dept-land-surveying  .oc-photo-col { background: #E65100; }
.oc-dept-mep             .oc-photo-col { background: #00695C; }
.oc-dept-accountant      .oc-photo-col { background: #827717; }
.oc-dept-manager         .oc-photo-col { background: #B71C1C; }
.oc-dept-training        .oc-photo-col { background: #1A237E; }
.oc-dept-administration  .oc-photo-col { background: #4E342E; }
.oc-dept-none            .oc-photo-col { background: #546E7A; }

/* Dept grid "reports to" label */
.org-card-reports { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* ── Profile Photo + Cropper ─────────────────────────────── */
.profile-photo-wrap {
  display: flex; align-items: center; gap: 16px; margin-bottom: 18px;
}
.profile-photo-preview {
  width: 90px; height: 90px; border-radius: 50%; overflow: hidden;
  border: 3px solid var(--border); flex-shrink: 0;
  background: var(--rb-charcoal-3);
  display: flex; align-items: center; justify-content: center;
}
.profile-photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.profile-photo-initials {
  font-size: 32px; font-weight: 700; color: rgba(255,255,255,0.85);
}
.profile-photo-actions { display: flex; flex-direction: column; gap: 6px; }

/* Photo crop modal — all names prefixed photo-crop-* to avoid Cropper.js class conflicts */
.photo-crop-modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.82);
  display: flex; align-items: center; justify-content: center;
}
.photo-crop-box {
  background: #fff; border-radius: 12px; overflow: hidden;
  width: 560px; max-width: 96vw;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.55);
}
.photo-crop-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px; background: #fff;
}
.crop-area {
  width: 100%; height: 400px; background: #1a1a1a;
  overflow: hidden; position: relative;
}
.crop-area > img { max-width: 100%; display: block; }
.photo-crop-controls {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--border);
  flex-wrap: wrap; background: #fff;
}

/* ── Resizable table columns ──────────────────────────────────────────────
   Drag the right edge of a column header to resize; widths persist per browser
   (see the resizable-columns module in main.js). */

/* Grey separator line between columns so the boundary (and the grab handle) is
   visible. The handle's red bar sits on top of this line on hover. */
/* Fixed layout so each column keeps its own width and resizing one column does
   NOT reflow the others: the dragged right edge moves, the left edge stays put. */
.rb-resizable.rb-cols-frozen { table-layout: fixed; }
.rb-resizable th, .rb-resizable td { border-right: 1px solid #E6E8EC; }
.rb-resizable th:last-child, .rb-resizable td:last-child { border-right: none; }

.rb-resizable th.rb-th {
  position: sticky;
  top: 0;
  z-index: 35;
}

/* Resized headers wrap to show their complete label instead of collapsing to
   "PRIORI..." / "STA...". Extra right padding keeps text clear of the handle. */
.rb-resizable th.rb-col-fixed {
  box-sizing: border-box;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
  padding-right: 20px;
  vertical-align: middle;
}
/* Body cells WRAP to as many lines as needed instead of hiding content. */
.rb-resizable.rb-cols-frozen td {
  white-space: normal; overflow-wrap: break-word; word-break: break-word;
}
/* Keep each cell's content within its column so a narrow column never spills
   onto its neighbour ("info overlaps after resize"). A staff cell can overflow
   only while its picker is open, which lets the menu escape the table cell
   without letting the closed picker/chips cover the next column. */
.rb-resizable.rb-cols-frozen td { overflow: hidden; }
.rb-resizable.rb-cols-frozen td:has(.staff-picker[open]),
.rb-resizable.rb-cols-frozen td.rb-staff-picker-open { overflow: visible; }
/* Inline editors (text inputs, dropdowns, the staff picker, notes) carry fixed
   min-/max-widths that would otherwise overflow a narrowed column. Inside a
   resized cell, let them flow to the column width. Checkboxes/radios are
   EXCLUDED — stretching them to 100% broke the staff tick-box dropdown layout. */
.rb-resizable.rb-cols-frozen td .inline-cell,
.rb-resizable.rb-cols-frozen td input:not([type="checkbox"]):not([type="radio"]),
.rb-resizable.rb-cols-frozen td select,
.rb-resizable.rb-cols-frozen td textarea,
.rb-resizable.rb-cols-frozen td .notes-input,
.rb-resizable.rb-cols-frozen td .notes-display,
.rb-resizable.rb-cols-frozen td .staff-picker {
  min-width: 0 !important; max-width: 100% !important; width: 100% !important;
  box-sizing: border-box;
}
.rb-resizable.rb-cols-frozen td .staff-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.rb-resizable.rb-cols-frozen td .staff-option input[type="checkbox"] {
  flex: 0 0 14px;
  width: 14px !important;
  min-width: 14px !important;
  max-width: 14px !important;
  margin-top: 2px;
}
.rb-resizable.rb-cols-frozen td .staff-option span {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}
/* Staff chips show their full name and wrap onto new lines instead of
   ellipsis-truncating ("L...") when the column is narrowed. */
.rb-resizable.rb-cols-frozen td .staff-chip span {
  max-width: 100% !important; white-space: normal !important;
  overflow: visible !important; text-overflow: clip !important; word-break: break-word;
}

.rb-col-resizer {
  position: absolute; top: 0; right: 0; width: 9px; height: 100%;
  cursor: col-resize; user-select: none; touch-action: none; z-index: 5;
}
.rb-col-resizer::after {
  content: ""; position: absolute; top: 0; right: -1px; width: 2px; height: 100%;
  background: transparent; transition: background 0.12s ease;
}
.rb-col-resizer:hover::after,
body.rb-col-resizing .rb-col-resizer::after { background: var(--rb-red, #C00000); }
.rb-resizable th.rb-last-visible .rb-col-resizer { display: none; }
body.rb-col-resizing { cursor: col-resize !important; user-select: none; }

/* ── Responsive / mobile shell ─────────────────────────────────────────── */
@media (max-width: 900px) {
  body { overflow-x: hidden; }
  body.sidebar-open { overflow: hidden; }
  .sidebar {
    width: min(84vw, 300px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 120;
    box-shadow: 8px 0 28px rgba(0,0,0,.24);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    border: 0;
    background: rgba(15,23,42,.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 110;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .main-content { margin-left: 0; min-width: 0; width: 100%; }
  .topbar { height: 60px; padding: 0 14px; gap: 10px; }
  .mobile-menu-toggle {
    display: inline-flex;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
  }
  .mobile-menu-toggle span { width: 19px; height: 2px; background: var(--text); border-radius: 2px; }
  .page-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { min-width: 0; gap: 7px; margin-left: auto; }
  .page-body { padding: 16px; min-width: 0; }
  .page-header { flex-direction: column; gap: 12px; }
  .page-header > * { max-width: 100%; }
  /* Header action rows (Export / Import / + New …) wrap instead of running off
     the right edge. These are inline display:flex rows with no class of their own. */
  .page-header > div { flex-wrap: wrap; }
  .widget-header { gap: 10px; flex-wrap: wrap; }
  .filters-bar { align-items: stretch; }
  .filter-group, .search-input { min-width: min(100%, 220px); flex: 1 1 180px; }
  .form-grid, .form-grid-3, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .form-actions { flex-wrap: wrap; }
  .table-wrapper { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
  .table-wrapper table { width: max-content; min-width: 100%; }
  .modal { width: min(92vw, 480px); max-height: 88vh; overflow-y: auto; }
  .modal-actions { flex-wrap: wrap; }
  .toast { max-width: calc(100vw - 32px); }
}

@media (max-width: 600px) {
  :root { --header-height: 58px; }
  body { font-size: 14px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .page-body { padding: 12px; }
  .page-title { font-size: 15px; }
  .topbar-right > .role-badge,
  .user-chip-name,
  .topbar-switch-account { display: none; }
  .user-chip { padding: 4px; border: 0; background: transparent; }
  .user-avatar { width: 32px; height: 32px; }
  #syncWidget { gap: 4px !important; min-width: 0; }
  /* Auto-sync runs on its own; drop the manual button + status text on phones so
     the top bar stays uncramped. (The widget only shows on the office PC anyway.) */
  #syncNowBtn, #syncWidget #syncBadge { display: none !important; }
  #syncWidget .btn { padding: 5px 8px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; min-width: 0; }
  .card-value { font-size: 28px; }
  .widget { margin-bottom: 14px; }
  .widget-header { padding: 12px 14px; align-items: flex-start; }
  th { padding: 9px 10px; }
  td { padding: 10px; }
  .btn { min-height: 40px; padding: 8px 13px; justify-content: center; }
  .btn-sm { min-height: 36px; }
  .filters-bar { padding: 12px; }
  .filter-group, .search-input { min-width: 100%; width: 100%; }
  .filter-group select, .filter-group input { width: 100%; min-height: 42px; }
  .form-actions > *, .form-actions form { flex: 1 1 auto; }
  .modal-actions > *, .modal-actions form { flex: 1 1 auto; }
}

@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-body { padding: 10px; }
}

/* ── Phone card tables ──────────────────────────────────────────────────────
   On phones a wide data table is unreadable when scrolled sideways. We drop the
   table grid and render each row as a stacked card: one "LABEL   value" line per
   visible cell. Two kinds of tables become cards (see responsive_tables.js):
     • table[data-column-picker]  — the big data tables (projects, dashboard
       drill-down, allocations, asset register, my report). Always card on phone;
       labels come from each column's data-column-label.
     • table.rb-card              — any other table that is genuinely too wide to
       fit the screen; the class + per-cell data-label are added by JS at runtime.
       Narrow summary tables are left as compact tables (they read fine).
   Desktop is untouched — everything here lives inside the phone breakpoint.
   !important beats the inline px widths resizable_columns.js sets on th/td, and
   keeps column-picker-hidden ([hidden]) cells hidden. */
@media (max-width: 600px) {
  :is(table[data-column-picker], table.rb-card) { display: block; width: 100% !important; min-width: 0 !important; }
  :is(table[data-column-picker], table.rb-card) > thead { display: none; }
  :is(table[data-column-picker], table.rb-card) > tbody { display: block; width: auto !important; min-width: 0 !important; }

  :is(table[data-column-picker], table.rb-card) > tbody > tr {
    display: block;
    width: auto !important;
    margin: 0 0 12px;
    padding: 4px 13px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--card, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
  }
  :is(table[data-column-picker], table.rb-card) > tbody > tr:last-child { margin-bottom: 0; }
  :is(table[data-column-picker], table.rb-card) > tbody > tr:hover td { background: transparent; }

  :is(table[data-column-picker], table.rb-card) > tbody > tr > td {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 3px 12px;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    padding: 9px 0;
    border: 0;
    border-bottom: 1px solid #EEF0F3;
    font-size: 14px;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
  }
  :is(table[data-column-picker], table.rb-card) > tbody > tr > td:last-child { border-bottom: 0; }

  /* Column label on the left; value flows after it. */
  :is(table[data-column-picker], table.rb-card) > tbody > tr > td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 38%;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    white-space: normal;
  }
  /* The value part should take the remaining width and wrap. */
  :is(table[data-column-picker], table.rb-card) > tbody > tr > td[data-label] > * { flex: 1 1 55%; min-width: 0; }

  /* Keep column-picker-hidden cells hidden, and drop the row-number noise
     (both the picker "rownum" column and a plain table's "#"/"No." column). */
  table[data-column-picker] > tbody > tr > td[hidden] { display: none !important; }
  table[data-column-picker] > tbody > tr > td[data-column="rownum"],
  table[data-column-picker] > thead th[data-column="rownum"],
  table.rb-card > tbody > tr > td[data-label="#"],
  table.rb-card > tbody > tr > td[data-label="No."],
  table.rb-card > tbody > tr > td[data-label="No"] { display: none !important; }

  /* Action / checkbox cells have no label — let their controls span the row. */
  :is(table[data-column-picker], table.rb-card) > tbody > tr > td:not([data-label]) {
    justify-content: flex-start;
    gap: 8px;
    padding-top: 11px;
  }

  /* Inline editors (name/category inputs, client & staff pickers) fill the row. */
  :is(table[data-column-picker], table.rb-card) td .inline-cell,
  :is(table[data-column-picker], table.rb-card) td select,
  :is(table[data-column-picker], table.rb-card) td input[type="text"],
  :is(table[data-column-picker], table.rb-card) td input[type="number"],
  :is(table[data-column-picker], table.rb-card) td :is(.staff-picker, .ar-staff-picker) {
    flex: 1 1 55%;
    min-width: 0;
    width: auto;
    max-width: 100% !important;
    min-height: 38px;
  }
  /* The staff / assignee dropdowns (projects + asset register) are absolutely
     positioned menus fixed at ~260px with left:0 — on a phone they spill off the
     right edge. Stretching them left:0/right:0 caps them to their picker's width. */
  .staff-picker-menu, .ar-staff-menu {
    left: 0; right: 0; width: auto !important; max-width: 100% !important;
  }

  /* Slightly larger header text on any tables that still scroll (not carded). */
  .table-wrapper table:not([data-column-picker]):not(.rb-card) th { font-size: 11.5px; }
}

/* ── Wrap-and-edit cells ───────────────────────────────────────────────────
   Long Project Owner / Client values show as wrapping text by default and reveal
   the inline editor on click (see the wrap-and-edit module in main.js). */
.ec { width: 100%; }
.ec-view {
  white-space: normal; overflow-wrap: break-word; word-break: break-word;
  cursor: text; min-height: 22px; padding: 5px 7px; line-height: 1.35;
  border: 1px solid transparent; border-radius: 6px;
}
.ec-view:hover { border-color: var(--border); background: #fff; }
.ec-view.ec-empty { color: var(--text-muted); }
/* Status / Priority badges keep their colour but may wrap in a narrow column. */
.ec-view .badge { white-space: normal; }
.ec > .inline-cell { display: none; width: 100%; box-sizing: border-box; }
.ec.editing > .ec-view { display: none; }
.ec.editing > .inline-cell { display: block; }

/* Staff pickers can live inside horizontally/vertically scrollable table
   wrappers.  While open, resizable_columns.js fixes the menu to the viewport
   so the wrapper cannot clip the staff list. */
.staff-picker-menu.rb-floating-menu {
  position: fixed;
  z-index: 1000;
  right: auto !important;
  width: min(260px, calc(100vw - 16px)) !important;
  max-width: calc(100vw - 16px) !important;
  margin: 0;
  box-sizing: border-box;
}

/* ── Column picker (Show & arrange columns) ────────────────────────────────
   Shared by any <table data-column-picker>. The floating menu + header
   drag-reorder cues; pairs with resizable_columns.js. See column_picker.js. */
.project-column-menu{position:fixed;z-index:1000;min-width:220px;max-height:70vh;overflow:auto;padding:8px;background:#fff;border:1px solid var(--border);border-radius:8px;box-shadow:0 12px 30px rgba(15,23,42,.18)}
.project-column-menu[hidden]{display:none}
.project-column-menu-title{padding:5px 8px 7px;font-size:11px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--text-muted)}
.project-column-option{display:flex;align-items:center;gap:8px;padding:7px 8px;border-radius:5px;cursor:pointer;font-size:13px}
.project-column-option:hover{background:#f3f4f6}
.project-column-option[draggable="true"]{cursor:grab}
.project-column-option.dragging{opacity:.55}
.project-column-option.drag-over{box-shadow:inset 0 2px var(--rb-red)}
.project-column-option input{margin:0}
.project-column-grip{margin-left:auto;color:var(--text-muted);font-weight:700;letter-spacing:-2px}
.project-column-hint{padding:7px 8px 3px;border-top:1px solid var(--border);margin-top:5px;color:var(--text-muted);font-size:11px}
table[data-column-picker] thead th[data-column][draggable="true"]{cursor:grab}
table[data-column-picker] thead th.project-header-dragging{opacity:.65}
table[data-column-picker] thead th.project-drop-before{box-shadow:inset 4px 0 var(--rb-red)}
table[data-column-picker] thead th.project-drop-after{box-shadow:inset -4px 0 var(--rb-red)}
table[data-column-picker] thead th .rb-col-resizer{cursor:col-resize}
