/* ==========================================================================
   BFF App Framework -- shared design tokens + navbar
   ==========================================================================
   Every product loads this stylesheet ahead of its own styles.css and sets
   `data-theme="light"` / `data-theme="dark"` on <html> to force a theme.
   Leaving the attribute off falls back to the visitor's OS preference via
   the prefers-color-scheme block below -- see UserSettingsView / the
   `theme` context processor for how the attribute gets set.
   ========================================================================== */

:root {
  /* Light palette (default) -- modeled on data-utopia-core */
  --bg:        #f7f8fa;
  --surface:   #ffffff;
  --border:    #e2e5ea;
  --accent:    #0d6efd;
  --accent2:   #6610f2;
  --accent3:   #0891b2;
  --green:     #157347;
  --yellow:    #a1670a;
  --red:       #b02a37;
  --muted:     #6c757d;
  --text:      #1a1a2e;
  --subtext:   #495057;
  --radius:    10px;
  --gap:       18px;
}

[data-theme="dark"] {
  /* Dark palette -- modeled on agentarium */
  --bg:        #0d0f14;
  --surface:   #151820;
  --border:    #232738;
  --accent:    #4f8ef7;
  --accent2:   #a78bfa;
  --accent3:   #22d3ee;
  --green:     #34d399;
  --yellow:    #fbbf24;
  --red:       #f87171;
  --muted:     #6b7280;
  --text:      #e2e8f0;
  --subtext:   #94a3b8;
}

@media (prefers-color-scheme: dark) {
  /* No explicit choice (no cookie, no saved account preference) -- follow
     the browser. Higher specificity than the plain `:root` light rule
     above, so it wins whenever it applies; an explicit data-theme="light"
     is excluded so a signed-in user's choice always wins over the OS. */
  :root:not([data-theme="light"]) {
    --bg:        #0d0f14;
    --surface:   #151820;
    --border:    #232738;
    --accent:    #4f8ef7;
    --accent2:   #a78bfa;
    --accent3:   #22d3ee;
    --green:     #34d399;
    --yellow:    #fbbf24;
    --red:       #f87171;
    --muted:     #6b7280;
    --text:      #e2e8f0;
    --subtext:   #94a3b8;
  }
}

/* Navbar chrome intentionally does NOT follow the light/dark toggle -- every
   product's navbar was a dark bar (Bootstrap `navbar-dark bg-dark`, or
   agentarium's already-dark surface) regardless of the page's own theme
   before this shared component existed, and tying it to --surface made
   light-theme navbars turn white, which read as a regression rather than
   an improvement. Fixed to the dark palette's surface/border/text/accent
   values so agentarium (already dark) is visually unchanged and the other
   three products get their original dark bar back. */
:root {
  --nav-bg:     #151820;
  --nav-border: #232738;
  --nav-text:   #e2e8f0;
  --nav-muted:  #6b7280;
  --nav-accent: #4f8ef7;
}

/* ── Bootstrap 5.3 theming bridge ────────────────────────────────
   Bootstrap-based products (personal-assistant, data-utopia-core,
   trading-v2) get full dark-mode component coverage (.card, .table,
   .form-control, .alert, .dropdown-menu, .modal, .btn-primary, ...) for
   free by setting data-bs-theme, rather than hand-overriding every
   Bootstrap component class here. Set data-bs-theme via
   {% include "bff_app_framework/theme_init.html" %} in <head> -- it
   resolves the same explicit choice / prefers-color-scheme fallback
   used for data-theme above (Bootstrap has no native "auto" mode, so
   this needs a resolved value, not just the attribute presence). */
[data-bs-theme="dark"] {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--subtext);
  --bs-border-color: var(--border);
  --bs-secondary-bg: var(--surface);
  --bs-tertiary-bg: var(--surface);
  --bs-primary: var(--accent);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent);
}

[data-bs-theme="light"] {
  --bs-primary: var(--accent);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent);
}

/* Bootstrap-based products render Django messages and inline errors via raw
   .alert-{tag} classes, not the .bff-alert-* component below -- left alone,
   those pull Bootstrap's own compiled $theme-colors palette regardless of
   data-bs-theme, clashing with every other token-driven element on the same
   page (worst in dark mode, where Bootstrap's stock alert-danger is nearly
   black-on-black). Recoloring the bare Bootstrap classes here, using the same
   color-mix formula as .bff-alert-*, means every product gets one consistent
   alert look for free with no template changes. */
.alert-success { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); border-color: var(--green); }
.alert-danger,
.alert-error   { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); border-color: var(--red); }
.alert-info    { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); border-color: var(--accent); }
.alert-warning { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); border-color: var(--yellow); }

/* ── Theme-aware logo swap (opt-in utility, bring your own images) ──
   Pair an <img class="bff-logo-light"> with <img class="bff-logo-dark">
   of the same lockup in a product's own template -- exactly one is shown,
   following the same explicit-choice-then-OS-preference resolution as the
   palette above. The framework ships no logo assets itself. */
.bff-logo-dark { display: none; }
[data-theme="dark"] .bff-logo-light { display: none; }
[data-theme="dark"] .bff-logo-dark { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bff-logo-light { display: none; }
  :root:not([data-theme="light"]) .bff-logo-dark { display: block; }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: background 0.15s ease, color 0.15s ease;
}

a { color: var(--accent); }

/* ── Top Navigation ───────────────────────────────────────────── */
.bff-topnav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.bff-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 28px;
  flex-shrink: 0;
}

.bff-nav-logo-link,
.bff-nav-brand-name-link {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.bff-nav-logo {
  width: 32px; height: 32px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff; letter-spacing: -0.5px;
  flex-shrink: 0;
}

/* Generic initials-badge look -- the default "no logo yet" state. Products
   that override the brand_initials block with an <img> (see
   .bff-nav-logo-img below) instead of text get this background dropped
   automatically, so there's no gradient bleeding through a transparent PNG. */
.bff-nav-logo:not(:has(img)) {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

/* Opt-in: a product supplying its own logo image overrides brand_initials
   with <img class="bff-nav-logo-img" src="{% static '<product-owned-path>' %}">.
   This framework ships no logo assets of its own -- bring your own. */
.bff-nav-logo-img {
  width: 100%; height: 100%;
  object-fit: contain;
}

.bff-nav-brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--nav-text);
  letter-spacing: -0.2px;
}

.bff-nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  flex-wrap: wrap;
}

.bff-nav-link {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--nav-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.bff-nav-link:hover { color: var(--nav-text); background: var(--nav-border); }
.bff-nav-link.active { color: var(--nav-accent); background: rgba(79, 142, 247, 0.1); }

.bff-nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

/* ── Mobile nav toggle (hidden on desktop; shown in the breakpoint below) ── */
.bff-nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.bff-nav-toggle-bar {
  display: block;
  width: 100%;
  height: 2px;
  border-radius: 1px;
  background: var(--nav-text);
  transition: transform 0.15s, opacity 0.15s;
}

.bff-nav-toggle[aria-expanded="true"] .bff-nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.bff-nav-toggle[aria-expanded="true"] .bff-nav-toggle-bar:nth-child(2) { opacity: 0; }
.bff-nav-toggle[aria-expanded="true"] .bff-nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Mobile nav collapse. Desktop rules above are untouched -- everything in
   this breakpoint only takes effect at <=768px, swapping the inline link
   row for a toggleable dropdown panel anchored to the (sticky-positioned,
   so already a valid containing block) .bff-topnav. */
@media (max-width: 768px) {
  .bff-topnav { padding: 0 16px; }
  .bff-nav-brand { margin-right: 12px; }
  .bff-nav-brand-name { font-size: 14px; }

  .bff-nav-toggle { display: flex; }

  .bff-nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex: none;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 8px 12px 12px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 150;
  }

  .bff-nav-links.open { display: flex; }

  .bff-nav-link { width: 100%; padding: 10px 12px; }

  .bff-nav-right { gap: 6px; }

  .bff-user-dropdown,
  .bff-notif-dropdown {
    position: fixed;
    left: 8px;
    right: 8px;
    top: 56px;
    min-width: 0;
    width: auto;
  }
}

/* ── User dropdown ────────────────────────────────────────────── */
.bff-user-menu { position: relative; }

.bff-user-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--nav-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
}

.bff-user-toggle:hover { color: var(--nav-text); background: var(--nav-border); }

.bff-user-caret {
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  display: inline-block;
  padding: 3px;
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.bff-user-menu.open .bff-user-caret { transform: rotate(-135deg); }

.bff-user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--nav-bg);
  border: 1px solid var(--nav-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 6px;
  z-index: 200;
}

.bff-user-menu.open .bff-user-dropdown { display: block; }

.bff-user-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--nav-text);
  text-decoration: none;
  border-radius: 6px;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
}

.bff-user-dropdown-item:hover { background: var(--nav-border); }

/* ── Notification bell ───────────────────────────────────────────
   Structurally mirrors .bff-user-menu (same open/close JS pattern, in
   notifications.js) -- see bff_app_framework/__init__.py's docstring and
   context_processors.notifications for how to opt out of rendering this. */
.bff-notif-menu { position: relative; }

.bff-notif-toggle {
  position: relative;
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--nav-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}

.bff-notif-toggle:hover { color: var(--nav-text); background: var(--nav-border); }

.bff-notif-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.bff-notif-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--nav-bg);
  border: 1px solid var(--nav-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 200;
}

.bff-notif-menu.open .bff-notif-dropdown { display: block; }

.bff-notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--nav-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--nav-text);
}

.bff-notif-dropdown-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bff-notif-mark-all,
.bff-notif-clear-all {
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.bff-notif-mark-all { color: var(--nav-accent); }
.bff-notif-clear-all { color: var(--red); }

.bff-notif-item {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 32px 10px 12px;
  border-bottom: 1px solid var(--nav-border);
  cursor: pointer;
}

.bff-notif-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  text-align: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--nav-muted);
  font-size: 16px;
  cursor: pointer;
}

.bff-notif-delete:hover { background: var(--nav-border); color: var(--nav-text); }

.bff-notif-item:last-child { border-bottom: none; }
.bff-notif-item:hover { background: var(--nav-border); }

.bff-notif-item.unread { background: rgba(79, 142, 247, 0.08); }

.bff-notif-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--nav-text);
}

.bff-notif-item-body {
  font-size: 12px;
  color: var(--nav-muted);
  margin-top: 2px;
}

.bff-notif-item-time {
  font-size: 11px;
  color: var(--nav-muted);
  margin-top: 4px;
}

.bff-notif-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--nav-muted);
}

/* ── Buttons / cards / forms (shared component vocabulary) ──────── */
.bff-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  background: none;
  color: var(--text);
}

.bff-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.bff-btn-primary:hover { filter: brightness(0.9); }
.bff-btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.bff-btn-secondary:hover { background: var(--border); }

.bff-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.bff-alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid;
  margin-bottom: 12px;
}

.bff-alert-success { background: rgba(52, 211, 153, 0.12); color: var(--green); border-color: var(--green); }
.bff-alert-danger,
.bff-alert-error   { background: rgba(248, 113, 113, 0.12); color: var(--red); border-color: var(--red); }
.bff-alert-info    { background: rgba(79, 142, 247, 0.12); color: var(--accent); border-color: var(--accent); }
.bff-alert-warning { background: rgba(251, 191, 36, 0.12); color: var(--yellow); border-color: var(--yellow); }

.bff-input {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.bff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bff-table th {
  text-align: left;
  font-weight: 600;
  color: var(--subtext);
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}
.bff-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }

.bff-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}
.bff-badge-active   { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.bff-badge-inactive { background: var(--border); color: var(--muted); }

/* ── Theme picker (User Settings page) ───────────────────────────── */
.bff-theme-options {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.bff-theme-option {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  width: 160px;
  cursor: pointer;
  background: var(--surface);
}

.bff-theme-option.selected { border-color: var(--accent); }

.bff-theme-option input { margin-right: 8px; }

.bff-theme-swatch {
  height: 48px;
  border-radius: 6px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.bff-theme-swatch.light { background: linear-gradient(135deg, #f7f8fa, #ffffff); }
.bff-theme-swatch.dark  { background: linear-gradient(135deg, #0d0f14, #151820); }
.bff-theme-swatch.system {
  background: linear-gradient(135deg, #f7f8fa 50%, #0d0f14 50%);
}

/* ── MFA (User Settings status pill + setup/backup-codes pages) ─────── */
.bff-mfa-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bff-mfa-status-on  { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.bff-mfa-status-off { background: rgba(108, 117, 125, 0.15); color: var(--muted); }

.bff-mfa-password-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.bff-mfa-qr {
  display: flex;
  justify-content: center;
  margin: 16px 0;
  /* Fixed white, not --surface: the QR module path is drawn in a fixed dark
     color, so on dark theme a --surface background would make it unscannable. */
  background: #ffffff;
  padding: 16px;
  border-radius: var(--radius);
}

.bff-mfa-qr svg { width: 200px; height: 200px; }

.bff-mfa-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  letter-spacing: 0.05em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 4px;
  word-break: break-all;
  user-select: all;
}

.bff-mfa-code-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.3em;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.bff-mfa-backup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.bff-mfa-backup-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px;
}
