/* ═══════════════════════════════════════════════════════════════════════════════
   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); }

/* Action guide — red cue after labels and on the hamburger */
.wcr-menu-label {
  display: inline;
  line-height: 1.2;
}
.wcr-menu-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  min-width: 6px;
  min-height: 6px;
  margin-left: 0.28em;
  vertical-align: super;
  border-radius: 999px;
  background: #dc2626;
  box-shadow: 0 0 0 1.5px var(--w-bg-surface, #fff);
  pointer-events: none;
}
.menu-btn {
  position: relative;
}
.menu-btn .wcr-menu-dot {
  position: absolute;
  top: 0.18rem;
  right: 0.12rem;
  margin: 0;
  vertical-align: top;
  width: 7px;
  height: 7px;
  min-width: 7px;
  min-height: 7px;
}
/* Sidebar rows: keep cue after the last letter (inline) so overflow:hidden cannot clip it */
.sidebar a .wcr-menu-dot,
.sidebar2 a .wcr-menu-dot,
.sidebar3 a .wcr-menu-dot {
  position: static;
  transform: none;
  margin-left: 0.28em;
  vertical-align: super;
  width: 6px;
  height: 6px;
  min-width: 6px;
  min-height: 6px;
}
/* Fund switch + page tabs */
.treas-fund-switch__btn,
.acct-fund-switch__btn,
.budget-fund-switch__btn {
  position: relative;
}
.treas-fund-switch__btn .wcr-menu-dot,
.acct-fund-switch__btn .wcr-menu-dot,
.budget-fund-switch__btn .wcr-menu-dot {
  position: absolute;
  top: 0.12rem;
  right: 0.1rem;
  margin: 0;
  vertical-align: top;
  width: 6px;
  height: 6px;
  min-width: 6px;
  min-height: 6px;
}
.wcr-page-tab .wcr-menu-dot {
  position: static;
  transform: none;
  margin-left: 0.28em;
  vertical-align: super;
}
/* Filter dropdown that leads to waiting work (e.g. OBR Status → Pending) */
.wcr-cue-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}
.wcr-cue-wrap > .wcr-menu-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  margin: 0;
  width: 7px;
  height: 7px;
  min-width: 7px;
  min-height: 7px;
}
html.dark .wcr-menu-dot,
body.dark .wcr-menu-dot,
html[data-theme="midnight"] .wcr-menu-dot,
body[data-theme="midnight"] .wcr-menu-dot {
  box-shadow: 0 0 0 1.5px var(--w-bg-surface, #16171c);
}
/* Month picker: red tag on control + per-month dots (action queues) */
.wcr-month-pick {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}
.wcr-month-pick__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 8.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
html.dark .wcr-month-pick__btn,
html[data-theme="midnight"] .wcr-month-pick__btn {
  border-color: rgba(255, 255, 255, 0.1);
  background: #171717;
}
.wcr-month-pick__btn .wcr-menu-dot {
  position: absolute;
  top: 0.28rem;
  right: 0.28rem;
  margin: 0;
}
.wcr-month-pick__label {
  flex: 1;
  padding-right: 0.5rem;
}
.wcr-month-pick__menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 16rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
}
html.dark .wcr-month-pick__menu,
html[data-theme="midnight"] .wcr-month-pick__menu {
  border-color: rgba(255, 255, 255, 0.1);
  background: #171717;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}
.wcr-month-pick__menu[hidden] {
  display: none !important;
}
.wcr-month-pick__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  font-size: 0.875rem;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.wcr-month-pick__item:hover,
.wcr-month-pick__item.is-active {
  background: #f1f5f9;
}
html.dark .wcr-month-pick__item:hover,
html.dark .wcr-month-pick__item.is-active,
html[data-theme="midnight"] .wcr-month-pick__item:hover,
html[data-theme="midnight"] .wcr-month-pick__item.is-active {
  background: rgba(255, 255, 255, 0.08);
}
.wcr-month-pick__item .wcr-menu-dot {
  position: static;
  margin: 0;
  vertical-align: middle;
  flex-shrink: 0;
}
.wcr-tab-count[hidden],
.wcr-tab-count.is-zero {
  display: none !important;
}
