/* ===============================================================
   Genesis Image CDN - portal-specific theme additions
   Loaded after genesis-tokens.css + genesis-bootstrap-bridge.css.
   Everything here is cdn-portal-specific: the 3-group sidebar shell
   (Source/Publish/Admin, with rails off the shared --cat-* ramp per
   design-alignment decision #2), the auth page, the theme toggle,
   and the .genesis-table/badge/stat-card conventions ported from
   Brain Portal's class names (not its full CSS) so both apps read
   as the same design system without importing Brain-Portal-only
   nav-rail tokens (see genesis-brain/design-tokens/README.md).
   =============================================================== */

/* -- Sidebar shell ------------------------------------------- */
.genesis-sidebar {
  width: 240px;
  height: 100vh;
  background: var(--bg-sunken);
  border-right: 1px solid var(--border-strong);
  color: var(--text);
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.genesis-sidebar .sidebar-brand {
  padding: 1rem 1rem 0.875rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.genesis-sidebar .sidebar-brand img {
  width: 32px; height: 32px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.genesis-sidebar .sidebar-brand h5 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
  margin: 0;
}
.genesis-sidebar .sidebar-brand .brand-sub {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-top: 2px;
}
.genesis-sidebar .nav-link {
  color: var(--text-secondary);
  padding: 0.42rem 0.875rem;
  border-radius: var(--radius-sm);
  margin: 1px 0.375rem;
  font-size: 0.8125rem;
  transition: background 0.12s, color 0.12s;
  display: flex; align-items: center; gap: 0.55rem;
}
.genesis-sidebar .nav-link:hover {
  background: var(--bg-surface);
  color: var(--text);
}
.genesis-sidebar .nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
.genesis-sidebar .nav-link i { font-size: 0.9rem; width: 1rem; text-align: center; flex-shrink: 0; }

.genesis-sidebar .nav-supergroup {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--section-rail, var(--text-muted));
  padding: 0.6rem 0.875rem 0.3rem 1rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--section-rail, transparent);
}
.genesis-sidebar .nav-group:first-child .nav-supergroup { border-top: none; margin-top: 0.25rem; }
.genesis-sidebar .nav-group { border-left: 3px solid var(--section-rail, transparent); }
.genesis-sidebar .nav-group .nav-link { border-left: none; margin-left: 0.375rem; }

/* Sidebar footer (user chip + logout) */
.genesis-sidebar .sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.genesis-sidebar .sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brain-teal);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
}
.genesis-sidebar .sidebar-user-name { font-size: 0.78rem; font-weight: 600; color: var(--text); word-break: break-all; }
.genesis-sidebar .sidebar-user-role { font-size: 0.68rem; color: var(--text-secondary); text-transform: capitalize; }

/* -- Responsive: off-canvas drawer below 768px ----------------- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.75rem; left: 0.75rem;
  z-index: 200;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}
.sidebar-backdrop { display: none; }

@media (max-width: 767.98px) {
  .sidebar-toggle { display: flex; }
  .genesis-sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
    z-index: 300;
  }
  .genesis-sidebar.mobile-open { transform: translateX(0); }
  .genesis-main { margin-left: 0 !important; }
  .genesis-content { padding: 1.25rem 1rem !important; padding-top: 3.5rem !important; }
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 250;
  }
}

/* -- Layout ------------------------------------------------- */
/* Subtle background life for the app chrome (2026-09-03, "we need a fun background" - the
   login page already has the real product-photo collage; this is its lightweight cousin for
   every other page). Pure CSS, no images/fonts to fetch, so it costs nothing to load - a soft
   dot grid plus two large, very low-opacity gradient blobs in the accent/teal palette, both
   fixed to the viewport so they don't scroll or repaint per-page. Sits behind .genesis-topbar
   and every .genesis-card/.stat-card (all opaque, var(--bg-surface)), so it only shows in the
   gutters/margins around real content - never competes with anything readable. Token-driven,
   so it re-tints itself automatically in dark mode with zero extra rules. */
.genesis-main {
  background-image:
    radial-gradient(circle at 8% 8%, color-mix(in srgb, var(--accent) 10%, transparent) 0%, transparent 38%),
    radial-gradient(circle at 96% 14%, color-mix(in srgb, var(--cat-1) 8%, transparent) 0%, transparent 42%),
    radial-gradient(circle, color-mix(in srgb, var(--border-strong) 55%, transparent) 1px, transparent 1.4px);
  background-size: auto, auto, 22px 22px;
  background-attachment: fixed, fixed, fixed;
  background-repeat: no-repeat, no-repeat, repeat;
}
[data-theme="dark"] .genesis-main {
  background-image:
    radial-gradient(circle at 8% 8%, color-mix(in srgb, var(--accent) 7%, transparent) 0%, transparent 38%),
    radial-gradient(circle at 96% 14%, color-mix(in srgb, var(--cat-1) 6%, transparent) 0%, transparent 42%),
    radial-gradient(circle, color-mix(in srgb, var(--border-strong) 35%, transparent) 1px, transparent 1.4px);
}
.genesis-main { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden; }
.genesis-topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  position: sticky; top: 0; z-index: 90;
}
.genesis-topbar .page-title { font-family: var(--font-display); font-weight: 500; font-size: 1.35rem; margin: 0; color: var(--text); }
.genesis-topbar .page-subtitle { font-size: 0.8125rem; color: var(--text-secondary); margin: 0; }
.genesis-content { padding: 1.5rem 2rem; flex: 1; width: 100%; max-width: 1600px; box-sizing: border-box; }

/* -- Cards -------------------------------------------------- */
.genesis-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}
.genesis-card.p-0 { padding: 0; }

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-card .stat-icon {
  width: 46px; height: 46px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-text);
}
.auto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

/* -- genesis-table: one convention for all admin tables ------
   Wrap the .table in .genesis-card.p-0 + .table-responsive, per
   the design-alignment plan (fixes 0-of-13 tables having a
   responsive wrapper today). */
.table-responsive { border-radius: var(--radius-lg); }
.genesis-table thead th {
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.85rem 1rem;
  white-space: nowrap;
}
.genesis-table tbody td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.genesis-table tbody tr:last-child td { border-bottom: none; }
.genesis-table tbody tr:hover { background: var(--bg-surface-2); }
.genesis-table td.actions-cell { white-space: nowrap; }

/* -- Status badges - one pill convention, replaces the mixed
   text-bg-* usage (13 of which were invisible text-bg-light on a
   light surface) ----------------------------------------------- */
.status-badge {
  display: inline-flex; align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
}
.status-badge.status-success { background: var(--success-soft); color: var(--success); }
.status-badge.status-warning { background: var(--warning-soft); color: var(--warning); }
.status-badge.status-danger  { background: var(--danger-soft);  color: var(--danger); }
.status-badge.status-info    { background: var(--info-soft);    color: var(--info); }
.status-badge.status-neutral { background: var(--bg-surface-2); color: var(--text-secondary); border: 1px solid var(--border); }
.status-badge.status-admin   { background: var(--cat-3-soft);   color: var(--cat-3); }

/* -- Auth page (login) ----------------------------------------- */
.auth-page {
  min-height: 100vh;
  background: var(--bg-sunken);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-card .auth-logo { text-align: center; margin-bottom: 1.75rem; }
.auth-card .auth-logo img { width: 64px; height: 64px; object-fit: contain; border-radius: 14px; }
.auth-card .auth-logo h4 { font-family: var(--font-display); font-weight: 500; color: var(--text); margin-top: 0.75rem; }
.auth-card .auth-logo p { color: var(--text-muted); font-size: 0.875rem; }

/* Background collage - a random sample of the CDN's own real product-image thumbnails, faded
   and duotone-tinted toward the accent palette (deliberately "slightly cartoony", not a stark
   photo grid) so it reads as texture behind the card, never competing with it for attention.
   The card itself sits above via z-index/shadow-lg (already set) and the collage layer is
   dimmed low enough that its own contrast never approaches the card's. */
.auth-collage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  padding: 6px;
  overflow: hidden;
  opacity: 0.35;
  filter: saturate(0.7) sepia(0.25) hue-rotate(-6deg);
  pointer-events: none;
}
[data-theme="dark"] .auth-collage { opacity: 0.22; filter: saturate(0.6) sepia(0.15) hue-rotate(-6deg) brightness(0.8); }
.auth-collage-tile {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-sunken);
  aspect-ratio: 1;
}
.auth-collage-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.auth-page { position: relative; overflow: hidden; }
.auth-card { position: relative; z-index: 1; }
@media (max-width: 767.98px) {
  .auth-collage { grid-template-columns: repeat(3, 1fr); }
}

/* -- Theme toggle ----------------------------------------------- */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.theme-toggle-btn:hover {
  background: var(--bg-surface);
  color: var(--text);
  border-color: var(--border-strong);
}

/* -- Global busy overlay - tokenised (was a hardcoded light-only
   rgba(255,255,255,.75) scrim that would look wrong in dark mode) */
#global-busy-overlay {
  background: color-mix(in srgb, var(--bg-app) 82%, transparent);
}
#global-busy-overlay .spinner-border { color: var(--accent) !important; }
#global-busy-message { color: var(--text); }

/* -- Misc hardcoded-light fixes carried over from the design sweep
   (thumbnail backgrounds, lookup-result borders) --------------- */
.thumb-bg { background: var(--bg-surface-2); }
.result-border { border-color: var(--border) !important; }

/* -- API reference page (2026-09-03, cdn-portal reconciliation) --
   Mirrors Brain Portal's own /api-reference presentation (method
   badge + auth pill + expandable params/response), recreated in
   plain Bootstrap/Jinja rather than the React component itself. */
.api-hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--bg-surface) 60%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
}
.api-base-url {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  word-break: break-all;
}
.api-endpoint { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-surface); margin-bottom: 0.6rem; overflow: hidden; }
.api-endpoint-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}
.api-endpoint-head:hover { background: var(--bg-surface-2); }
.api-endpoint-path { font-family: var(--font-mono); font-size: 0.86rem; color: var(--text); }
.api-endpoint-summary { color: var(--text-secondary); font-size: 0.82rem; flex: 1 1 auto; min-width: 0; }
.api-endpoint-chevron { color: var(--text-muted); transition: transform 0.15s; flex-shrink: 0; }
.api-endpoint.open .api-endpoint-chevron { transform: rotate(90deg); }
.api-endpoint-body { display: none; padding: 0 1rem 1rem; border-top: 1px solid var(--border); }
.api-endpoint.open .api-endpoint-body { display: block; padding-top: 0.85rem; }
.method-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  border-radius: var(--radius-sm);
  padding: 0.22rem 0.5rem;
  min-width: 58px;
  text-align: center;
  flex-shrink: 0;
}
.method-GET    { background: var(--success-soft); color: var(--success); }
.method-POST   { background: var(--info-soft);    color: var(--info); }
.method-DELETE { background: var(--danger-soft);  color: var(--danger); }
.method-PATCH, .method-PUT { background: var(--warning-soft); color: var(--warning); }
.api-params-table th, .api-params-table td { font-size: 0.8rem; }
.api-params-table code { font-size: 0.78rem; }
