/* ============================================================
   Django Wallet — main.css
   Design system : Bootstrap 5 + tokens dark/light
   WI-20260403-MASTER-001
   ============================================================ */

/* ─── 1. DESIGN TOKENS ─────────────────────────────────────── */

[data-theme='dark'] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --positive: #3fb950;
  --negative: #f85149;
  --warning: #d29922;
  --info: #388bfd;
  --badge-high-bg: #1a3a28;
  --badge-high-fg: #3fb950;
  --badge-mid-bg: #3a2a00;
  --badge-mid-fg: #d29922;
  --badge-low-bg: #3a1010;
  --badge-low-fg: #f85149;
  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #636c76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --positive: #1a7f37;
  --negative: #cf222e;
  --warning: #9a6700;
  --info: #0550ae;
  --badge-high-bg: #dafbe1;
  --badge-high-fg: #1a7f37;
  --badge-mid-bg: #fff3cd;
  --badge-mid-fg: #9a6700;
  --badge-low-bg: #ffebe9;
  --badge-low-fg: #cf222e;
  color-scheme: light;
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

/* Bootstrap text/bg overrides */
.text-body {
  color: var(--text) !important;
}
.text-muted {
  color: var(--text-muted) !important;
}
.bg-body,
.bg-white {
  background-color: var(--surface) !important;
}
a {
  color: var(--accent);
}
a:hover {
  color: var(--accent-hover);
}
hr {
  border-color: var(--border);
  opacity: 1;
}

/* ─── 3. NAVBAR ─────────────────────────────────────────────── */

.navbar {
  background-color: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1.5rem;
}

.navbar-brand {
  font-weight: 700;
  color: var(--accent) !important;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.navbar-brand:hover {
  color: var(--accent-hover) !important;
}

.nav-link {
  color: var(--text-muted) !important;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.375rem 0.625rem !important;
  border-radius: 6px;
  transition:
    background 0.15s,
    color 0.15s;
}
.nav-link:hover,
.nav-link.active {
  color: var(--text) !important;
  background: var(--surface-2);
}

.navbar-toggler {
  border-color: var(--border);
  color: var(--text-muted);
}

/* ─── 4. LAYOUT ─────────────────────────────────────────────── */

#main-wrapper {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 52px);
}

.page-header {
  padding: 1rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.page-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

#main-content {
  flex: 1;
  padding: 1.25rem 1.5rem;
  background: var(--bg);
}

footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ─── 5. MESSAGES DJANGO ────────────────────────────────────── */

.alert {
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}
.alert-success {
  background: rgba(63, 185, 80, 0.1);
  border-color: rgba(63, 185, 80, 0.3);
  color: var(--positive);
}
.alert-danger,
.alert-error {
  background: rgba(248, 81, 73, 0.1);
  border-color: rgba(248, 81, 73, 0.3);
  color: var(--negative);
}
.alert-warning {
  background: rgba(210, 153, 34, 0.1);
  border-color: rgba(210, 153, 34, 0.3);
  color: var(--warning);
}
.alert-info {
  background: rgba(56, 139, 253, 0.1);
  border-color: rgba(56, 139, 253, 0.3);
  color: var(--info);
}

/* ─── 6. TABLES FINANCIÈRES ─────────────────────────────────── */

.finance-table {
  font-size: 0.8125rem;
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.finance-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

.finance-table thead th a {
  color: var(--text-muted);
  text-decoration: none;
}
.finance-table thead th a:hover {
  color: var(--accent);
}

.finance-table tbody td {
  padding: 0.4375rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
  background: var(--surface);
}

.finance-table tbody tr:last-child td {
  border-bottom: none;
}

.finance-table tbody tr:hover td {
  background: rgba(88, 166, 255, 0.04);
}

.table-wrapper {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  overflow-x: auto;
}

/* Valeurs numériques */
.num {
  font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ticker {
  font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--accent);
}

/* ─── 7. CARDS ───────────────────────────────────────────────── */

.finance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.finance-card-header {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.finance-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
  color: var(--text);
}

/* Cards Bootstrap override */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.card-header {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
}
.card-body {
  padding: 1rem;
}
.card-footer {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 0.625rem 1rem;
}

/* ─── 8. BADGES DE NOTATION ─────────────────────────────────── */

.note-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2em 0.55em;
  border-radius: 20px;
  font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
  font-weight: 700;
  font-size: 0.75rem;
  min-width: 2.5em;
  white-space: nowrap;
}

.note-high {
  background: var(--badge-high-bg);
  color: var(--badge-high-fg);
}
.note-mid {
  background: var(--badge-mid-bg);
  color: var(--badge-mid-fg);
}
.note-low {
  background: var(--badge-low-bg);
  color: var(--badge-low-fg);
}

/* ─── 9. INDICATEURS POSITIF / NÉGATIF ─────────────────────── */

.value-positive {
  color: var(--positive);
  font-weight: 600;
}
.value-negative {
  color: var(--negative);
  font-weight: 600;
}
.value-neutral {
  color: var(--text-muted);
}

/* ─── 10. BOUTONS ────────────────────────────────────────────── */

.btn {
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-outline-primary {
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}
.btn-outline-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--border);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--negative);
  border-color: var(--negative);
  color: #fff;
}

.btn-outline-danger {
  border-color: var(--negative);
  color: var(--negative);
  background: transparent;
}
.btn-outline-danger:hover {
  background: var(--negative);
  color: #fff;
}

.btn-icon {
  padding: 0.25rem 0.4rem;
  font-size: 0.75rem;
  line-height: 1.2;
  border-radius: 6px;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
}

/* ─── 11. FORMULAIRES ───────────────────────────────────────── */

.form-control,
.form-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
}
.form-control:focus,
.form-select:focus {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
  outline: none;
}
.form-control::placeholder {
  color: var(--text-muted);
}
.form-label {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.form-check-label {
  color: var(--text);
}
.invalid-feedback {
  font-size: 0.75rem;
}

.form-container {
  max-width: 640px;
  margin: 0 auto;
}

/* Crispy forms override */
.crispy-form .mb-3 {
  margin-bottom: 1rem !important;
}

/* ─── 12. PAGINATION ─────────────────────────────────────────── */

.pagination {
  gap: 0.25rem;
}

.page-link {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px !important;
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  transition:
    background 0.15s,
    color 0.15s;
}
.page-link:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.page-item.disabled .page-link {
  background: var(--surface-2);
  color: var(--text-muted);
  opacity: 0.5;
}

/* ─── 13. HTMX LOADING ───────────────────────────────────────── */

.htmx-indicator {
  display: none;
  opacity: 0;
  transition: opacity 0.15s ease-in;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
  opacity: 1;
}

.sync-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── 14. UTILITAIRES ────────────────────────────────────────── */

.border-color {
  border-color: var(--border) !important;
}
.surface-bg {
  background: var(--surface) !important;
}
.surface-2-bg {
  background: var(--surface-2) !important;
}

/* Stats row */
.stat-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}
.stat-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.stat-value {
  font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
  font-weight: 700;
  font-size: 1.1rem;
}

/* Sticky table header */
.sticky-header thead th {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Responsive */
@media (max-width: 768px) {
  #main-content {
    padding: 1rem;
  }
  .page-header {
    padding: 0.75rem 1rem;
  }
  .navbar {
    padding: 0.5rem 1rem;
  }
  .finance-table {
    font-size: 0.75rem;
  }
  .finance-table thead th,
  .finance-table tbody td {
    padding: 0.375rem 0.5rem;
  }
}

/* ─── 15. TOGGLE DARK/LIGHT (TRANSITION) ────────────────────── */

html,
body,
.navbar,
.card,
.finance-table,
.finance-table tbody td,
.finance-table thead th,
#main-content,
.page-header,
footer {
  transition:
    background-color 0.2s ease,
    color 0.1s ease,
    border-color 0.2s ease;
}

/* ─── 16. SCREENER TABLE (overflow-x) ───────────────────────── */

.screener-table {
  font-size: 0.8125rem;
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 900px; /* force scroll horizontal sur petits écrans */
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.screener-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.625rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
  position: sticky;
  top: 0;
  z-index: 10;
}
.screener-table thead th a {
  color: var(--text-muted);
  text-decoration: none;
}
.screener-table thead th a:hover {
  color: var(--accent);
}
.screener-table tbody td {
  padding: 0.4375rem 0.625rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
  background: var(--surface);
}
.screener-table tbody tr:last-child td {
  border-bottom: none;
}
.screener-table tbody tr:hover td {
  background: rgba(88, 166, 255, 0.04);
}
