/* ═══════════════════════════════════════════════════════════════════════════════
   WILLOW DESIGN SYSTEM
   Unified theme tokens for Budget / Accounting / Treasury modules.

   LOADING ORDER:
     1. tailwind.css (base)
     2. willow-ui.css  ← THIS FILE (design tokens + light overrides)
     3. module-specific CSS (navbar.css, theme files, inline <style>)

   PHILOSOPHY:
     - Define CSS custom properties as the source of truth.
     - Only override elements that directly fight dark mode or theme.
     - Avoid bulk !important — use high specificity instead.
     - Respect existing inline styles; don't fight them blindly.
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────────────────────
   1. DESIGN TOKENS
   ─────────────────────────────────────────────────────────────────────────────── */
:root {
  /* Fund colors (overridden per-fund via navbar <style> block) */
  --w-fund-primary:        #3b82f6;
  --w-fund-primary-light:  #93c5fd;
  --w-fund-primary-dark:   #1d4ed8;
  --w-fund-bg-gradient:    #e0e7ff;
  --w-fund-row-stripe:     rgba(59,130,246,0.07);
  --w-fund-header-bg:      rgba(59,130,246,0.08);
  --w-fund-sidebar-hover:  rgba(59,130,246,0.08);
  --w-fund-sidebar-active: rgba(59,130,246,0.14);
  /* Text on filled primary buttons (paired with primary→primary-dark fills) */
  --w-text-on-primary:     #ffffff;

  /* Surfaces (light mode) */
  --w-bg-page:        #f6f8fb;
  --w-bg-surface:     #ffffff;
  --w-bg-subtle:      #f1f4f9;
  --w-bg-muted:       #e8ecf1;

  /* Text */
  --w-text-primary:   #0f172a;
  --w-text-secondary: #475569;
  --w-text-tertiary:  #64748b;
  --w-text-muted:     #94a3b8;

  /* Borders */
  --w-border-default: #e2e8f0;
  --w-border-subtle:  #f1f5f9;
  --w-border-strong:  #cbd5e1;

  /* Shadows */
  --w-shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --w-shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --w-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -2px rgba(0,0,0,0.04);
  --w-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.06), 0 4px 6px -4px rgba(0,0,0,0.04);

  /* Radius */
  --w-radius-sm: 6px;
  --w-radius-md: 10px;
  --w-radius-lg: 14px;
  --w-radius-xl: 20px;

  /* Typography */
  --w-font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --w-font-mono: "Cascadia Code", "Fira Code", "SF Mono", Consolas, monospace;

  /* Status colors */
  --w-success-bg:     #f0fdf4;
  --w-success-text:   #15803d;
  --w-success-border: #bbf7d0;
  --w-warning-bg:     #fffbeb;
  --w-warning-text:   #b45309;
  --w-warning-border: #fde68a;
  --w-error-bg:       #fef2f2;
  --w-error-text:     #b91c1c;
  --w-error-border:   #fecaca;
  --w-info-bg:        #eff6ff;
  --w-info-text:      #1d4ed8;
  --w-info-border:    #bfdbfe;
}

/* Native checkboxes inherit fund chrome (navbar sets --w-fund-primary) */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--w-fund-primary);
}

/* Dark mode token overrides */
.dark,
body.dark {
  --w-bg-page:        #0c0d10;
  --w-bg-surface:     #16171c;
  --w-bg-subtle:      #1c1d23;
  --w-bg-muted:       #24252c;

  --w-text-primary:   #fafafa;
  --w-text-secondary: #a1a1aa;
  --w-text-tertiary:  #71717a;
  --w-text-muted:     #52525b;

  --w-border-default: #27272a;
  --w-border-subtle:  #1f1f23;
  --w-border-strong:  #3f3f46;

  --w-shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
  --w-shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --w-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
  --w-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);

  --w-success-bg:     rgba(34,197,94,0.10);
  --w-success-text:   #4ade80;
  --w-success-border: rgba(34,197,94,0.20);
  --w-warning-bg:     rgba(245,158,11,0.10);
  --w-warning-text:   #fbbf24;
  --w-warning-border: rgba(245,158,11,0.20);
  --w-error-bg:       rgba(239,68,68,0.10);
  --w-error-text:     #f87171;
  --w-error-border:   rgba(239,68,68,0.20);
  --w-info-bg:        rgba(59,130,246,0.10);
  --w-info-text:      #60a5fa;
  --w-info-border:    rgba(59,130,246,0.20);
}

/* ───────────────────────────────────────────────────────────────────────────────
   2. OPTIONAL UTILITY HOOKS
   Classes that pages can OPT INTO for the modern look.
   Existing pages work unchanged — these are additive.
   ─────────────────────────────────────────────────────────────────────────────── */

.w-card {
  background: var(--w-bg-surface);
  border: 1px solid var(--w-border-default);
  border-radius: var(--w-radius-lg);
  box-shadow: var(--w-shadow-sm);
  padding: 1.25rem;
}
.w-card-soft {
  background: linear-gradient(170deg, var(--w-bg-surface) 0%, var(--w-bg-subtle) 100%);
  border: 1px solid var(--w-border-default);
  border-radius: var(--w-radius-lg);
  box-shadow: var(--w-shadow-xs);
  padding: 1.25rem;
}

.w-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--w-radius-md);
  border: 1px solid var(--w-border-default);
  background: var(--w-bg-surface);
  color: var(--w-text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
}
.w-btn:hover {
  background: var(--w-bg-subtle);
  color: var(--w-text-primary);
  border-color: var(--w-border-strong);
}
.w-btn-primary {
  background: linear-gradient(135deg, var(--w-fund-primary), var(--w-fund-primary-dark));
  color: var(--w-text-on-primary, #ffffff);
  border-color: var(--w-fund-primary-dark);
}
.w-btn-primary:hover {
  background: linear-gradient(135deg, var(--w-fund-primary-dark), var(--w-fund-primary));
  color: var(--w-text-on-primary, #ffffff);
}

/* Crisp data-surface recipe (User List look) — opt-in wrappers */
.w-data-surface {
  background: linear-gradient(170deg, var(--w-bg-surface), var(--w-bg-subtle));
  border: 1px solid var(--w-border-default);
  border-radius: var(--w-radius-lg);
  box-shadow: var(--w-shadow-md);
  padding: 1rem 1.25rem;
}
.w-data-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 8px;
  /* visible so sticky thead works; clip via parent .w-data-surface / wrapper if needed */
  overflow: visible;
  box-shadow: var(--w-shadow-md);
  background: var(--w-bg-surface);
}
.w-data-table thead th {
  background-color: var(--w-bg-surface);
  background-image: linear-gradient(135deg, var(--w-fund-header-bg), var(--w-bg-subtle));
  color: var(--w-text-primary);
  padding: 12px;
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid var(--w-border-default);
}
.w-data-table tbody td {
  padding: 10px;
  border-top: 1px solid var(--w-border-default);
  color: var(--w-text-primary);
}
.w-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(170deg, var(--w-bg-surface), var(--w-bg-subtle));
  border: 1px solid var(--w-border-default);
  border-radius: var(--w-radius-md);
  box-shadow: var(--w-shadow-sm);
}

/* ───────────────────────────────────────────────────────────────────────────────
   3. STATUS BADGES (used by Appearance card + notifications)
   ─────────────────────────────────────────────────────────────────────────────── */
.w-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
}
.w-badge-success { background: var(--w-success-bg); color: var(--w-success-text); border-color: var(--w-success-border); }
.w-badge-warning { background: var(--w-warning-bg); color: var(--w-warning-text); border-color: var(--w-warning-border); }
.w-badge-error   { background: var(--w-error-bg);   color: var(--w-error-text);   border-color: var(--w-error-border); }
.w-badge-info    { background: var(--w-info-bg);    color: var(--w-info-text);    border-color: var(--w-info-border); }

/* ───────────────────────────────────────────────────────────────────────────────
   4. APPEARANCE SETTINGS CARD (theme picker UI)
   ─────────────────────────────────────────────────────────────────────────────── */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.theme-card {
  position: relative;
  cursor: pointer;
  padding: 16px;
  border-radius: var(--w-radius-lg);
  border: 2px solid var(--w-border-default);
  background: var(--w-bg-surface);
  transition: all 200ms ease;
}
.theme-card:hover {
  border-color: var(--w-fund-primary);
  transform: translateY(-2px);
  box-shadow: var(--w-shadow-md);
}
.theme-card.active {
  border-color: var(--w-fund-primary);
  box-shadow: 0 0 0 3px var(--w-fund-sidebar-hover);
}
.theme-card-swatches {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.theme-card-swatches > div {
  width: 28px;
  height: 28px;
  border-radius: var(--w-radius-sm);
  border: 1px solid var(--w-border-default);
}
.theme-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--w-text-primary);
  margin-bottom: 4px;
}
.theme-card-desc {
  font-size: 12px;
  color: var(--w-text-tertiary);
  line-height: 1.4;
  margin: 0;
}
.theme-card-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--w-fund-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
}

/* Inline message in Appearance panel */
.theme-msg {
  display: none;
  padding: 8px 14px;
  border-radius: var(--w-radius-md);
  margin-bottom: 14px;
  font-size: 13px;
  border: 1px solid transparent;
}
.theme-msg.success { background: var(--w-success-bg); color: var(--w-success-text); border-color: var(--w-success-border); }
.theme-msg.error   { background: var(--w-error-bg);   color: var(--w-error-text);   border-color: var(--w-error-border); }
.theme-msg.info    { background: var(--w-info-bg);    color: var(--w-info-text);    border-color: var(--w-info-border); }
