/* ==========================================================================
   WDFX Design System Tokens & Base Primitives
   Brand Palette: Deep Emerald (#104C3E), Dark Forest (#0D352B),
   Soft Mint (#A8D9C5), Champagne Gold (#C6A66B) accent.
   Self-hosted Plus Jakarta Sans (400-800) + WCAG AA verified pairings
   (>= 4.5:1 normal text, >= 3.0:1 UI boundaries & focus rings).
   ========================================================================== */

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/PlusJakartaSans-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/PlusJakartaSans-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/PlusJakartaSans-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/PlusJakartaSans-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/PlusJakartaSans-ExtraBold.ttf') format('truetype');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Official WDFX Brand Primitives */
  --wfx-emerald: #104C3E;
  --wfx-forest: #0D352B;
  --wfx-mint: #A8D9C5;
  --wfx-gold: #C6A66B;

  /* Surfaces (Warm Stone Alabaster + Crisp Ivory) */
  --wfx-canvas: #F1F0EB;
  --wfx-surface: #FFFFFF;
  --wfx-sunken: #F5F4F0;
  --wfx-hover-surface: #EAEAE3;

  /* Translucent Liquid Glass Accent Surfaces (capped to focal elements) */
  --wfx-glass-bg: rgba(255, 255, 255, 0.80);
  --wfx-glass-surface: rgba(255, 255, 255, 0.88);
  --wfx-glass-border: rgba(16, 76, 62, 0.14);
  --wfx-glass-highlight: rgba(255, 255, 255, 0.85);
  --wfx-glass-blur: 18px;
  --wfx-glass-shadow:
    0 24px 54px -20px rgba(13, 53, 43, 0.18),
    0 8px 20px -10px rgba(13, 53, 43, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.88);

  /* Borders */
  --wfx-border: #DFDFD7;
  --wfx-border-strong: #C5C7BF;
  --wfx-border-control: #8A918D;

  /* Ink (WCAG AA/AAA verified on canvas & surface) */
  --wfx-ink: #121816;
  --wfx-ink-secondary: #3E4845;
  --wfx-ink-muted: #55605C;

  /* Brand & Deliberate Single Accent */
  --wfx-brand: #104C3E;
  --wfx-brand-hover: #0D352B;
  --wfx-brand-ink: #104C3E;
  --wfx-brand-on: #FFFFFF;
  --wfx-brand-tint: #E5F1EC;

  --wfx-accent: #7D5D1E;
  --wfx-accent-raw: #C6A66B;
  --wfx-accent-tint: #F7F1E3;
  --wfx-accent-border: #D9C498;

  /* Semantic Financial States */
  --wfx-profit: #0E6B45;
  --wfx-profit-tint: #E6F4EE;
  --wfx-profit-border: #A8D8C2;

  --wfx-loss: #B42318;
  --wfx-loss-hover: #911B12;
  --wfx-loss-on: #FFFFFF;
  --wfx-loss-tint: #FCECEB;
  --wfx-loss-border: #F2B8B5;

  --wfx-warn: #8A4309;
  --wfx-warn-tint: #FEF4DF;
  --wfx-warn-border: #E8C784;

  /* Focus & Elevation */
  --wfx-focus: #104C3E;
  --wfx-shadow-card: 0 1px 2px rgba(13, 53, 43, 0.04), 0 10px 26px -14px rgba(13, 53, 43, 0.10);
  --wfx-shadow-card-hover: 0 4px 12px rgba(13, 53, 43, 0.06), 0 16px 34px -16px rgba(13, 53, 43, 0.14);
  --wfx-shadow-overlay: 0 24px 56px -12px rgba(13, 53, 43, 0.22), 0 4px 14px rgba(13, 53, 43, 0.08);
  --wfx-backdrop: rgba(10, 22, 18, 0.52);

  /* Typography */
  --wfx-font-sans: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --wfx-font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  /* Concentric Radii Scale (varied by role, never all pills) */
  --wfx-radius-xs: 6px;
  --wfx-radius-sm: 10px;
  --wfx-radius-md: 14px;
  --wfx-radius-lg: 20px;
  --wfx-radius-xl: 24px;

  /* Spacing, Layout & Motion */
  --wfx-topbar-h: 64px;
  --wfx-sidebar-w: 256px;
  --wfx-ease-silk: cubic-bezier(0.22, 1, 0.36, 1);
  --wfx-ease-snap: cubic-bezier(0.2, 0, 0, 1);
  --wfx-transition: 160ms cubic-bezier(0.2, 0, 0, 1);
}

:root[data-theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"] {
  color-scheme: dark;

  --wfx-canvas: #0A100E;
  --wfx-surface: #111917;
  --wfx-sunken: #16211E;
  --wfx-hover-surface: #1D2B27;

  --wfx-glass-bg: rgba(17, 26, 23, 0.78);
  --wfx-glass-surface: rgba(20, 31, 28, 0.86);
  --wfx-glass-border: rgba(168, 217, 197, 0.14);
  --wfx-glass-highlight: rgba(168, 217, 197, 0.12);
  --wfx-glass-shadow:
    0 28px 60px -18px rgba(0, 0, 0, 0.65),
    0 8px 22px -8px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(168, 217, 197, 0.14);

  --wfx-border: #23322D;
  --wfx-border-strong: #31453F;
  --wfx-border-control: #5B736B;

  --wfx-ink: #F1F5F3;
  --wfx-ink-secondary: #B8C7C1;
  --wfx-ink-muted: #8FA39B;

  --wfx-brand: #4EC49E;
  --wfx-brand-hover: #67D3B0;
  --wfx-brand-ink: #A8D9C5;
  --wfx-brand-on: #071A14;
  --wfx-brand-tint: #132C25;

  --wfx-accent: #D7BA7F;
  --wfx-accent-raw: #C6A66B;
  --wfx-accent-tint: #292214;
  --wfx-accent-border: #5E4C28;

  --wfx-profit: #55D69D;
  --wfx-profit-tint: #102B20;
  --wfx-profit-border: #21573F;

  --wfx-loss: #F78279;
  --wfx-loss-hover: #D9382C;
  --wfx-loss-on: #FFFFFF;
  --wfx-loss-tint: #301718;
  --wfx-loss-border: #692B2B;

  --wfx-warn: #F2C363;
  --wfx-warn-tint: #2D2312;
  --wfx-warn-border: #634C1F;

  --wfx-focus: #A8D9C5;
  --wfx-shadow-card: 0 2px 6px rgba(0, 0, 0, 0.32), 0 12px 28px -12px rgba(0, 0, 0, 0.55);
  --wfx-shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.42), 0 18px 36px -14px rgba(0, 0, 0, 0.65);
  --wfx-shadow-overlay: 0 24px 56px rgba(0, 0, 0, 0.65), 0 4px 14px rgba(0, 0, 0, 0.45);
  --wfx-backdrop: rgba(4, 10, 8, 0.76);
}

/* Base Accessibility & Interaction Affordances (R-32, R-39) */
a[href],
button,
summary,
select,
label[for],
input[type="checkbox"],
input[type="radio"],
[role="button"],
[role="tab"],
[role="switch"] {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--wfx-focus);
  outline-offset: 2px;
}

.num,
.mono {
  font-family: var(--wfx-font-mono);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Custom WDFX Toast Stack (Replaces native alerts & raw JSON errors)
   ========================================================================== */
.wfx-toast-region {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(410px, calc(100vw - 32px));
  pointer-events: none;
}

.wfx-toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--wfx-glass-surface);
  color: var(--wfx-ink);
  border: 1px solid var(--wfx-border-strong);
  border-left: 3.5px solid var(--wfx-brand);
  border-radius: var(--wfx-radius-md);
  box-shadow: var(--wfx-shadow-overlay);
  font-family: var(--wfx-font-sans);
  font-size: 13.5px;
  line-height: 1.48;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 220ms var(--wfx-ease-silk), transform 220ms var(--wfx-ease-silk);
}

.wfx-toast.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.wfx-toast[data-tone="success"] { border-left-color: var(--wfx-profit); }
.wfx-toast[data-tone="error"] { border-left-color: var(--wfx-loss); }
.wfx-toast[data-tone="warning"] { border-left-color: var(--wfx-warn); }

.wfx-toast-icon {
  width: 19px;
  height: 19px;
  margin-top: 1px;
  flex-shrink: 0;
  color: var(--wfx-brand-ink);
}

.wfx-toast[data-tone="success"] .wfx-toast-icon { color: var(--wfx-profit); }
.wfx-toast[data-tone="error"] .wfx-toast-icon { color: var(--wfx-loss); }
.wfx-toast[data-tone="warning"] .wfx-toast-icon { color: var(--wfx-warn); }

.wfx-toast-body { min-width: 0; }

.wfx-toast-title {
  display: block;
  font-weight: 700;
  font-size: 13px;
  color: var(--wfx-ink);
  margin-bottom: 2px;
}

.wfx-toast-msg {
  margin: 0;
  color: var(--wfx-ink-secondary);
  word-break: break-word;
}

.wfx-toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  margin: -3px -4px -3px 0;
  border: 1px solid transparent;
  border-radius: var(--wfx-radius-xs);
  background: transparent;
  color: var(--wfx-ink-muted);
  font-size: 17px;
  line-height: 1;
  transition: background var(--wfx-transition), color var(--wfx-transition);
}

.wfx-toast-close:hover {
  background: var(--wfx-sunken);
  color: var(--wfx-ink);
}

/* ==========================================================================
   Custom WDFX Modal Dialogs (Replaces browser confirm() / prompt())
   ========================================================================== */
dialog.wfx-dialog {
  width: min(480px, calc(100vw - 24px));
  max-width: 100%;
  padding: 0;
  border: 1px solid var(--wfx-border-strong);
  border-radius: var(--wfx-radius-lg);
  background: var(--wfx-surface);
  color: var(--wfx-ink);
  box-shadow: var(--wfx-shadow-overlay);
  font-family: var(--wfx-font-sans);
  overflow: hidden;
}

dialog.wfx-dialog[open] {
  animation: wfxDialogPop 220ms var(--wfx-ease-silk);
}

@keyframes wfxDialogPop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

dialog.wfx-dialog::backdrop {
  background: var(--wfx-backdrop);
  backdrop-filter: blur(4px);
}

.wfx-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--wfx-border);
}

.wfx-dialog-title-wrap {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.wfx-dialog-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--wfx-radius-sm);
  background: var(--wfx-brand-tint);
  color: var(--wfx-brand-ink);
  flex-shrink: 0;
}

.wfx-dialog[data-tone="danger"] .wfx-dialog-badge {
  background: var(--wfx-loss-tint);
  color: var(--wfx-loss);
}

.wfx-dialog[data-tone="warning"] .wfx-dialog-badge {
  background: var(--wfx-warn-tint);
  color: var(--wfx-warn);
}

.wfx-dialog-title {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--wfx-ink);
}

.wfx-dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--wfx-border);
  border-radius: var(--wfx-radius-sm);
  background: var(--wfx-sunken);
  color: var(--wfx-ink-secondary);
  font-size: 18px;
  line-height: 1;
  transition: background var(--wfx-transition), color var(--wfx-transition), border-color var(--wfx-transition);
}

.wfx-dialog-close:hover {
  background: var(--wfx-hover-surface);
  border-color: var(--wfx-border-strong);
  color: var(--wfx-ink);
}

.wfx-dialog-body {
  padding: 20px 22px;
  font-size: 14px;
  line-height: 1.58;
  color: var(--wfx-ink-secondary);
}

.wfx-dialog-body p {
  margin: 0 0 12px;
  white-space: pre-line;
}

.wfx-dialog-body p:last-child { margin-bottom: 0; }

.wfx-dialog-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.wfx-dialog-field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--wfx-ink);
}

.wfx-dialog-field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1.5px solid var(--wfx-border-control);
  border-radius: var(--wfx-radius-sm);
  background: var(--wfx-surface);
  color: var(--wfx-ink);
  font-family: var(--wfx-font-sans);
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color var(--wfx-transition), box-shadow var(--wfx-transition);
}

.wfx-dialog-field input:focus {
  outline: none;
  border-color: var(--wfx-brand);
  box-shadow: 0 0 0 3px var(--wfx-brand-tint);
}

.wfx-dialog-err {
  margin-top: 12px;
  padding: 10px 13px;
  border-radius: var(--wfx-radius-sm);
  border: 1px solid var(--wfx-loss-border);
  background: var(--wfx-loss-tint);
  color: var(--wfx-loss);
  font-size: 13px;
  font-weight: 600;
}

.wfx-dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--wfx-border);
  background: var(--wfx-sunken);
}

/* ==========================================================================
   Shared Tactile Button System
   ========================================================================== */
.wfx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: var(--wfx-radius-sm);
  border: 1px solid var(--wfx-border-strong);
  background: var(--wfx-surface);
  color: var(--wfx-ink);
  font-family: var(--wfx-font-sans);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(13, 53, 43, 0.04);
  transition:
    background var(--wfx-transition),
    border-color var(--wfx-transition),
    color var(--wfx-transition),
    box-shadow var(--wfx-transition),
    transform 110ms var(--wfx-ease-snap);
}

.wfx-btn:hover:not(:disabled) {
  background: var(--wfx-hover-surface);
  border-color: var(--wfx-ink-muted);
  box-shadow: 0 3px 10px -4px rgba(13, 53, 43, 0.14);
  transform: translateY(-1px);
}

.wfx-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
  box-shadow: none;
}

.wfx-btn:disabled {
  opacity: 0.5;
  box-shadow: none;
  transform: none;
}

.wfx-btn-primary {
  background: linear-gradient(135deg, #104C3E 0%, #0D352B 100%);
  border-color: #104C3E;
  color: #FFFFFF;
  box-shadow: 0 4px 14px -4px rgba(16, 76, 62, 0.42);
}

.wfx-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #145E4D 0%, #0D352B 100%);
  border-color: #0D352B;
  color: #FFFFFF;
  box-shadow: 0 8px 20px -6px rgba(16, 76, 62, 0.52);
}

[data-theme="dark"] .wfx-btn-primary {
  background: linear-gradient(135deg, #52C9A2 0%, #38AE89 100%);
  border-color: #52C9A2;
  color: #071A14;
  box-shadow: 0 4px 16px -4px rgba(78, 196, 158, 0.32);
}

[data-theme="dark"] .wfx-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #69D8B4 0%, #45BC97 100%);
  border-color: #69D8B4;
  color: #071A14;
}

.wfx-btn-danger {
  background: var(--wfx-loss);
  border-color: var(--wfx-loss);
  color: var(--wfx-loss-on);
  box-shadow: 0 3px 12px -4px rgba(180, 35, 24, 0.35);
}

.wfx-btn-danger:hover:not(:disabled) {
  background: var(--wfx-loss-hover);
  border-color: var(--wfx-loss-hover);
  color: #FFFFFF;
  box-shadow: 0 6px 16px -6px rgba(180, 35, 24, 0.45);
}

.wfx-btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--wfx-ink-secondary);
}

.wfx-btn-ghost:hover:not(:disabled) {
  background: var(--wfx-hover-surface);
  border-color: var(--wfx-border);
  color: var(--wfx-ink);
  box-shadow: none;
}

@media (max-width: 679px) {
  .wfx-toast-region {
    top: auto;
    bottom: 14px;
    right: 12px;
    left: 12px;
    width: auto;
  }

  .wfx-btn {
    min-height: 44px;
  }

  .wfx-dialog-foot {
    flex-direction: column-reverse;
  }

  .wfx-dialog-foot .wfx-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
