/*
 * Control Centre — shared dashboard shell stylesheet
 *
 * Single source of truth for the topbar/sidebar/nav look shared across every
 * internal app (Cerriva DAM, Cerriva PIM, Control Centre itself, and any
 * app built to this shell). Apps link this file directly instead of
 * re-implementing the shell's visual styling locally — edit this file,
 * every linked app picks it up on next page load, no per-app redeploy.
 *
 * Apps still own their own markup (Layout/Aside/HeaderBar components) and
 * still write the class names below onto their own elements — this file
 * only supplies the *look* (colors, spacing, states), not the structure.
 *
 * Whitelabeling per app/domain: override any --dash-* custom property in
 * the app's own (small, local) CSS, loaded AFTER this stylesheet — e.g.
 *   :root { --dash-accent: #e2543f; --dash-font-family: "Poppins", sans-serif; }
 * is enough for a full accent + type rebrand; overriding --dash-sidebar-bg
 * and --dash-content-bg too gets a deeper one. A client's own web font
 * still needs its own @font-face/Google Fonts <link> in that app (fonts
 * aren't bundled into this shared file), --dash-font-family just points
 * the shell at whatever family the app already loaded. The app's own
 * logo/name markup in its topbar was always local, never part of this
 * file, so swapping in a client's logo needs no extra mechanism either —
 * just change what's inside .dash-topbar in that app's own HeaderBar.
 *
 * Hosted at https://assets.mathijsjansen.nl/dashboard-shell.css
 */

:root {
  --dash-topbar-height: 40px;
  --dash-sidebar-width: 220px;

  --dash-topbar-bg: #f8f8f8;
  --dash-topbar-border: #e0e0e0;

  --dash-sidebar-bg: #1a1a2e;
  --dash-sidebar-text: rgba(255, 255, 255, 0.7);
  --dash-sidebar-text-active: #ffffff;
  --dash-sidebar-border: rgba(255, 255, 255, 0.1);
  --dash-sidebar-active-bg: rgba(255, 255, 255, 0.08);

  /* Per-app accent — override with a single line in the app's own CSS:
     :root { --dash-accent: #your-color; } */
  --dash-accent: #34d399;

  --dash-content-bg: #ffffff;
  --dash-text-primary: #222222;
  --dash-text-secondary: #666666;
  --dash-text-muted: #999999;
  --dash-border-light: #eeeeee;

  --dash-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Per-client logo — set by a client's ClientTheme (see
     lib/clientTheme.js), never by an app directly. Unset by default so
     .dash-topbar-logo renders as nothing (0 width) until a logo exists. */
  --dash-logo-url: none;

  --dash-app-rail-width: 56px;
  --dash-app-rail-expanded-width: 208px;
}

.dash-topbar,
.dash-sidebar,
.dash-main {
  font-family: var(--dash-font-family);
}

/* Topbar — fixed, 40px, app chrome on the left, user menu on the right. */
.dash-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--dash-topbar-height);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--dash-topbar-bg);
  border-bottom: 1px solid var(--dash-topbar-border);
  font-size: 13px;
  color: var(--dash-text-primary);
}

.dash-topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--dash-text-secondary);
}

/* Top-left client logo. Hidden by default (CSS can't conditionally react
   to whether --dash-logo-url is "set" — display: var(--dash-logo-url) isn't
   valid, that variable holds a url(...)). A client theme with a logo emits
   its own `.dash-topbar-logo { display: inline-block; }` override alongside
   --dash-logo-url (see lib/clientTheme.js's renderClientThemeCss) to make
   it visible — put an empty element with this class where the app's own
   name/logo currently sits, it stays invisible until that override lands. */
.dash-topbar-logo {
  display: none;
  width: 64px;
  height: 48px;
  background-image: var(--dash-logo-url);
  background-repeat: no-repeat;
  background-position: left center;
  background-size: contain;
}

.dash-topbar-spacer {
  flex: 1;
}

.dash-topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--dash-text-secondary);
  cursor: pointer;
}

/* Cross-app switcher rail — opt-in. An app renders a fixed-left column of
   square icon badges (see https://assets.mathijsjansen.nl/app-switcher.json
   for the data, published by Control Centre's Stack page) AND adds
   `has-app-rail` to <body>, which is what actually shifts the topbar/
   sidebar/main over to make room — an app that doesn't add the class can
   ignore all of this, nothing here affects it. Currently used by rag and
   brand as the first two apps testing cross-app navigation.

   Collapsed it's just the icon column (--dash-app-rail-width); hovering
   the rail (not each icon individually) widens it as an overlay — z-index
   already puts it above the topbar/sidebar, so expanding doesn't reflow
   anything else — revealing each app's name next to its icon. */
.dash-app-rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--dash-app-rail-width);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 10px;
  background: #0f0f1e;
  border-right: 1px solid var(--dash-sidebar-border);
  overflow: hidden;
  transition: width 0.18s ease;
}

.dash-app-rail:hover {
  width: var(--dash-app-rail-expanded-width);
}

.dash-app-rail-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  color: #ffffff;
  text-decoration: none;
  opacity: 0.75;
  transition: opacity 0.15s ease;
}

.dash-app-rail-icon:hover {
  opacity: 1;
}

.dash-app-rail-badge {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.dash-app-rail-icon:hover .dash-app-rail-badge {
  transform: scale(1.06);
}

/* The active app was only getting a ring, still sitting at the same
   dimmed 0.75 opacity as every other icon unless actually hovered — from
   a glance it didn't read as "the one you're in" at all. Full opacity +
   a soft glow (not just a hard ring) makes it unambiguous. */
.dash-app-rail-icon.active {
  opacity: 1;
}

.dash-app-rail-icon.active .dash-app-rail-badge {
  box-shadow: 0 0 0 2px var(--dash-accent), 0 0 14px -1px var(--dash-accent);
}

.dash-app-rail-icon.active .dash-app-rail-label {
  color: #ffffff;
  font-weight: 700;
}

.dash-app-rail-badge svg {
  width: 20px;
  height: 20px;
}

/* Laid out (and taking up width) even while collapsed — the rail's own
   overflow: hidden clips it until the rail expands on hover, so it
   reveals rather than pops in. */
.dash-app-rail-label {
  flex-shrink: 0;
  font-family: var(--dash-font-family);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

body.has-app-rail .dash-topbar {
  left: var(--dash-app-rail-width);
}

body.has-app-rail .dash-sidebar {
  left: var(--dash-app-rail-width);
}

body.has-app-rail .dash-main {
  margin-left: calc(var(--dash-sidebar-width) + var(--dash-app-rail-width));
}

/* Sidebar — fixed, dark navy, offset below the topbar. */
.dash-sidebar {
  position: fixed;
  top: var(--dash-topbar-height);
  bottom: 0;
  left: 0;
  width: var(--dash-sidebar-width);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--dash-sidebar-bg);
  overflow-y: auto;
  transition: transform 0.2s ease;
}

.dash-nav-top {
  flex: 1;
  padding: 8px 0;
}

.dash-nav-bottom {
  padding: 8px 0;
  border-top: 1px solid var(--dash-sidebar-border);
}

.dash-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--dash-sidebar-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.1s ease, color 0.1s ease;
}

.dash-nav-item:hover {
  color: var(--dash-sidebar-text-active);
  background: rgba(255, 255, 255, 0.04);
}

.dash-nav-item.active {
  border-left-color: var(--dash-accent);
  background: var(--dash-sidebar-active-bg);
  color: var(--dash-sidebar-text-active);
}

.dash-nav-item svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

/* Mobile off-canvas scrim (click-outside-to-close). */
.dash-scrim {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--dash-topbar-height);
  background: rgba(0, 0, 0, 0.3);
  z-index: 30;
}

.dash-scrim.open {
  display: block;
}

/* Main content — light theme, offset by the topbar + sidebar. */
.dash-main {
  margin-left: var(--dash-sidebar-width);
  margin-top: var(--dash-topbar-height);
  min-height: calc(100vh - var(--dash-topbar-height));
  background: var(--dash-content-bg);
  color: var(--dash-text-primary);
  overflow-y: auto;
  padding: 24px;
}

@media (max-width: 768px) {
  .dash-topbar-menu-btn {
    display: block;
  }

  .dash-sidebar {
    transform: translateX(-100%);
  }

  .dash-sidebar.open {
    transform: translateX(0);
  }

  .dash-main {
    margin-left: 0;
  }

  /* The off-canvas sidebar already owns the left edge on mobile — keep the
     rail out of the way rather than teaching it to co-exist with the
     hamburger drawer too. */
  .dash-app-rail {
    display: none;
  }

  body.has-app-rail .dash-topbar,
  body.has-app-rail .dash-sidebar {
    left: 0;
  }

  body.has-app-rail .dash-main {
    margin-left: 0;
  }
}

/* Login / first-run setup screen — full-viewport centered card on a dark
   diagonal gradient, one form serving both modes (setup vs. sign-in). */
.dash-login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--dash-sidebar-bg) 0%, #16213e 100%);
  font-family: var(--dash-font-family);
}

.dash-login-card {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 40px 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.dash-login-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--dash-text-primary);
}

.dash-login-subtitle {
  font-size: 14px;
  text-align: center;
  color: var(--dash-text-muted);
}

.dash-login-input {
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: var(--dash-font-family);
}

.dash-login-input.error {
  border-color: #e53935;
}

.dash-login-button {
  padding: 10px 12px;
  border-radius: 6px;
  border: none;
  width: 100%;
  background: #222222;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.dash-login-button:disabled {
  opacity: 0.7;
  cursor: default;
}

.dash-login-error {
  font-size: 13px;
  color: #e53935;
}
