/* NexusWorks360 — base styles. No framework; plain CSS tuned for the vanilla-JS SPA. */

/* Brand primary is #6e8933 (NexusWorks360 green). It is used as-is for fills,
   borders and active indicators. White on it is 3.97:1, so link/tab TEXT uses
   --color-primary-text, a darker (light theme) or lighter (dark theme) shade of
   the same green that clears WCAG AA 4.5:1. */
:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-surface-2: #f1f3f6;
  --color-surface-elevated: #f1f3f6;
  --color-border: #dfe3e8;
  --color-text: #1c1e21;
  --color-text-muted: #5a6570;
  --color-primary: #6e8933;
  --color-primary-hover: #5b7229;
  --color-primary-text: #5b7229;
  --color-primary-subtle: #eef3e2;
  --color-accent: var(--color-primary);
  --color-danger: #c23333;
  --color-warning: #b77500;
  --color-success: #1e7c3a;
  --color-focus: #9cb862;
  --radius: 4px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --spacing-1: 4px;
  --spacing-2: 8px;
  --spacing-3: 12px;
  --spacing-4: 16px;
  --spacing-5: 24px;
  --spacing-6: 32px;
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #161a1f;
    --color-surface: #1f242b;
    --color-surface-2: #262c34;
    --color-surface-elevated: #262c34;
    --color-border: #333b44;
    --color-text: #e6e8eb;
    --color-text-muted: #8b9199;
    --color-primary: #6e8933;
    --color-primary-hover: #7f9c3d;
    --color-primary-text: #9cb862;
    --color-primary-subtle: #2a3322;
    --color-focus: #9cb862;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-base);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

#app { min-height: 100%; display: flex; flex-direction: column; }

a { color: var(--color-primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }

button, .button {
  display: inline-block;
  padding: var(--spacing-2) var(--spacing-4);
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
button:hover, .button:hover { background: var(--color-border); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

button.primary, .button.primary {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}
button.primary:hover, .button.primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

button.danger { color: var(--color-danger); border-color: var(--color-danger); background: transparent; }
button.danger:hover { background: var(--color-danger); color: white; }

button.link, .button.link {
  background: transparent;
  border-color: transparent;
  padding: var(--spacing-1) var(--spacing-2);
  color: var(--color-primary-text);
}
button.link:hover { background: var(--color-surface-2); }

input, select, textarea {
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-2) var(--spacing-3);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-focus);
  outline-offset: 0;
  border-color: var(--color-focus);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-1);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.field { margin-bottom: var(--spacing-4); }
.field .error { color: var(--color-danger); font-size: 12px; margin-top: var(--spacing-1); }

/* Layout — app shell with collapsible left sidebar.
   `body.sidebar-collapsed` shrinks the sidebar to icon-only mode. */
:root {
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 64px;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}
body.sidebar-collapsed .shell { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.shell-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  /* allow the edge-toggle to float past the right border */
  overflow: visible;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-3);
  border-bottom: 1px solid var(--color-border);
  min-width: 0;
}

/* Floating chevron handle outside the sidebar's right edge — toggles collapsed state.
   Vertically aligned with the brand logo's horizontal centerline (sidebar-top has
   padding-3 = 12px, brand logo is 28px tall → center at 12+14 = 26px from top;
   24px toggle with top: 14px puts its center at 14+12 = 26px — same line). */
.sidebar-edge-toggle {
  position: absolute;
  top: calc(var(--spacing-3) + 2px);
  right: -28px;
  z-index: 5;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.sidebar-edge-toggle:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-primary, currentColor);
}
.sidebar-edge-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  transition: transform 0.18s ease;
}
.sidebar-edge-icon svg { width: 100%; height: 100%; }
/* When collapsed, flip the chevron so it points right (= "expand"). */
body.sidebar-collapsed .sidebar-edge-icon { transform: rotate(180deg); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  flex: 1;
  min-width: 0;
  color: var(--color-text);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
  display: none; /* shown only in collapsed mode (rule below) */
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  object-fit: contain;
}
.brand-name {
  display: inline-block;
  height: 28px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
body.sidebar-collapsed .brand-mark { display: inline-flex; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--spacing-3);
  flex: 1;
  overflow-y: auto;
}

.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  padding: var(--spacing-2) var(--spacing-3);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
}
.sidebar-link:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.sidebar-link.active {
  background: var(--color-surface-2);
  color: var(--color-text);
  font-weight: 600;
}
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  width: 3px;
  height: 60%;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}
.sidebar-icon svg { width: 100%; height: 100%; display: block; }

.sidebar-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  border-top: 1px solid var(--color-border);
  padding: var(--spacing-3);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-3);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  min-width: 0;
}
.user-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-surface-2);
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.user-meta { min-width: 0; }
.user-meta .user-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-controls { display: flex; flex-direction: column; gap: var(--spacing-2); }
.sidebar-controls .lang-picker { width: 100%; padding: var(--spacing-1) var(--spacing-2); }

/* Collapsed mode: hide labels + the brand chip; the toggle button keeps its
   top-left position so it never jumps between layouts. Tooltip on hover via
   the link's title attr. */
.sidebar-badge {
  margin-left: auto;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  background: var(--color-danger, #ff5050);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  flex-shrink: 0;
}
/* Collapsed sidebar: badge becomes a small overlay dot on the icon. */
body.sidebar-collapsed .sidebar-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  margin-left: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
}
body.sidebar-collapsed .sidebar-label { display: none; }
body.sidebar-collapsed .sidebar-brand { gap: 0; justify-content: center; flex: 0 0 auto; }
body.sidebar-collapsed .sidebar-top { justify-content: center; padding: var(--spacing-2); }
body.sidebar-collapsed .sidebar-link { justify-content: center; padding: var(--spacing-2); }
body.sidebar-collapsed .sidebar-link.active::before { left: -3px; }
body.sidebar-collapsed .sidebar-user { justify-content: center; }
body.sidebar-collapsed .sidebar-controls { align-items: center; }

/* --- Sidebar groups, sections, search, pinned/recent --- */

.sidebar-shortcut {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: var(--spacing-2);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--spacing-2);
}

.sidebar-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: var(--spacing-2);
}
.sidebar-search-icon {
  position: absolute;
  left: var(--spacing-2);
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.sidebar-search-icon svg { width: 100%; height: 100%; }
.sidebar-search-input {
  width: 100%;
  padding: var(--spacing-2) var(--spacing-2) var(--spacing-2) calc(var(--spacing-2) * 2 + 16px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
}
.sidebar-search-input::placeholder { color: var(--color-text-muted); }
.sidebar-search-input:focus { outline: none; border-color: var(--color-primary); }

.sidebar-section {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--spacing-3);
}
.sidebar-section-label {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-1) var(--spacing-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.sidebar-section-icon {
  display: inline-flex;
  width: 13px;
  height: 13px;
}
.sidebar-section-icon svg { width: 100%; height: 100%; }
.sidebar-section-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid transparent;
}
.sidebar-group-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  width: 100%;
  padding: var(--spacing-2);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  text-align: left;
}
.sidebar-group-header:hover { background: var(--color-surface-2); color: var(--color-text); }
.sidebar-group-chevron {
  display: inline-flex;
  width: 14px;
  height: 14px;
  transition: transform 0.15s ease;
}
.sidebar-group-chevron svg { width: 100%; height: 100%; }
.sidebar-group-header.collapsed .sidebar-group-chevron { transform: rotate(-90deg); }
.sidebar-group-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-group-count {
  flex: 0 0 auto;
  min-width: 18px;
  padding: 0 6px;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
}
.sidebar-group-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 var(--spacing-2);
  overflow: hidden;
  max-height: 1500px;
  transition: max-height 0.18s ease;
}
.sidebar-group-body.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

/* Star button — appears on hover, stays visible when pinned. */
.sidebar-star {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 2px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  opacity: 0;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-star svg { width: 100%; height: 100%; }
.sidebar-link:hover .sidebar-star { opacity: 0.6; }
.sidebar-star:hover { opacity: 1 !important; color: var(--color-text); background: var(--color-surface-2); }
.sidebar-star.pinned { opacity: 1; color: var(--color-warning, #f4a012); }

/* Live filter — items not matching the query and groups with no matches collapse out. */
.sidebar-link.filtered-out,
.sidebar-group.filtered-out,
.sidebar-shortcut.filtered-out,
.sidebar-section.filtered-out { display: none !important; }
/* When searching, force-expand the group bodies so matches are visible. */
.sidebar-nav.searching .sidebar-group-body.collapsed {
  max-height: 1500px;
  padding: 2px 0 var(--spacing-2);
  pointer-events: auto;
}
.sidebar-nav.searching .sidebar-group-header { pointer-events: none; }

/* Group needs to be a positioning context so the collapsed-mode flyout can anchor to it. */
.sidebar-group { position: relative; }

/* Collapsed-mode group icon trigger — hidden in expanded mode. */
.sidebar-group-icon-btn { display: none; }
.sidebar-flyout-label { display: none; }

/* Collapsed sidebar: hide search, section labels, stars, expanded group headers + the
   shortcut divider. Group bodies become hover-popovers anchored to each group's icon. */
body.sidebar-collapsed .sidebar-search,
body.sidebar-collapsed .sidebar-section-label,
body.sidebar-collapsed .sidebar-group-header,
body.sidebar-collapsed .sidebar-star { display: none; }
body.sidebar-collapsed .sidebar-shortcut { border-bottom: none; }
/* Allow flyouts to escape the sidebar's right edge. With ~10 group icons in the
   collapsed sidebar there's no real need for scroll on the outer nav anyway —
   flyouts have their own internal scroll for long groups. */
body.sidebar-collapsed .sidebar-nav { overflow: visible; }

/* Show the icon trigger in collapsed mode; style it like a flat icon link. */
body.sidebar-collapsed .sidebar-group-icon-btn {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius);
}
body.sidebar-collapsed .sidebar-group-icon-btn:hover,
body.sidebar-collapsed .sidebar-group:hover .sidebar-group-icon-btn,
body.sidebar-collapsed .sidebar-group:focus-within .sidebar-group-icon-btn {
  background: var(--color-surface-2);
  color: var(--color-text);
}
body.sidebar-collapsed .sidebar-group-icon-btn.has-active {
  color: var(--color-text);
  position: relative;
}
body.sidebar-collapsed .sidebar-group-icon-btn.has-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  width: 3px;
  height: 60%;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}
body.sidebar-collapsed .sidebar-group-icon-btn .sidebar-icon { width: 22px; height: 22px; }

/* Flyout: hidden by default in collapsed mode, shown on hover/focus over the group. */
body.sidebar-collapsed .sidebar-group-body,
body.sidebar-collapsed .sidebar-group-body.collapsed {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: var(--spacing-2);
  min-width: 240px;
  max-height: 70vh;
  overflow-y: auto;
  padding: var(--spacing-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 30;
  pointer-events: auto;
  max-width: 320px;
}
body.sidebar-collapsed .sidebar-group:hover > .sidebar-group-body,
body.sidebar-collapsed .sidebar-group:focus-within > .sidebar-group-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
body.sidebar-collapsed .sidebar-flyout-label {
  display: block;
  padding: var(--spacing-1) var(--spacing-2) var(--spacing-2);
  margin-bottom: var(--spacing-1);
  border-bottom: 1px solid var(--color-border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
/* Inside the flyout, show full-text links (override the global label-hiding rule). */
body.sidebar-collapsed .sidebar-group-body .sidebar-label { display: inline; }
body.sidebar-collapsed .sidebar-group-body .sidebar-link {
  justify-content: flex-start;
  padding: var(--spacing-2) var(--spacing-3);
}
body.sidebar-collapsed .sidebar-group-body .sidebar-link.active::before { left: -3px; }

.shell-main { padding: var(--spacing-5); max-width: 1400px; margin: 0 auto; width: 100%; min-width: 0; }

/* Cards / surfaces */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-5);
  margin-bottom: var(--spacing-4);
}
.card h2 { margin: 0 0 var(--spacing-4) 0; font-size: 18px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-5);
  gap: var(--spacing-4);
}
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .actions { display: flex; gap: var(--spacing-2); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: var(--spacing-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
th { font-size: 12px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--color-surface-2); }
.row-action { width: 80px; text-align: right; padding-right: 12px; }
button.small { padding: 4px 10px; font-size: 12px; }
.notification-row:hover { background: var(--color-surface-2); }
.notification-unread { background: var(--color-surface-2, rgba(255,255,255,0.04)); border-left: 3px solid var(--color-primary, #2db5ff); }
.tabbar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
}
.tabbar a {
  padding: 10px 16px;
  text-decoration: none;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 500;
  font-size: 14px;
  transition: color 120ms, border-color 120ms;
}
.tabbar a:hover {
  color: var(--color-text);
}
.tabbar a.active {
  color: var(--color-primary, #2db5ff);
  border-bottom-color: var(--color-primary, #2db5ff);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.photo-tile {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 120ms, box-shadow 120ms;
}
.photo-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.photo-tile-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--color-surface-2);
}
.photo-tile-meta {
  padding: 8px 12px 10px;
}
.photo-tile-caption {
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-tile-archived-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.02em;
}
.photo-detail-img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  background: var(--color-surface-2);
  border-radius: var(--radius);
}

/* Inline gallery strip used inside other modules' detail modals. */
.photo-gallery-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.photo-gallery-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.photo-gallery-header h3 {
  margin: 0;
  font-size: 14px;
}
.photo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.photo-strip-tile {
  display: block;
  width: 96px;
  height: 72px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
.photo-strip-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pill-info { background: rgba(45,181,255,0.15); color: #2db5ff; }
.pill-action { background: rgba(255,165,0,0.15); color: #ffa500; }
.pill-warning { background: rgba(255,200,0,0.2); color: #ffc800; }
.pill-critical { background: rgba(255,80,80,0.2); color: #ff5050; }
.pill-unread { background: rgba(45,181,255,0.2); color: #2db5ff; font-size: 10px; }

/* Login */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--spacing-5);
}
.login-card {
  max-width: 380px;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-6);
  box-shadow: var(--shadow-md);
}
.login-card .login-logo {
  display: block;
  width: auto;
  height: 56px;
  max-width: 100%;
  object-fit: contain;
  margin: 0 auto var(--spacing-5);
}
.login-card h1 { margin: 0 0 var(--spacing-2) 0; font-size: 22px; text-align: center; }
.login-card p.sub { color: var(--color-text-muted); margin: 0 0 var(--spacing-5) 0; font-size: 13px; text-align: center; }

/* Status pills */
.pill {
  display: inline-block;
  padding: 2px var(--spacing-2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
.pill.draft { background: #e2e8f0; color: #2d3748; }
.pill.active { background: #c6f6d5; color: #1a4731; }
.pill.onhold { background: #fefcbf; color: #744210; }
.pill.completed { background: #bee3f8; color: #1a4467; }
.pill.archived { background: #fed7d7; color: #822727; }
.pill.approved { background: #c6f6d5; color: #1a4731; }
.pill.pending { background: #e2e8f0; color: #2d3748; }
.pill.inprogress { background: #feebc8; color: #744210; }
.pill.cancelled { background: #fed7d7; color: #822727; }
/* Numeric pill variants — Sprint-21+ pages render status enums by ordinal so the
   same CSS works for any aggregate's lifecycle. Index-to-meaning is per-page,
   but the colour palette tracks the same Draft → live → terminal/error gradient
   used by the named classes above. */
.pill-0 { background: #e2e8f0; color: #2d3748; }              /* Draft / Pending */
.pill-1 { background: #feebc8; color: #744210; }              /* Issued / OutForBid / Active / Reached */
.pill-2 { background: #c6f6d5; color: #1a4731; }              /* Paid / Awarded / Completed / Invoiced */
.pill-3 { background: #fed7d7; color: #822727; }              /* Cancelled / Terminated / Declined / Rejected */
.pill-4 { background: #fbb6ce; color: #702459; }              /* Voided */

/* Tree (WBS) */
.tree { font-family: var(--font-mono); font-size: 13px; }
.tree-node { padding: var(--spacing-1) 0; border-bottom: 1px dashed var(--color-border); }
.tree-node:last-child { border-bottom: none; }
.tree-row { display: grid; grid-template-columns: 1fr auto auto auto auto; gap: var(--spacing-3); align-items: center; }
.tree-row .code { color: var(--color-text-muted); font-weight: 600; }
.tree-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.tree-children { margin-left: var(--spacing-5); border-left: 1px solid var(--color-border); padding-left: var(--spacing-3); }

/* Tabs */
.tabs { display: flex; gap: var(--spacing-1); border-bottom: 1px solid var(--color-border); margin-bottom: var(--spacing-4); }
.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--spacing-3) var(--spacing-4);
  border-radius: 0;
  color: var(--color-text-muted);
  font-weight: 500;
}
.tabs button.active { color: var(--color-primary-text); border-bottom-color: var(--color-primary); }
.tabs button:hover { color: var(--color-text); background: transparent; }

/* Modal dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--spacing-5) var(--spacing-5);
  z-index: 900;
  animation: fade-in 120ms ease-out;
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-5);
  box-shadow: var(--shadow-md);
  max-width: 720px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: modal-in 160ms ease-out;
}

.modal h2 { margin: 0 0 var(--spacing-2) 0; font-size: 18px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Link buttons used inline in tables */
button.link.danger { color: var(--color-danger); }
button.link.danger:hover { background: var(--color-surface-2); color: var(--color-danger); }

/* Toast notifications */
#toast-root {
  position: fixed;
  top: var(--spacing-5);
  right: var(--spacing-5);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius);
  padding: var(--spacing-3) var(--spacing-4);
  box-shadow: var(--shadow-md);
  max-width: 360px;
  pointer-events: auto;
  animation: slide-in 160ms ease-out;
}
.toast.error { border-left-color: var(--color-danger); }
.toast.success { border-left-color: var(--color-success); }
.toast.warning { border-left-color: var(--color-warning); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Empty + loading states */
.empty { text-align: center; color: var(--color-text-muted); padding: var(--spacing-6); }
.loading { text-align: center; color: var(--color-text-muted); padding: var(--spacing-6); font-style: italic; }

/* Utility */
.row { display: flex; gap: var(--spacing-4); flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.muted { color: var(--color-text-muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.numeric { font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: var(--spacing-3); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--spacing-2) var(--spacing-4); }
.dl dt { color: var(--color-text-muted); font-size: 12px; }
.dl dd { margin: 0; }

/* `.kv` -- key/value rows used by every detail modal + several inline cards.
   Each direct child is `<div><strong>label</strong><span>value</span></div>`;
   `display: contents` lets the children participate in the parent grid so all
   labels align in a single column regardless of label-text length. */
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--spacing-1) var(--spacing-4);
  align-items: baseline;
}
.kv > div { display: contents; }
.kv > div > strong {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kv > div > span {
  font-weight: 400;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* Two-column layout used by the BIM viewer (canvas + side panel) and any
   future page that needs a fixed-width sidebar next to a flexible main area.
   The right column has a min/max so it doesn't crush below ~280px or stretch
   wider than ~360px. */
.layout-canvas-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 360px);
  gap: var(--spacing-3);
  align-items: start;
}
@media (max-width: 720px) {
  .layout-canvas-side { grid-template-columns: minmax(0, 1fr); }
}
.kpis,
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--spacing-3); }
.kpi { background: var(--color-surface-2); padding: var(--spacing-4); border-radius: var(--radius); }
.kpi .label,
.kpi .kpi-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .value,
.kpi .kpi-value { font-size: 22px; font-weight: 600; margin-top: var(--spacing-2); font-variant-numeric: tabular-nums; }
.kpi .kpi-help { font-size: 11px; color: var(--color-text-muted); margin-top: var(--spacing-2); line-height: 1.3; }
