@tailwind base;
@tailwind components;
@tailwind utilities;

/* ============================================================
   Theme System — CSS Custom Properties for Light / Dark modes
   Forge: Navy + Amber (V2 Final)
   ============================================================ */

:root {
  /* Light mode (default) */
  --bg-primary:    #F3F4F8;
  --bg-secondary:  #EBEDF4;
  --bg-tertiary:   #DDE0EC;
  --bg-card:       #FFFFFF;
  --bg-card-hover: #F8F9FC;
  --bg-sidebar:    #EBEDF4;
  --bg-input:      #EBEDF4;
  --border-primary:   #D0D4E0;
  --border-secondary: #E4E7F0;
  --text-primary:  #0C1222;
  --text-secondary:#4A5578;
  /* tertiary darkened #7A839A→#63697E: 3.79→5.45:1 on card, clears WCAG AA for the
     muted small text (placeholders, timestamps, helper lines). Measured, not eyeballed. */
  --text-tertiary: #63697E;
  --text-heading:  #080E1E;
  --shadow-card: 0 1px 3px rgba(8,13,27,0.06), 0 1px 2px rgba(8,13,27,0.03);
  --shadow-sidebar: 1px 0 0 var(--border-primary);

  /* Amber accent — primary (CTAs, revenue, agent activation) */
  --accent:       #C07820;
  --accent-hover: #D08828;
  --accent-soft:  rgba(192, 120, 32, 0.08);
  --accent-glow:  rgba(192, 120, 32, 0.12);
  --accent-gradient: linear-gradient(135deg, #C07820, #D08828);

  /* Ice blue — secondary (navigation, data, links) */
  --blue:      #3B6DC9;
  --blue-soft: rgba(59, 109, 201, 0.08);

  /* Semantic */
  --emerald: #059669;
  --amber:   #D97706;
  --red:     #DC2626;
  --cyan:    #0891B2;
}

html.dark {
  /* Dark mode — deep navy */
  --bg-primary:    #060B18;
  --bg-secondary:  #0C1324;
  --bg-tertiary:   #141D33;
  --bg-card:       rgba(12, 19, 42, 0.7);
  --bg-card-hover: rgba(16, 24, 50, 0.8);
  --bg-sidebar:    #040810;
  --bg-input:      rgba(100, 140, 220, 0.06);
  --border-primary:   rgba(100, 140, 220, 0.10);
  --border-secondary: rgba(100, 140, 220, 0.05);
  --text-primary:  #D8E0F0;
  --text-secondary:#7A8AAB;
  /* tertiary lightened #4A5A7A→#7484A3: 2.84→5.21:1 on navy, clears WCAG AA (was
     failing even large-text 3:1). Stays below secondary so the hierarchy holds. */
  --text-tertiary: #7484A3;
  --text-heading:  #EDF2FC;
  /* Dark-mode meta tiers for the Tailwind grey remap below. Measured against the
     card background (#0a1125, i.e. --bg-card composited over --bg-primary):
       --meta-strong  10.46:1   was gray-400  7.39
       --meta-subtle   7.30:1   was gray-500  3.88  (failed AA)
     Kept as their own variables rather than reusing --text-secondary/tertiary so
     the remap can be generous without moving the tokens other components read. */
  --meta-strong:   #B6C2DA;
  --meta-subtle:   #93A2C0;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 0 0 1px rgba(100,140,220,0.06);
  --shadow-sidebar: 1px 0 0 rgba(100, 140, 220, 0.08);

  /* Amber accent */
  --accent:       #E8A030;
  --accent-hover: #F0B040;
  --accent-soft:  rgba(232, 160, 48, 0.08);
  --accent-glow:  rgba(232, 160, 48, 0.12);
  --accent-gradient: linear-gradient(135deg, #D49228, #E8A030, #F0B848);

  /* Ice blue */
  --blue:      #5B8DEF;
  --blue-soft: rgba(91, 141, 239, 0.08);

  /* Semantic */
  --emerald: #34D399;
  --amber:   #F59E0B;
  --red:     #EF4444;
  --cyan:    #22D3EE;
}


/* ============================================================
   Component Styles
   ============================================================ */

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-primary);
}
html.dark .card:hover {
  border-color: rgba(100, 140, 220, 0.15);
}

.card-solid {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
}

/* Form inputs */
input, select, textarea {
  background: var(--bg-input);
  border-color: var(--border-primary);
  color: var(--text-primary);
}
input::placeholder, textarea::placeholder {
  color: var(--text-tertiary);
}
select option {
  background: var(--bg-primary);
  color: var(--text-primary);
}
html.dark select option {
  background: #0C1324;
  color: #D8E0F0;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.15s;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  font-weight: 600;
}
.btn-primary:hover {
  filter: brightness(1.1);
}
.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}
.btn-secondary:hover {
  background: var(--bg-tertiary);
  color: var(--text-heading);
}
.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.2);
}
.btn-danger:hover {
  background: rgba(239,68,68,0.2);
}
/* Ghost button — transparent with accent text */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
}
/* Approve button — amber CTA */
.btn-approve {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  font-weight: 600;
}
.btn-approve:hover {
  filter: brightness(1.1);
}

/* Badge pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 9999px;
  line-height: 16px;
}

/* Empty state container */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  text-align: center;
}
.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  opacity: 0.6;
}
.empty-state h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 4px;
}
.empty-state p {
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 320px;
}
.empty-state .empty-action {
  margin-top: 16px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* Table striping */
.table-striped tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}
html.dark .table-striped tbody tr:nth-child(even) {
  background: rgba(100, 140, 220, 0.03);
}

/* Chart fade-in animation */
@keyframes chart-in {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}
.chart-animated {
  animation: chart-in 0.4s ease-out;
}

/* Stat card number animation */
@keyframes count-in {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}
.stat-animated {
  animation: count-in 0.3s ease-out;
}

/* Card entrance animation */
@keyframes card-enter {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.card-enter {
  animation: card-enter 0.3s ease-out both;
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border-primary);
  margin: 16px 0;
}

/* Search dropdown */
.search-results {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
html.dark .search-results {
  background: #0C1324;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* Loading spinner */
.loading-spinner {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 2px solid transparent;
  border-bottom-color: var(--accent);
  border-radius: 9999px;
  animation: spin 0.75s linear infinite;
}
.loading-spinner-sm {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-bottom-color: var(--accent);
  border-radius: 9999px;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Bloomberg-style ticker */
.ticker {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 0;
  font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
  font-size: 11px;
  overflow: hidden;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-secondary);
}
html.dark .ticker {
  background: rgba(6, 11, 24, 0.85);
}
.ticker-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 100%;
  border-right: 1px solid var(--border-secondary);
  white-space: nowrap;
}
.ticker-label {
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.ticker-value {
  color: var(--text-heading);
  font-weight: 700;
  font-size: 12px;
}
.ticker-change {
  font-size: 10px;
  font-weight: 600;
}
.ticker-up {
  color: var(--emerald);
}
.ticker-down {
  color: var(--red);
}
.ticker-flat {
  color: var(--text-tertiary);
}
.ticker-alert {
  color: var(--amber);
  animation: ticker-pulse 2s ease-in-out infinite;
}
@keyframes ticker-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.ticker-sep {
  width: 1px;
  height: 14px;
  background: var(--border-primary);
  flex-shrink: 0;
}

/* Row hover glow */
/* Hover-bg: pure CSS replacement for inline onmouseover/out */
.hover-bg { transition: background 0.15s; }
.hover-bg:hover { background: var(--bg-tertiary); }

.row-hover-glow {
  transition: box-shadow 0.15s, background 0.15s;
}
html.dark .row-hover-glow:hover {
  box-shadow: inset 4px 0 0 var(--accent);
  background: rgba(232, 160, 48, 0.03);
}

/* Content container — max width + responsive padding for wide screens */
.content-container {
  max-width: 1800px;
  margin-left: auto;
  margin-right: auto;
  /* Stop wide children (e.g. the 6-col leaderboard table on mobile) from scrolling
     the whole page sideways. `clip` (not `hidden`) leaves vertical dropdowns/menus
     visible and lets inner `overflow-x-auto` containers scroll on their own. */
  overflow-x: clip;
}
@media (min-width: 1280px) {
  .content-container { padding-left: 2rem; padding-right: 2rem; }
}
@media (min-width: 1536px) {
  .content-container { padding-left: 2.5rem; padding-right: 2.5rem; }
}
@media (min-width: 1920px) {
  .content-container { padding-left: 3rem; padding-right: 3rem; }
}


/* ============================================================
   Light-mode compatibility layer
   Remaps existing dark-theme Tailwind classes so dashboard
   templates work in light mode without modification.
   ============================================================ */

/* Text colors */
:root:not(.dark) .text-white {
  color: var(--text-heading);
}
:root:not(.dark) .text-gray-200 {
  color: var(--text-primary);
}
:root:not(.dark) .text-gray-300 {
  color: var(--text-primary);
}
:root:not(.dark) .text-gray-400 {
  color: var(--text-secondary);
}
:root:not(.dark) .text-gray-500 {
  color: var(--text-tertiary);
}
:root:not(.dark) .text-gray-600 {
  color: var(--text-tertiary);
}
/* Light-mode readability: these light text classes were not remapped, so in
   light mode they rendered near-white on a light card (Terri: the pipeline-stats
   writing on the overview page). slate-400 alone is used 120+ times. */
:root:not(.dark) .text-gray-100 {
  color: var(--text-primary);
}
:root:not(.dark) .text-slate-200 {
  color: var(--text-primary);
}
:root:not(.dark) .text-slate-300 {
  color: var(--text-secondary);
}
:root:not(.dark) .text-slate-400 {
  color: var(--text-secondary);
}
/* Amber utilities aren't remapped by default, so text-amber-300/400 render as pale
   yellow-on-white and fail contrast in light mode (Xavier 07-19: "awaiting enrichment"
   hard to read). Pin them to the darker semantic amber. Fixes every amber label at once. */
:root:not(.dark) .text-amber-200,
:root:not(.dark) .text-amber-300,
:root:not(.dark) .text-amber-400 {
  color: var(--amber);
}

/* ============================================================
   DARK-mode readability layer
   The light layer above has existed for a while; there was never a dark
   equivalent, so in dark mode — which is what the dashboards actually run in —
   every template fell through to the raw Tailwind palette. Measured against the
   card background (#0a1125):

     .text-gray-500   3.88:1   FAILS WCAG AA        179 uses on the 3 main screens
     .text-gray-600   2.48:1   fails badly           15 uses
     .text-gray-400   7.39:1   passes, but thin at 10-11px

   Client feedback 21 Jul, six separate times: the grey text is too hard to read.
   The cause was not the templates, it was this missing block.

   Remapped by COLOUR CLASS ALONE, deliberately: ~40% of colour usages carry no
   size class in the same attribute (they inherit size from a parent), so any
   size-scoped selector such as `.text-xs.text-gray-500` would silently miss them.

   Hierarchy is preserved — 14.15 > 10.46 > 7.30 — so the visual ranking of
   heading / meta / subtle still reads, it is simply all legible now.
   ============================================================ */

html.dark .text-gray-200,
html.dark .text-gray-300,
html.dark .text-slate-200,
html.dark .text-slate-300 {
  color: var(--text-primary);
}
html.dark .text-gray-400,
html.dark .text-slate-400 {
  color: var(--meta-strong);
}
html.dark .text-gray-500,
html.dark .text-gray-600,
html.dark .text-slate-500 {
  color: var(--meta-subtle);
}

/* Background colors */
:root:not(.dark) .bg-white\/5 {
  background: var(--bg-input);
}
:root:not(.dark) .bg-white\/\[0\.02\] {
  background: var(--bg-secondary);
}
:root:not(.dark) .bg-white\/\[0\.03\] {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/\[0\.04\] {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/\[0\.06\] {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/\[0\.07\] {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/\[0\.08\] {
  background: var(--bg-input);
}
:root:not(.dark) .bg-white\/3 {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/8 {
  background: var(--bg-tertiary);
}
:root:not(.dark) .bg-white\/10 {
  background: #D0D4E0;
}

/* Border colors */
:root:not(.dark) .border-white\/5 {
  border-color: var(--border-secondary);
}
:root:not(.dark) .border-white\/10 {
  border-color: var(--border-primary);
}
:root:not(.dark) .border-white\/20 {
  border-color: var(--border-primary);
}
:root:not(.dark) .border-white\/\[0\.03\] {
  border-color: var(--border-secondary);
}
:root:not(.dark) .border-white\/\[0\.06\] {
  border-color: var(--border-primary);
}
:root:not(.dark) .border-white\/\[0\.08\] {
  border-color: var(--border-primary);
}

/* App background */
:root:not(.dark) .app-bg {
  background: var(--bg-secondary);
}

/* Glass morphism -> clean solid in light mode */
:root:not(.dark) .glass {
  background: var(--bg-card);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-color: var(--border-primary);
}
:root:not(.dark) .glass-strong {
  background: var(--bg-card);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-color: var(--border-primary);
  box-shadow: var(--shadow-card);
}

/* Dot grid — disabled in light mode */
:root:not(.dark) .dot-grid {
  background-image: none;
}

/* Table row hovers */
:root:not(.dark) .hover\:bg-white\/5:hover {
  background: var(--bg-tertiary);
}
:root:not(.dark) .hover\:bg-white\/\[0\.02\]:hover {
  background: var(--bg-tertiary);
}
:root:not(.dark) .hover\:bg-white\/\[0\.04\]:hover {
  background: var(--bg-tertiary);
}
:root:not(.dark) .hover\:bg-white\/\[0\.06\]:hover {
  background: var(--bg-tertiary);
}
:root:not(.dark) .hover\:bg-white\/\[0\.08\]:hover {
  background: var(--bg-input);
}
:root:not(.dark) .hover\:bg-white\/3:hover {
  background: var(--bg-tertiary);
}

/* Glow effects — removed in light mode */
:root:not(.dark) .glow-purple,
:root:not(.dark) .glow-blue {
  box-shadow: none;
}

/* Shadow overrides */
:root:not(.dark) .shadow-purple-500\/20,
:root:not(.dark) .shadow-purple-500\/25,
:root:not(.dark) .shadow-black\/40,
:root:not(.dark) .shadow-black\/20 {
  --tw-shadow-color: rgba(8,13,27,0.06);
}
