/* ==========================================================================
   ALGO CMS - MASTER DESIGN SYSTEM & CONTRAST SAFETY MATRIX
   PURE CUSTOM CSS — ZERO EXTERNAL FRAMEWORKS
   ========================================================================== */

/* ── 1. CSS VARIABLES & CONTRAST SAFETY MATRIX ── */

:root, [data-theme="light"] {
  /* ── BACKGROUNDS (Bright Paper: 90 - 100) ── */
  --bg-primary: #f8fafc;         /* Brightness 97: Canvas page background */
  --bg-secondary: #ffffff;       /* Brightness 100: Card/panel surface */
  --bg-tertiary: #f1f5f9;        /* Brightness 94: Subtle contrast background */
  --bg-card: #ffffff;            /* Brightness 100: Elevated card surface */
  --bg-input: #ffffff;           /* Brightness 100: Input field surface */
  --bg-modal-overlay: rgba(15, 23, 42, 0.5);
  --bg-tooltip: #0f172a;
  --bg-code: #f1f5f9;
  --bg-hover: #f1f5f9;
  --bg-active: #e2e8f0;
  --bg-sticky-header: rgba(248, 250, 252, 0.96);
  --bg-sticky-footer: rgba(255, 255, 255, 0.98);

  /* ── FOREGROUNDS / TEXT: STRICT CONTRAST (Pure Black & Deep Charcoal) ── */
  --text-primary: #000000;       /* PURE BLACK: Headings, symbols, main text */
  --text-secondary: #1e293b;     /* DEEP DARK CHARCOAL: Body text, labels */
  --text-tertiary: #475569;      /* CRISP MEDIUM DARK: Secondary hints, timestamps */
  --text-inverse: #ffffff;       /* PURE WHITE: Text on solid buttons */
  --text-link: #2563eb;
  --text-link-hover: #1d4ed8;

  /* ── BORDERS ── */
  --border-primary: #cbd5e1;     /* Crisp visible card & section divider */
  --border-secondary: #e2e8f0;   /* Subtle table divider */
  --border-input: #94a3b8;       /* Crisp input border */
  --border-input-focus: #2563eb;
  --border-card: #cbd5e1;

  /* ── ACCENTS (Saturated with White Text) ── */
  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-primary-light: rgba(37, 99, 235, 0.1);
  --accent-success: #16a34a;
  --accent-success-light: rgba(22, 163, 74, 0.1);
  --accent-danger: #dc2626;
  --accent-danger-light: rgba(220, 38, 38, 0.1);
  --accent-warning: #d97706;
  --accent-warning-light: rgba(217, 119, 6, 0.1);
  --accent-info: #0891b2;
  --accent-info-light: rgba(8, 145, 178, 0.1);

  /* ── SHADOWS ── */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.1);
  --shadow-xl: 0 20px 48px rgba(15, 23, 42, 0.12);

  /* ── CHART COLORS ── */
  --chart-bg: #ffffff;
  --chart-grid: #e2e8f0;
  --chart-text: #1e293b;
  --chart-crosshair: #475569;
  --chart-candle-up: #16a34a;
  --chart-candle-down: #dc2626;
  --chart-volume-up: rgba(22, 163, 74, 0.35);
  --chart-volume-down: rgba(220, 38, 38, 0.35);
  --chart-equity-line: #2563eb;
  --chart-equity-fill: rgba(37, 99, 235, 0.12);

  /* ── PRICE FLASH ── */
  --flash-green-bg: rgba(22, 163, 74, 0.18);
  --flash-red-bg: rgba(220, 38, 38, 0.18);

  /* ── SCROLLBAR ── */
  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #cbd5e1;
  --scrollbar-thumb-hover: #94a3b8;

  /* ── MISC ── */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

[data-theme="dark"] {
  /* ── BACKGROUNDS (Dark Charcoal Surfaces: 0 - 10) ── */
  --bg-primary: #06090e;         /* Brightness 2: Deep dark canvas */
  --bg-secondary: #0c1220;       /* Brightness 5: Card/panel surface */
  --bg-tertiary: #111a2e;        /* Brightness 8: Elevated panel surface */
  --bg-card: #0c1220;            /* Brightness 5: Elevated card surface */
  --bg-input: #111a2e;           /* Brightness 8: Dark input field surface */
  --bg-modal-overlay: rgba(0, 0, 0, 0.75);
  --bg-tooltip: #1e293b;
  --bg-code: #111a2e;
  --bg-hover: #162032;
  --bg-active: #1a2540;
  --bg-sticky-header: rgba(6, 9, 14, 0.95);
  --bg-sticky-footer: rgba(12, 18, 32, 0.98);

  /* ── FOREGROUNDS / TEXT: STRICT CONTRAST (Pure White & Bright Slate) ── */
  --text-primary: #ffffff;       /* PURE WHITE: Headings, symbols, main text */
  --text-secondary: #f1f5f9;     /* BRIGHT NEAR-WHITE: Body text, labels */
  --text-tertiary: #cbd5e1;      /* BRIGHT LIGHT GRAY: Secondary hints, timestamps */
  --text-inverse: #ffffff;       /* PURE WHITE: Text on solid buttons */
  --text-link: #60a5fa;
  --text-link-hover: #93bbfd;

  /* ── BORDERS ── */
  --border-primary: #1e293b;     /* Dark card borders */
  --border-secondary: #162032;   /* Subtle dividers */
  --border-input: #334155;       /* Visible dark input borders */
  --border-input-focus: #3b82f6;
  --border-card: #1e293b;

  /* ── ACCENTS (Saturated with White Text) ── */
  --accent-primary: #3b82f6;
  --accent-primary-hover: #60a5fa;
  --accent-primary-light: rgba(59, 130, 246, 0.15);
  --accent-success: #22c55e;
  --accent-success-light: rgba(34, 197, 94, 0.15);
  --accent-danger: #ef4444;
  --accent-danger-light: rgba(239, 68, 68, 0.15);
  --accent-warning: #f59e0b;
  --accent-warning-light: rgba(245, 158, 11, 0.15);
  --accent-info: #22d3ee;
  --accent-info-light: rgba(34, 211, 238, 0.15);

  /* ── SHADOWS ── */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.5);

  /* ── CHART COLORS ── */
  --chart-bg: #0c1220;
  --chart-grid: #1e293b;
  --chart-text: #cbd5e1;
  --chart-crosshair: #94a3b8;
  --chart-candle-up: #22c55e;
  --chart-candle-down: #ef4444;
  --chart-volume-up: rgba(34, 197, 94, 0.3);
  --chart-volume-down: rgba(239, 68, 68, 0.3);
  --chart-equity-line: #3b82f6;
  --chart-equity-fill: rgba(59, 130, 246, 0.12);

  /* ── PRICE FLASH ── */
  --flash-green-bg: rgba(34, 197, 94, 0.2);
  --flash-red-bg: rgba(239, 68, 68, 0.2);

  /* ── SCROLLBAR ── */
  --scrollbar-track: #0c1220;
  --scrollbar-thumb: #1e293b;
  --scrollbar-thumb-hover: #334155;
}

/* ── 2. GLOBAL RESET & BASE TYPOGRAPHY ── */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 14px; }
body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  transition: background var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Selection */
::selection { background: var(--accent-primary); color: var(--text-inverse); }

/* Links */
a { color: var(--text-link); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--text-link-hover); }

/* Headings */
h1, h2, h3, h4, h5, h6 { color: var(--text-primary); font-weight: 700; line-height: 1.3; }

/* Paragraphs & Text */
p, span, td, th, li, label { color: var(--text-secondary); }

/* ── 3. COMPONENTS ── */

/* Cards & Panels */
.card, .panel, .box, .widget, [class*="card"], [class*="panel"] {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
  transition: background var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal);
}

/* Form Inputs, Selects, Textareas */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="search"], input[type="date"],
input[type="time"], input[type="datetime-local"], select, textarea {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-input) !important;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-normal);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-input-focus) !important;
  box-shadow: 0 0 0 3px var(--accent-primary-light) !important;
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary) !important; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
select option { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }

/* Buttons: GUARANTEED WHITE TEXT ON SATURATED BUTTONS */
.btn, button, [class*="btn"] {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-md); font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; outline: none; text-decoration: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.btn:hover, button:hover { opacity: 0.92; }
.btn:active, button:active { transform: scale(0.98); }

.btn-primary, .btn-blue, a.btn-primary, button.btn-primary { background: var(--accent-primary) !important; color: #ffffff !important; }
.btn-primary *, a.btn-primary *, button.btn-primary * { color: #ffffff !important; }

.btn-success, .btn-green, a.btn-success, button.btn-success { background: var(--accent-success) !important; color: #ffffff !important; }
.btn-success *, a.btn-success *, button.btn-success * { color: #ffffff !important; }

.btn-danger, .btn-red, a.btn-danger, button.btn-danger { background: var(--accent-danger) !important; color: #ffffff !important; }
.btn-danger *, a.btn-danger *, button.btn-danger * { color: #ffffff !important; }

.btn-warning, .btn-orange, a.btn-warning, button.btn-warning { background: var(--accent-warning) !important; color: #ffffff !important; }
.btn-warning *, a.btn-warning *, button.btn-warning * { color: #ffffff !important; }

.btn-ghost, .btn-outline { background: transparent !important; color: var(--text-primary) !important; border: 1px solid var(--border-primary) !important; }
.btn-ghost:hover { background: var(--bg-hover) !important; }
.btn-sm { padding: 6px 12px !important; font-size: 12px !important; }
.btn-lg { padding: 14px 28px !important; font-size: 15px !important; }
button:disabled, .btn:disabled { opacity: 0.5 !important; cursor: not-allowed !important; }

/* Tables */
table, .table, [class*="table"] { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border-primary);
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-secondary);
  color: var(--text-secondary);
  font-size: 13px;
}
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* Badges / Tags */
.badge, .tag, .pill, .status {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: var(--radius-full); font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
}
.badge-success, .tag-success, .status-active, .status-running { background: var(--accent-success-light) !important; color: var(--accent-success) !important; }
.badge-danger, .tag-danger, .status-stopped, .status-failed { background: var(--accent-danger-light) !important; color: var(--accent-danger) !important; }
.badge-warning, .tag-warning, .status-pending { background: var(--accent-warning-light) !important; color: var(--accent-warning) !important; }
.badge-info, .tag-info { background: var(--accent-info-light) !important; color: var(--accent-info) !important; }
.badge-primary { background: var(--accent-primary-light) !important; color: var(--accent-primary) !important; }

/* Alerts */
.alert, .notice, .message, [class*="alert"] {
  padding: 14px 18px; border-radius: var(--radius-md); font-size: 13px;
  border-left: 4px solid;
}
.alert-success { background: var(--accent-success-light); border-color: var(--accent-success); color: var(--accent-success); }
.alert-danger, .alert-error { background: var(--accent-danger-light); border-color: var(--accent-danger); color: var(--accent-danger); }
.alert-warning { background: var(--accent-warning-light); border-color: var(--accent-warning); color: var(--accent-warning); }
.alert-info { background: var(--accent-info-light); border-color: var(--accent-info); color: var(--accent-info); }

/* Dropdown Menus */
.dropdown, .menu, [class*="dropdown"] {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.dropdown-item, .menu-item { color: var(--text-primary) !important; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; }
.dropdown-item:hover { background: var(--bg-hover) !important; color: var(--text-primary) !important; }

/* Tooltips */
.tooltip { background: var(--bg-tooltip); color: #ffffff; font-size: 12px; padding: 6px 10px; border-radius: var(--radius-sm); }

/* Code */
code { background: var(--bg-code); color: var(--accent-primary); padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: monospace; }
pre { background: var(--bg-code); color: var(--text-primary); padding: 16px; border-radius: var(--radius-md); overflow-x: auto; border: 1px solid var(--border-secondary); }

/* Price Flash Animations */
@keyframes flashGreen {
  0% { background: var(--flash-green-bg); }
  100% { background: transparent; }
}
@keyframes flashRed {
  0% { background: var(--flash-red-bg); }
  100% { background: transparent; }
}
.flash-up { animation: flashGreen 0.4s ease-out; }
.flash-down { animation: flashRed 0.4s ease-out; }

/* ── 4. RESPONSIVE CONTAINER & HAMBURGER DRAWER ── */

.app-container {
  width: 96%;
  max-width: 1680px;
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-sticky-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-secondary);
  padding: 10px 16px;
}

.site-footer {
  margin-top: auto;
  background: var(--bg-sticky-footer);
  border-top: 1px solid var(--border-secondary);
  padding: 16px;
  color: var(--text-tertiary);
  font-size: 12px;
}

.mobile-bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 1000;
  background: var(--bg-sticky-footer);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-secondary);
  padding: 6px 12px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
@media (min-width: 768px) {
  .mobile-bottom-nav { display: none !important; }
}

.chart-container {
  background: var(--chart-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* Master Hamburger Drawer */
.hamburger-drawer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  display: none;
}
.hamburger-drawer.open { display: flex; }
.hamburger-content {
  margin-left: auto;
  width: 320px;
  max-width: 85%;
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border-primary);
  box-shadow: var(--shadow-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* ── 5. UTILITY CLASSES ── */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 24px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }
