/*
 * Afford-X app shell: design tokens, left rail, top bar and the right-hand
 * Compass panel. Mounted by /js/afx-nav.js; the Compass chat itself comes from
 * /js/afx-compass-dock.js.
 *
 * Visual language follows John's platform mockup (same family as the website):
 * navy rail, light #F6F8FA canvas, white cards with a soft shadow, Poppins,
 * jade #54A966 as the action color and the red / yellow / jade decile ribbon.
 * Light is the default theme; dark uses the mockup's navy surfaces.
 * Page stylesheets map their own variables onto the --afx-* tokens below.
 */

:root,
html[data-theme="light"] {
  /* Brand palette (mockup) */
  --afx-navy: #0d1b2a;
  --afx-jade: #54a966;
  --afx-red: #bf0603;
  --afx-yellow: #fcba04;
  --afx-powder: #96adc8;
  --afx-jade-soft: #eaf5ee;
  --afx-red-soft: #fbebea;
  --afx-yellow-soft: #fef6e0;
  --afx-powder-soft: #eef3f8;
  --afx-yellow-ink: #8a6403;
  --afx-powder-ink: #4a6a8f;

  /* Surfaces */
  --afx-bg: #f6f8fa;
  --afx-surface-1: #ffffff;
  --afx-surface-2: #f6f8fa;
  --afx-surface-3: #eef3f8;
  --afx-card: #ffffff;
  --afx-card-2: #f6f8fa;
  --afx-card-3: #eef3f8;
  --afx-popover: #ffffff;
  --afx-border-subtle: #e3e9f0;
  --afx-border-default: #e3e9f0;
  --afx-border-strong: #d3dce6;

  /* Text */
  --afx-fg: #0d1b2a;
  --afx-text-strong: #0d1b2a;
  --afx-text-muted: #44546a;
  --afx-text-subtle: #7a8aa0;
  --afx-text-faint: #a3b1c2;

  /* Brand / semantic */
  --afx-brand-300: #7fbf8d;
  --afx-brand-400: #54a966;
  --afx-brand-500: #54a966;
  --afx-brand-600: #478f57;
  --afx-primary: var(--afx-jade);
  --afx-primary-fg: #ffffff;
  --afx-cta: var(--afx-jade);
  --afx-cta-hover: #478f57;
  --afx-cta-fg: #ffffff;
  --afx-destructive: var(--afx-red);
  --afx-warning: var(--afx-yellow-ink);
  --afx-info: var(--afx-powder-ink);
  --afx-ai: var(--afx-jade);
  --afx-ai-bg: var(--afx-jade-soft);
  --afx-chart-1: var(--afx-jade);
  --afx-chart-2: var(--afx-powder);
  --afx-chart-3: var(--afx-yellow);
  --afx-chart-4: var(--afx-navy);
  --afx-chart-5: var(--afx-red);

  /* Rail (always navy) */
  --afx-rail: #0d1b2a;
  --afx-rail-ink: #c9d6e4;
  --afx-rail-ink-dim: #7e93ab;
  --afx-sidebar: #ffffff; /* Compass panel background */

  --afx-shadow: 0 1px 2px rgba(13, 27, 42, 0.05), 0 8px 24px rgba(13, 27, 42, 0.06);
  --afx-shadow-pop: 0 12px 32px rgba(13, 27, 42, 0.14);
  --afx-focus: rgba(84, 169, 102, 0.35);

  /* Cards: kept as "fill + edge" so pages using the padding-box/border-box
     pattern render the mockup's flat card with a 1px line border. */
  --afx-grad-fill: linear-gradient(var(--afx-card), var(--afx-card));
  --afx-grad-edge: linear-gradient(var(--afx-border-default), var(--afx-border-default));

  --afx-r-lg: 16px;
  --afx-r-md: 12px;
  --afx-r-sm: 8px;
  --afx-radius: 10px;
  --afx-font-sans: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --afx-font-heading: var(--afx-font-sans);
  --afx-font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

html[data-theme="dark"] {
  --afx-jade-soft: #12301f;
  --afx-red-soft: #361113;
  --afx-yellow-soft: #33290c;
  --afx-powder-soft: #16283a;
  --afx-yellow-ink: var(--afx-yellow);
  --afx-powder-ink: var(--afx-powder);

  --afx-bg: #0a1420;
  --afx-surface-1: #111f2e;
  --afx-surface-2: #16283a;
  --afx-surface-3: #1c3147;
  --afx-card: #111f2e;
  --afx-card-2: #16283a;
  --afx-card-3: #1c3147;
  --afx-popover: #111f2e;
  --afx-border-subtle: #22354a;
  --afx-border-default: #22354a;
  --afx-border-strong: #2c425a;

  --afx-fg: #eaf1f8;
  --afx-text-strong: #ffffff;
  --afx-text-muted: #b4c4d6;
  --afx-text-subtle: #7e93ab;
  --afx-text-faint: #56708b;

  --afx-destructive: #e5534b;
  --afx-warning: var(--afx-yellow);
  --afx-chart-4: #eaf1f8;

  --afx-rail: #08111b;
  --afx-sidebar: #111f2e;

  --afx-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --afx-shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* Mockup card: white surface, 1px line, soft shadow. */
.afx-card-grad {
  border: 1px solid var(--afx-border-default) !important;
  background: var(--afx-card) !important;
  box-shadow: var(--afx-shadow);
}

@keyframes afx-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Decile ribbon: D1–D3 red, D4–D7 yellow, D8–D10 jade. */
.afx-ribbon {
  display: flex;
  gap: 3px;
}
.afx-ribbon i {
  height: 8px;
  flex: 1;
  border-radius: 3px;
}
.afx-ribbon i:nth-child(-n + 3) { background: var(--afx-red); }
.afx-ribbon i:nth-child(n + 4):nth-child(-n + 7) { background: var(--afx-yellow); }
.afx-ribbon i:nth-child(n + 8) { background: var(--afx-jade); }
.afx-ribbon.is-tall i { height: 12px; }

/* ---------- Layout variables ---------- */

html.afxs-app {
  --afxs-sidebar-w: 236px;
  --afxs-header-h: 56px;
  --afxs-agent-w: 0px;
  /* Offsets page-level fixed elements (overlays, toasts) can use. */
  --afxs-left: var(--afxs-sidebar-w);
  --afxs-right: var(--afxs-agent-w);
  --afxs-top: var(--afxs-header-h);
  padding: var(--afxs-header-h) var(--afxs-agent-w) 0 var(--afxs-sidebar-w);
  background: var(--afx-bg);
  scroll-padding-top: calc(var(--afxs-header-h) + 16px);
}
html.afxs-app.afxs-sidebar-collapsed {
  --afxs-sidebar-w: 0px;
}
html.afxs-app.afxs-agent-open {
  --afxs-agent-w: var(--afxs-agent-size, 380px);
}
html.afxs-app.afxs-animate {
  transition: padding 0.2s ease-out;
}
html.afxs-app body {
  background: transparent !important;
  min-height: calc(100vh - var(--afxs-header-h)) !important;
  font-family: var(--afx-font-sans);
  -webkit-font-smoothing: antialiased;
}
html.afxs-app h1,
html.afxs-app h2,
html.afxs-app h3,
html.afxs-app h4 {
  font-family: var(--afx-font-heading);
}

/* Old per-page chrome that the shell replaces. */
html.afxs-app header.afx-top,
html.afxs-app .topbar {
  display: none !important;
}

.afxs-ico {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.afxs-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.afxs-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 999px; }
.afxs-scroll::-webkit-scrollbar-track { background: transparent; }

/* Shell elements reset whatever the host page does to buttons, links and fonts. */
#afx-app-nav,
#afx-app-nav *,
.afxs-agent,
.afxs-agent * {
  box-sizing: border-box;
}
#afx-app-nav,
.afxs-agent {
  font-family: var(--afx-font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--afx-fg);
  -webkit-font-smoothing: antialiased;
}
#afx-app-nav a,
.afxs-agent a {
  text-decoration: none;
  color: inherit;
}
#afx-app-nav button,
.afxs-agent button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  cursor: pointer;
}

/* ---------- Rail (left sidebar) ---------- */

.afxs-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
  width: var(--afxs-sidebar-w);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--afx-rail);
  color: var(--afx-rail-ink);
}
.afxs-animate .afxs-sidebar {
  transition: width 0.2s ease-out, transform 0.2s ease-out;
}
.afxs-sidebar-inner {
  width: 236px;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.afxs-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 10px;
  color: #ffffff !important;
}
.afxs-logo img {
  height: 30px;
  width: auto;
  display: block;
}
.afxs-logo-word {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #ffffff;
}
.afxs-tagline {
  flex-shrink: 0;
  margin: 0;
  padding: 0 20px 14px;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--afx-rail-ink-dim);
}
.afxs-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
}
.afxs-group-label {
  margin: 0;
  padding: 14px 10px 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--afx-rail-ink-dim);
}
.afxs-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--afx-rail-ink) !important;
  transition: background-color 0.15s, color 0.15s;
}
.afxs-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff !important;
}
.afxs-link.is-on {
  background: rgba(84, 169, 102, 0.18);
  color: #ffffff !important;
}
.afxs-num {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--afx-rail-ink-dim);
}
.afxs-num .afxs-ico {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}
.afxs-link.is-on .afxs-num {
  background: var(--afx-jade);
  color: #ffffff;
}
.afxs-link span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.afxs-badge-ai {
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(84, 169, 102, 0.22);
  color: #9fd8ab;
  font-size: 9.5px;
  font-weight: 600;
}

/* Workspace / user menu at the bottom of the rail */
.afxs-user {
  position: relative;
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.afxs-user-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  text-align: left;
  color: var(--afx-rail-ink) !important;
  transition: background-color 0.15s;
}
.afxs-user-btn:hover,
.afxs-user.is-open .afxs-user-btn {
  background: rgba(255, 255, 255, 0.06);
}
.afxs-user-copy {
  min-width: 0;
  flex: 1;
}
.afxs-user-name,
.afxs-user-sub {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.afxs-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--afx-rail-ink);
}
.afxs-user-sub {
  font-size: 11px;
  color: var(--afx-rail-ink-dim);
}
.afxs-user-btn > .afxs-ico {
  width: 14px;
  height: 14px;
  color: var(--afx-rail-ink-dim);
}
.afxs-menu {
  position: absolute;
  left: 12px;
  bottom: calc(100% - 4px);
  width: 212px;
  padding: 6px;
  border: 1px solid var(--afx-border-default);
  border-radius: var(--afx-r-md);
  background: var(--afx-popover);
  box-shadow: var(--afx-shadow-pop);
  display: none;
  z-index: 5;
}
.afxs-user.is-open .afxs-menu {
  display: block;
}
.afxs-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  color: var(--afx-fg) !important;
}
.afxs-menu-item:hover,
.afxs-menu-item:focus-visible {
  background: var(--afx-surface-3);
  outline: none;
}
.afxs-menu-item .afxs-ico {
  width: 15px;
  height: 15px;
  color: var(--afx-text-subtle);
}
.afxs-menu-item.is-danger,
.afxs-menu-item.is-danger .afxs-ico {
  color: var(--afx-destructive) !important;
}
.afxs-menu-item[aria-checked="true"]::after {
  content: "";
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--afx-jade);
}
.afxs-menu-sep {
  height: 1px;
  margin: 5px -6px;
  background: var(--afx-border-default);
}
.afxs-menu-label {
  margin: 0;
  padding: 6px 8px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--afx-text-subtle);
}

/* ---------- Top bar ---------- */

.afxs-header {
  position: fixed;
  top: 0;
  left: var(--afxs-sidebar-w);
  right: var(--afxs-agent-w);
  z-index: 50;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 32px;
  background: var(--afx-surface-1);
  border-bottom: 1px solid var(--afx-border-default);
}
.afxs-animate .afxs-header {
  transition: left 0.2s ease-out, right 0.2s ease-out;
}
.afxs-icon-btn {
  width: 30px;
  height: 30px;
  margin-left: -6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--afx-text-subtle) !important;
  transition: background-color 0.15s, color 0.15s;
}
.afxs-icon-btn:hover {
  background: var(--afx-surface-3);
  color: var(--afx-fg) !important;
}
.afxs-menu-btn {
  display: none;
}
.afxs-crumbs {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--afx-text-subtle);
  white-space: nowrap;
  overflow: hidden;
}
.afxs-crumbs a {
  color: var(--afx-text-subtle) !important;
}
.afxs-crumbs a:hover {
  color: var(--afx-fg) !important;
}
.afxs-crumbs .is-last {
  color: var(--afx-fg);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.afxs-header-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.afxs-org {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 260px;
  padding: 5px 12px;
  border: 1px solid var(--afx-border-strong);
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--afx-text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.afxs-org::before {
  content: "";
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--afx-jade);
}
/* Mockup "Theme" button and the Compass toggle share the outline style. */
.afxs-top-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--afx-border-strong) !important;
  border-radius: 10px;
  font-size: 12px !important;
  font-weight: 500;
  color: var(--afx-text-muted) !important;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.afxs-top-btn:hover {
  border-color: var(--afx-jade) !important;
  color: var(--afx-fg) !important;
}
.afxs-ai-btn img {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  object-fit: cover;
  display: block;
}
.afxs-agent-open .afxs-ai-btn {
  border-color: var(--afx-jade) !important;
  background: var(--afx-jade-soft);
  color: var(--afx-fg) !important;
}
.afxs-kbd {
  padding: 0 5px;
  border: 1px solid var(--afx-border-default);
  border-radius: 5px;
  background: var(--afx-surface-2);
  font-family: var(--afx-font-mono);
  font-size: 10px;
  color: var(--afx-text-subtle);
}

/* ---------- Compass panel (right) ---------- */

.afxs-agent {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: var(--afxs-agent-size, 380px);
  display: none;
  flex-direction: column;
  background: var(--afx-sidebar);
  border-left: 1px solid var(--afx-border-default);
}
.afxs-agent-open .afxs-agent {
  display: flex;
}
.afxs-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  width: 8px;
  cursor: col-resize;
  z-index: 2;
}
.afxs-resize::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 4px;
  height: 28px;
  margin-top: -14px;
  border-radius: 4px;
  background: var(--afx-border-strong);
  opacity: 0;
  transition: opacity 0.15s;
}
.afxs-resize:hover::after,
.afxs-resizing .afxs-resize::after {
  opacity: 1;
}
.afxs-resizing,
.afxs-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}
.afxs-agent-head {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--afx-border-default);
}
.afxs-agent-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
  font-weight: 600;
}
.afxs-agent-icon {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  object-fit: cover;
  display: block;
}
.afxs-agent-sub {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--afx-text-subtle);
}
.afxs-agent-head .afxs-icon-btn {
  margin: 0;
}
.afxs-agent-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.afxs-backdrop {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  /* Compass overlays the page instead of squeezing it. */
  html.afxs-app.afxs-agent-open {
    --afxs-agent-w: 0px;
  }
  .afxs-agent {
    width: min(420px, 100vw);
    box-shadow: var(--afx-shadow-pop);
  }
  .afxs-resize {
    display: none;
  }
}

@media (max-width: 900px) {
  html.afxs-app,
  html.afxs-app.afxs-sidebar-collapsed {
    --afxs-sidebar-w: 0px;
  }
  .afxs-sidebar {
    width: 236px;
    transform: translateX(-100%);
  }
  .afxs-drawer-open .afxs-sidebar {
    transform: none;
    box-shadow: var(--afx-shadow-pop);
  }
  .afxs-collapse-btn {
    display: none !important;
  }
  .afxs-menu-btn {
    display: inline-flex;
  }
  .afxs-header {
    padding: 0 16px;
  }
  .afxs-org,
  .afxs-top-label,
  .afxs-kbd,
  .afxs-theme-btn {
    display: none;
  }
  .afxs-drawer-open .afxs-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(13, 27, 42, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  html.afxs-app.afxs-animate,
  .afxs-animate .afxs-sidebar,
  .afxs-animate .afxs-header {
    transition: none;
  }
}

/* ---------- Sign-in layout (no rail) ---------- */

html.afxs-auth {
  background: var(--afx-bg);
}
html.afxs-auth body {
  background: transparent !important;
  font-family: var(--afx-font-sans);
  -webkit-font-smoothing: antialiased;
}
html.afxs-auth header.afx-top {
  display: none !important;
}
