@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============================================================
   PMO Suite Finance Application
   Design Tokens & Global Styles  (tokens.css)
   Light + Dark mode via CSS custom properties
   ============================================================ */

/* ─── Light Theme (default) ─────────────────────────────────── */
:root {
  --background:          #ffffff;
  --foreground:          #0f172a;
  --card:                #ffffff;
  --card-foreground:     #0f172a;
  --primary:             #2563eb;
  --primary-foreground:  #ffffff;
  --secondary:           #f1f5f9;
  --secondary-foreground:#475569;
  --muted:               #f8fafc;
  --muted-foreground:    #94a3b8;
  --accent:              #eff6ff;
  --accent-foreground:   #1d4ed8;
  --destructive:         #dc2626;
  --destructive-foreground: #fff;
  --border:              #e2e8f0;
  --input:               #e2e8f0;
  --ring:                #93c5fd;
  --radius:              0.75rem;

  /* Status colors */
  --status-green:   #16a34a;
  --status-amber:   #d97706;
  --status-red:     #dc2626;
  --status-blue:    #2563eb;

  /* Sidebar */
  /* Matches the dark-background variant baked into the CM Nexus IQ logo PNG
     so the logo area blends seamlessly with the rest of the left panel. */
  --sidebar-bg:     #041F3E;
  --sidebar-fg:     #cbd5e1;
  --sidebar-active: #2563eb;
  --sidebar-hover:  #0e3565;
  --sidebar-width:  240px;
  --sidebar-collapsed: 60px;

  /* Chart palette */
  --chart-1: #2563eb;
  --chart-2: #16a34a;
  --chart-3: #d97706;
  --chart-4: #dc2626;
  --chart-5: #7c3aed;

  /* CTA – primary action accent (orange) */
  --cta:            #ea6c10;
  --cta-foreground: #ffffff;

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Typography */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:  'SFMono-Regular', Consolas, monospace;
  --text-xs:    0.75rem;
  --text-sm:    0.875rem;
  --text-base:  1rem;
  --text-lg:    1.125rem;
  --text-xl:    1.25rem;
  --text-2xl:   1.5rem;
  --text-3xl:   1.875rem;

  /* Shadow */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow:     0 1px 3px rgba(0,0,0,0.1), 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);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

/* ─── Dark Theme ─────────────────────────────────────────────── */
html.dark {
  --background:          #0f172a;
  --foreground:          #f1f5f9;
  --card:                #1e293b;
  --card-foreground:     #f1f5f9;
  --primary:             #3b82f6;
  --primary-foreground:  #ffffff;
  --secondary:           #1e293b;
  --secondary-foreground:#94a3b8;
  --muted:               #1e293b;
  --muted-foreground:    #64748b;
  --accent:              #1e3a5f;
  --accent-foreground:   #93c5fd;
  --destructive:         #ef4444;
  --destructive-foreground: #fff;
  --border:              #334155;
  --input:               #334155;
  --ring:                #3b82f6;
  --sidebar-bg:          #041F3E;
  --sidebar-fg:          #94a3b8;
  --sidebar-hover:       #0e3565;
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Root scale trimmed ~6% for a denser UI without touching per-component sizes. */
html { font-size: 15px; }

body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Shell Layout ───────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  /* Fill the app-shell (which is height:100vh). When rendered outside the
     shell, still pin to the viewport so the sidebar never stops halfway. */
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  transition: width 0.2s ease;
  z-index: 40;
}

/* Sidebar markup is rendered inline in each module page so it exists in the
   very first paint. The `html.sidebar-collapsed` class is set synchronously
   in the page <head> from sessionStorage, so the CSS below determines the
   collapsed vs expanded width before the sidebar is ever painted — no
   fetch, no injection, no width transition can fire during navigation.
   The explicit collapse/expand toggle animation still works because it
   toggles the same html-class at runtime, and .sidebar transitions width. */
.sidebar.collapsed,
html.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
/* Hide text labels while the collapse button + icons remain visible. */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .sidebar-user-info,
html.sidebar-collapsed .sidebar .nav-label,
html.sidebar-collapsed .sidebar .nav-group-label,
html.sidebar-collapsed .sidebar .nav-badge,
html.sidebar-collapsed .sidebar .sidebar-logo-text,
html.sidebar-collapsed .sidebar .sidebar-user-info { display: none; }
.sidebar.collapsed .sidebar-logo,
html.sidebar-collapsed .sidebar .sidebar-logo      { justify-content: center; padding-left: var(--space-2); padding-right: var(--space-2); gap: 0; }
.sidebar.collapsed .sidebar-logo-img,
html.sidebar-collapsed .sidebar .sidebar-logo-img  { display: none; }
.sidebar.collapsed .sidebar-logo-mark,
html.sidebar-collapsed .sidebar .sidebar-logo-mark { display: flex; width: 36px; height: 36px; cursor: pointer; }
.sidebar.collapsed .sidebar-toggle,
html.sidebar-collapsed .sidebar .sidebar-toggle    { display: none; }
.sidebar.collapsed .nav-item,
html.sidebar-collapsed .sidebar .nav-item          { justify-content: center; padding-left: var(--space-2); padding-right: var(--space-2); }
.sidebar.collapsed .sidebar-toggle svg,
html.sidebar-collapsed .sidebar .sidebar-toggle svg { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-user,
html.sidebar-collapsed .sidebar .sidebar-user       { justify-content: center; padding: var(--space-3) var(--space-2); }
.sidebar.collapsed .sidebar-user-logout,
html.sidebar-collapsed .sidebar .sidebar-user-logout { width: 32px; height: 32px; padding: 0; justify-content: center; }
.sidebar.collapsed .sidebar-user-logout .nav-label,
html.sidebar-collapsed .sidebar .sidebar-user-logout .nav-label { display: none; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid #334155;
  min-height: 76px;
  flex-shrink: 0;
}
/* CM Nexus IQ full wordmark image (dark-background variant shown on the sidebar). */
.sidebar-logo-img {
  display: block;
  height: 56px;
  width: 168px;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  object-position: center bottom;
  flex-shrink: 0;
}
/* Icon-only mark: hidden in the expanded state, revealed when the sidebar collapses. */
.sidebar-logo-mark {
  display: none;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.sidebar-logo-mark svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.sidebar-logo span { font-size: 1.125rem; font-weight: 700; color: #fff; white-space: nowrap; letter-spacing: -0.02em; }

/* Collapse/expand toggle button anchored at the right of the logo row. */
.sidebar-toggle {
  margin-left: auto;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid #334155;
  border-radius: var(--radius);
  color: var(--sidebar-fg);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.2s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-toggle svg   { transition: transform 0.2s ease; }

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-3) 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.sidebar-nav::-webkit-scrollbar        { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb  { background: #334155; border-radius: 3px; }
.sidebar-nav::-webkit-scrollbar-track  { background: transparent; }

/* User profile — pinned at the bottom of the sidebar. */
.sidebar-user {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: 1px solid #334155;
  background: rgba(0, 0, 0, 0.15);
}
.sidebar-user-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: 11px;
  color: var(--sidebar-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  display: inline-block;
  margin-top: 4px;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 600;
  text-transform: capitalize;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--sidebar-active);
  color: #fff;
  line-height: 1.4;
}
.sidebar-user-logout {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 6px 10px;
  background: transparent;
  border: 1px solid #334155;
  border-radius: var(--radius);
  color: var(--sidebar-fg);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar-user-logout:hover { background: var(--sidebar-hover); color: #fff; border-color: var(--sidebar-hover); }
.sidebar-user-logout .nav-icon { width: 16px; height: 16px; }

.nav-group-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.15s;
  font-size: var(--text-sm);
  color: var(--sidebar-fg);
  text-decoration: none;
  position: relative;
}
.nav-item:hover  { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: rgba(255,255,255,0.6);
  border-radius: 0 2px 2px 0;
}

.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .nav-label { white-space: nowrap; }

.nav-badge {
  margin-left: auto;
  background: var(--destructive);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
}

/* ─── Sidebar Brand Footer ───────────────────────────────────── */
.sidebar-brand {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 1px solid rgba(255,255,255,0.06);
}
/* The CloudMoyo JPG carries generous whitespace around the wordmark.
   Use cover with a wider aspect ratio so the middle band (the wordmark itself) fills the pill. */
.sidebar-brand-img {
  display: block;
  height: 24px;
  width: 72px;
  object-fit: cover;
  object-position: center;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
/* Inline SVG wordmark fallback that always renders sharply on the dark rail. */
.cloudmoyo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(15,23,42,0.15);
}
.cloudmoyo-mark img { display: block; height: 24px; width: 72px; object-fit: cover; object-position: center; }
.cloudmoyo-mark svg { display: block; height: 22px; width: auto; }
.sidebar-brand-text {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
}
.sidebar-brand-icon { opacity: 0.85; }
.sidebar.collapsed .sidebar-brand,
html.sidebar-collapsed .sidebar .sidebar-brand { padding: var(--space-2); justify-content: center; }
.sidebar.collapsed .sidebar-brand-text,
html.sidebar-collapsed .sidebar .sidebar-brand-text { display: none; }
.sidebar.collapsed .sidebar-brand-icon,
html.sidebar-collapsed .sidebar .sidebar-brand-icon { display: flex; }
.sidebar.collapsed .sidebar-brand-img,
html.sidebar-collapsed .sidebar .sidebar-brand-img  { display: none; }

/* ─── Top Header ─────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
}
.breadcrumb a { color: var(--muted-foreground); }
.breadcrumb .current { color: var(--foreground); font-weight: 500; }
.breadcrumb-sep { color: var(--muted-foreground); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.global-search {
  display: flex;
  align-items: center;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  cursor: pointer;
  min-width: 220px;
}
.global-search kbd {
  background: var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: var(--font-mono);
  margin-left: auto;
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius);
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  position: relative;
}
.icon-btn:hover { background: var(--secondary); color: var(--foreground); }

.user-badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  transition: background 0.15s;
}
.user-badge:hover { background: var(--secondary); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.role-pill {
  font-size: 11px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 500;
}

/* ─── Page Content ───────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  background: #f8fafc;
}

html.dark .page-content { background: var(--background); }

/* ── Opt-in: "fit-viewport" page layout ─────────────────────────
   Turns the page area into a flex column that fills the viewport,
   so the whole page never scrolls — only the primary data card /
   grid does. Apply together with `.card-fill` (or `.grid-fill`) on
   the single dominant table container. The card-fill / grid-fill
   element becomes the flex-growing region; its inner scroll wrapper
   (.table-scroll / .alloc-scroll / .proj-grid-wrap) takes the
   remaining height and owns the vertical scrollbar.
   Falls back to normal page scroll on very short viewports so
   content is never clipped on small laptop screens. */
.page-content.fit-viewport {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.page-content.fit-viewport > .card-fill,
.page-content.fit-viewport > .grid-fill {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.page-content.fit-viewport > .card-fill > .card-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.page-content.fit-viewport .table-scroll,
.page-content.fit-viewport .alloc-scroll,
.page-content.fit-viewport .proj-grid-wrap {
  flex: 1 1 auto;
  min-height: 220px;
  max-height: none;
  overflow: auto;
}
/* Prevent horizontal overflow from wide filter/toolbar rows creating a
   page-level horizontal scrollbar. Rows already wrap via flex-wrap. */
.page-content.fit-viewport > * { min-width: 0; }

/* Short viewports: restore normal scrolling so nothing is clipped. */
@media (max-height: 640px) {
  .page-content.fit-viewport { overflow-y: auto; }
  .page-content.fit-viewport .table-scroll,
  .page-content.fit-viewport .alloc-scroll,
  .page-content.fit-viewport .proj-grid-wrap { min-height: 260px; }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-4);
}
.page-header > div:first-child { flex: 1; min-width: 0; }
.page-title { font-size: var(--text-2xl); font-weight: 700; color: var(--foreground); }
.page-subtitle { font-size: var(--text-sm); color: var(--muted-foreground); margin-top: var(--space-1); line-height: 1.5; }
.page-actions { display: flex; gap: var(--space-3); align-items: center; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

.card-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.card-title   { font-size: var(--text-base); font-weight: 600; }
.card-content { padding: var(--space-4); }

/* ─── KPI Tiles ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.kpi-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  transition: box-shadow 0.2s, transform 0.15s;
}
.kpi-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-tile-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-tile-icon.blue   { background: #dbeafe; color: #1d4ed8; }
.kpi-tile-icon.green  { background: #dcfce7; color: #15803d; }
.kpi-tile-icon.orange { background: #ffedd5; color: #c2410c; }
.kpi-tile-icon.purple { background: #ede9fe; color: #6d28d9; }
.kpi-tile-body { flex: 1; min-width: 0; }
.kpi-label  { font-size: var(--text-xs); color: var(--muted-foreground); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: var(--space-1); }
.kpi-value  { font-size: var(--text-2xl); font-weight: 700; line-height: 1.2; }
.kpi-delta  { font-size: var(--text-xs); color: var(--muted-foreground); margin-top: var(--space-1); }
.kpi-value.good { color: var(--status-green); }
.kpi-value.warn { color: var(--status-amber); }
.kpi-value.bad  { color: var(--status-red); }

/* ─── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

/* Scrollable body with a frozen header. Applied together with .table-sticky
   on the child <table> so the thead row stays visible while the body scrolls. */
.table-scroll { max-height: 65vh; overflow: auto; }
.table-sticky thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--secondary);
  box-shadow: 0 1px 0 var(--border);
}

/* Dense enterprise data-table behavior for standard tables that live inside
   .table-wrap: table sizes to content and owns its own horizontal scroll,
   cells stay on one line so dates / IDs / statuses never wrap. Cells that
   genuinely need to wrap (e.g. long free-text) can opt out with .wrap-cell. */
.table-wrap > table { width: auto; min-width: 100%; }
.table-wrap tbody td { white-space: nowrap; }
.table-wrap tbody td.wrap-cell { white-space: normal; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
thead th {
  background: var(--secondary);
  color: var(--secondary-foreground);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s; }
tbody tr:hover { background: rgba(37,99,235,0.04); }
tbody td { padding: var(--space-2) var(--space-3); vertical-align: middle; font-weight: 400; }

.row-actions-menu {
  position: relative;
  display: inline-block;
}

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-default     { background: var(--secondary);    color: var(--secondary-foreground); }
.badge-success     { background: #dcfce7; color: #15803d; }
.badge-warning     { background: #fef3c7; color: #92400e; }
.badge-danger      { background: #fee2e2; color: #991b1b; }
.badge-info        { background: #dbeafe; color: #1e40af; }
.badge-outline     { border: 1px solid var(--border); background: transparent; color: var(--foreground); }
.badge-pending     { background: #fef9c3; color: #713f12; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover { background: #b91c1c; }

.btn-ghost    { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--secondary); }

.btn-cta   { background: var(--cta); color: var(--cta-foreground); border-color: var(--cta); }
.btn-cta:hover { background: #c85b0c; border-color: #c85b0c; }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }

/* ─── Form Elements ──────────────────────────────────────────── */
.form-group  { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-label  { font-size: var(--text-sm); font-weight: 500; color: var(--foreground); }
.form-label.required::after { content: ' *'; color: var(--destructive); }

.form-input, .form-select, .form-textarea {
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  padding: 6px var(--space-3);
  font-size: var(--text-sm);
  color: var(--foreground);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font-sans);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(147,197,253,0.3);
}
.form-error { font-size: var(--text-xs); color: var(--destructive); }

.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.filter-row .form-select { width: auto; min-width: 110px; }
.filter-row .form-input  { width: auto; min-width: 180px; }

/* Single-row variant: forces every filter + Reset onto one line even with the
   sidebar expanded. Selects shrink to their content width and the search box
   absorbs any leftover space; gap and horizontal padding tighten so a typical
   Projects filter set (search + 6 selects + Reset) fits on ~1280px screens. */
.filter-row-single {
  flex-wrap: nowrap;
  gap: var(--space-2);
  padding: var(--space-3);
}
.filter-row-single > * { flex-shrink: 1; }
.filter-row-single .form-select { min-width: 0; width: auto; padding-right: var(--space-6); }
.filter-row-single .form-input  { min-width: 0; width: 100%; }
.filter-row-single .btn { flex-shrink: 0; white-space: nowrap; }

/* ─── Tabs ───────────────────────────────────────────────────── */
.tabs       { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: var(--space-5); }
.tab        { padding: var(--space-3) var(--space-5); font-size: var(--text-sm); font-weight: 500; cursor: pointer; color: var(--muted-foreground); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; }
.tab:hover  { color: var(--foreground); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Drawer / Sheet ─────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(520px, 95vw);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  z-index: 101;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.2s ease;
}
.drawer-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-title  { font-size: var(--text-lg); font-weight: 600; }
.drawer-body   { flex: 1; overflow-y: auto; padding: var(--space-6); }
.drawer-footer { padding: var(--space-5) var(--space-6); border-top: 1px solid var(--border); display: flex; gap: var(--space-3); justify-content: flex-end; }

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--card);
  border-radius: calc(var(--radius) * 2);
  box-shadow: var(--shadow-lg);
  width: min(520px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  animation: scaleIn 0.15s ease;
}
.modal-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title  { font-size: var(--text-lg); font-weight: 600; }
.modal-body   { padding: var(--space-6); }
.modal-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); display: flex; gap: var(--space-3); justify-content: flex-end; }

/* ─── Collapsible Form Section (shared, popup 3-col layout) ─── */
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  margin-bottom: var(--space-3);
  overflow: hidden;
}
.form-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--foreground);
  background: color-mix(in oklab, var(--muted) 60%, var(--card));
  border-bottom: 1px solid transparent;
  user-select: none;
}
.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary::marker { content: ''; }
.form-section[open] > summary { border-bottom-color: var(--border); }
.form-section > summary:hover { background: color-mix(in oklab, var(--muted) 80%, var(--card)); }
.form-section-icon {
  width: 28px; height: 28px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  color: var(--primary);
}
.form-section-icon svg { width: 16px; height: 16px; }
.form-section-title { flex: 1; }
.form-section-chevron {
  width: 16px; height: 16px;
  color: var(--muted-foreground);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.form-section[open] > summary .form-section-chevron { transform: rotate(180deg); }
.form-section-body { padding: var(--space-4); }

/* ── Collapsible section wrapper (KPI / Filters) ─────────────────
   <details>-based, no JS. Compact strip when closed, expands to
   show the wrapped `.kpi-grid` / `.filter-row` / `.alloc-filters`
   unchanged. DOM stays intact when closed so form values persist. */
.section-collapse { margin-bottom: var(--space-3); }
.section-collapse[open] { margin-bottom: var(--space-4); }
.section-collapse > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 4px var(--space-3);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.section-collapse > summary::-webkit-details-marker { display: none; }
.section-collapse > summary::marker { content: ''; }
.section-collapse > summary:hover { background: var(--secondary); }
.section-collapse > summary:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
}
.section-collapse > summary .sc-chev {
  margin-left: auto;
  width: 14px; height: 14px;
  color: var(--muted-foreground);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.section-collapse[open] > summary .sc-chev { transform: rotate(90deg); }
.section-collapse-body { margin-top: var(--space-2); }
.section-collapse-body > .kpi-grid,
.section-collapse-body > .filter-row,
.section-collapse-body > .alloc-filters { margin-bottom: 0; }

/* Allocation toolbar hosts filters + action buttons on one row. Give the
   collapse strip the full toolbar width so the action buttons wrap to the
   next row cleanly whether the filters are open or closed. */
.alloc-toolbar > .section-collapse { flex: 1 1 100%; min-width: 0; margin-bottom: 0; }
.alloc-toolbar > .section-collapse > summary {
  background: transparent;
  border-color: transparent;
  padding-left: 0;
  padding-right: 0;
}
.alloc-toolbar > .section-collapse > summary:hover { background: var(--muted); }


.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
}
.form-grid-3 > .form-group { margin: 0; }
.form-grid-3 .col-span-2 { grid-column: span 2; }
.form-grid-3 .col-span-3 { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid-3 .col-span-3 { grid-column: span 2; }
}
@media (max-width: 600px) {
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid-3 .col-span-2,
  .form-grid-3 .col-span-3 { grid-column: auto; }
}

/* ─── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  min-width: 280px;
  animation: slideInRight 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}
.toast.success { border-left: 4px solid var(--status-green); }
.toast.error   { border-left: 4px solid var(--status-red); }
.toast.warning { border-left: 4px solid var(--status-amber); }
.toast .toast-message { flex: 1; color: var(--foreground); line-height: 1.4; word-break: break-word; }
.toast .toast-close {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--muted-foreground); cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toast .toast-close:hover { background: var(--secondary); color: var(--foreground); border-color: var(--border); }

/* ─── Skeleton loader ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--secondary) 25%, var(--border) 50%, var(--secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
.skeleton-row { height: 40px; margin-bottom: var(--space-2); }
.skeleton-kpi { height: 80px; }

/* ─── Charts placeholder ─────────────────────────────────────── */
.chart-container {
  width: 100%;
  height: 300px;
  position: relative;
}

/* ─── Empty state ────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  text-align: center;
  gap: var(--space-3);
}
.empty-state svg { width: 48px; height: 48px; color: var(--muted-foreground); }
.empty-state h3  { font-size: var(--text-base); font-weight: 600; }
.empty-state p   { font-size: var(--text-sm); color: var(--muted-foreground); }

/* ─── Status indicators ──────────────────────────────────────── */
.health-green { color: var(--status-green); }
.health-amber { color: var(--status-amber); }
.health-red   { color: var(--status-red); }

.alloc-cell         { text-align: center; min-width: 56px; }
.alloc-cell.full    { background: #dbeafe; color: #1e40af; font-weight: 600; }
.alloc-cell.partial { background: #dcfce7; color: #15803d; }
.alloc-cell.over    { background: #fee2e2; color: #991b1b; font-weight: 700; }
.alloc-cell.bench   { background: var(--secondary); color: var(--muted-foreground); }

/* ─── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
  background: var(--card);
  min-height: 44px;
}
.pagination-left {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted-foreground);
  flex-wrap: wrap;
}
.pagination-left label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* Reusable Rows-per-page label; used by shared `renderRowsPerPage()` so
   Settings modules match the Employees pagination footer visually. */
.rows-per-page-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}
.pagination-size-select {
  height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
  font-size: var(--text-sm);
  cursor: pointer;
  min-width: 58px;
}
.pagination-right { display: flex; align-items: center; }
.pagination-controls { display: flex; gap: 3px; align-items: center; }
.page-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  line-height: 1;
}
.page-btn:hover  { background: var(--secondary); border-color: var(--border); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ─── AI Insight callout ─────────────────────────────────────── */
.ai-insight {
  border-left: 4px solid var(--primary);
  background: var(--accent);
  padding: var(--space-4);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: var(--text-sm);
}
.ai-insight-label { font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; color: var(--primary); margin-bottom: var(--space-2); }

/* ─── Lever slider ───────────────────────────────────────────── */
.lever-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.lever-card  { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.lever-label { font-size: var(--text-xs); font-weight: 600; color: var(--muted-foreground); margin-bottom: var(--space-2); text-transform: uppercase; }
.lever-value { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--space-3); }
.lever-slider { width: 100%; accent-color: var(--primary); }

/* ─── Chat UI ────────────────────────────────────────────────── */
.chat-container   { display: flex; flex-direction: column; height: calc(100vh - 200px); }
.chat-messages    { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.chat-msg         { max-width: 75%; }
.chat-msg.user    { align-self: flex-end; }
.chat-msg.ai      { align-self: flex-start; }
.chat-bubble      { padding: var(--space-3) var(--space-4); border-radius: calc(var(--radius)*2); font-size: var(--text-sm); line-height: 1.6; }
.chat-msg.user .chat-bubble { background: var(--primary); color: #fff; }
.chat-msg.ai   .chat-bubble { background: var(--secondary); color: var(--foreground); }
.chat-input-row   { display: flex; gap: var(--space-3); padding: var(--space-4); border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; }

/* ─── Gantt bar ──────────────────────────────────────────────── */
.gantt-bar         { height: 16px; border-radius: 3px; background: var(--primary); position: absolute; }
.gantt-bar.baseline { background: var(--muted-foreground); opacity: 0.4; }
.gantt-bar.delayed  { background: var(--status-red); }

/* ─── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn       { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes scaleIn      { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shimmer      { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Access Control read-only mode ──────────────────────────── */
/* Applied to <body> by Perms.enforce() when the caller has Read-only
   permission on the current module. Any element that triggers a write
   should carry `data-write` (marker attribute, no value needed) so the
   generic rule hides it without redesigning each page. Individual
   pages may add page-scoped rules for buttons that predate this
   convention. */
body.pmo-readonly [data-write] { display: none !important; }
body.pmo-readonly input[data-write],
body.pmo-readonly select[data-write],
body.pmo-readonly textarea[data-write] { pointer-events: none; opacity: 0.6; }

/* ─── Shared "Access Restricted" card ───────────────────────── */
/* Rendered by Perms.showAccessRestricted() inside the module's
   <main class="page-content">. Sidebar, header, and user profile
   remain untouched so the user can pivot to another module without
   a page reload. Tokens match the rest of the application so the
   experience is consistent across every module. */
.pmo-access-restricted {
  max-width: 520px;
  margin: var(--space-8) auto 0;
  padding: var(--space-8);
  text-align: center;
}
.pmo-access-restricted .pmo-ar-icon {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-4);
  background: #fee2e2; color: #dc2626;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700;
}
.pmo-access-restricted .pmo-ar-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 var(--space-2);
}
.pmo-access-restricted .pmo-ar-body {
  color: var(--foreground);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-2);
  line-height: 1.5;
}
.pmo-access-restricted .pmo-ar-hint {
  color: var(--muted-foreground);
  font-size: var(--text-xs);
  margin: 0;
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .nav-label, .nav-group-label, .nav-badge, .sidebar-logo-text { display: none; }
  .sidebar-logo { justify-content: center; padding-left: var(--space-2); padding-right: var(--space-2); gap: 0; }
  .sidebar-logo-img  { display: none; }
  .sidebar-logo-mark { display: flex; width: 36px; height: 36px; }
  .sidebar-toggle { display: none; }
  .nav-item     { justify-content: center; padding-left: var(--space-2); padding-right: var(--space-2); }
}

@media (max-width: 767px) {
  .sidebar { position: fixed; transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar.open { transform: translateX(0); }
  .page-content { padding: var(--space-4); }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .drawer { width: 100%; }
}
