:root {
  /* Palette "Midnight Gold" - Finance Theme */
  --bg-body: #f8f9fa;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #b7950b; /* Doré mat élégant */
  --primary-hover: #d4af37; /* Doré plus vif au survol */
  --primary-light: rgba(183, 149, 11, 0.1);
  --accent-blue: #1e3a8a; /* Bleu nuit profond pour les touches techniques */
  --border-color: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --header-height: 70px;
  --sidebar-width: 320px;
  --transition-speed: 0.3s;
}

[data-theme="dark"] {
  --bg-body: #0f172a; /* Bleu nuit très sombre (Slate 900) */
  --bg-card: #1e293b; /* Slate 800 */
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #d4af37; /* Doré plus lumineux sur fond sombre */
  --primary-hover: #fcd34d;
  --primary-light: rgba(212, 175, 55, 0.15);
  --accent-blue: #3b82f6;
  --border-color: #334155;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  overflow-x: hidden;
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

/* --- Layout --- */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.logo-section h1 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.75rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.main-grid {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr); /* minmax(0, 1fr) prevents grid blowout */
  gap: 2rem;
  flex: 1;
  padding-bottom: 3rem;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

/* Mode "Résultats" : Sidebar repliée */
.main-grid.sidebar-collapsed {
  grid-template-columns: 60px 1fr;
}

/* --- Sidebar / Config Panel --- */
.config-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--primary); /* Always gold */
  padding: 1.5rem;
  /* Removed sticky positioning */
  height: auto; 
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: visible; /* Changed from hidden to visible to avoid cutting off tooltips or content */
  z-index: 10;
}

.main-grid.sidebar-collapsed .config-panel {
  padding: 1rem 0.5rem;
  width: 60px;
  opacity: 0.9;
  border-color: var(--border-color); /* Revert to normal border when collapsed if desired, or keep gold */
}

/* Masquer le contenu quand replié */
.main-grid.sidebar-collapsed .config-panel form,
.main-grid.sidebar-collapsed .config-panel .card-header h2,
.main-grid.sidebar-collapsed .config-panel .card-header .close-sidebar-btn {
  display: none;
}

/* Bouton pour rouvrir la sidebar */
.sidebar-toggle {
  display: none;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 1rem;
  gap: 1rem;
}

.sidebar-toggle:hover {
  color: var(--primary-hover);
}

.main-grid.sidebar-collapsed .sidebar-toggle {
  display: flex;
}

.config-panel:hover {
  /* border-color: var(--primary); Already gold */
  box-shadow: var(--shadow-md);
}

/* Close Sidebar Button */
.close-sidebar-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.close-sidebar-btn:hover {
  background-color: var(--border-color);
  color: var(--text-main);
}

/* --- Forms & Inputs --- */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  height: auto;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form-row.date-row {
  gap: 0.5rem;
}

.form-row > div {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.form-row > div > input,
.form-row > div > select {
  margin-top: auto;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

/* Label avec Tooltip aligné */
.label-with-tooltip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-body);
  color: var(--text-main);
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
}

[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

input[type="date"] {
  font-family: 'Inter', sans-serif;
  color-scheme: dark; /* Default to dark scheme for calendar popup */
}

[data-theme="light"] input[type="date"] {
  color-scheme: light;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Supprimer les flèches des inputs number */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
input[type=number] {
  -moz-appearance: textfield;
}

/* Checkboxes & Radios Custom */
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: auto; /* Ensure it grows */
  width: 100%;
  padding-right: 0.5rem;
  margin-bottom: 0.5rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 6px;
  transition: background-color 0.2s;
  cursor: pointer;
}

.checkbox-item:hover {
  background-color: var(--bg-body);
}

.checkbox-item input[type="checkbox"],
.checkbox-item input[type="radio"] {
  accent-color: var(--primary);
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
}

.checkbox-item label {
  margin-bottom: 0;
  cursor: pointer;
  color: var(--text-main);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  gap: 0.5rem;
  text-decoration: none; /* Ensure no underline for links styled as buttons */
}

.btn-primary {
  background-color: var(--primary);
  color: #1e293b; /* Dark text for better contrast on gold */
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.15);
}

.btn-secondary {
  background-color: var(--bg-body);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

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

.btn-guide {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: color 0.2s, background-color 0.2s;
}

.btn-guide:hover {
  color: var(--primary);
  background-color: var(--primary-light);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: rotate(15deg);
}

/* --- Cards & Results --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Position Card Special Style */
.position-card {
  background: linear-gradient(135deg, rgba(30, 41, 59, 1) 0%, rgba(15, 23, 42, 1) 100%);
  border: 1px solid var(--primary);
  position: relative;
  overflow: hidden;
}

.position-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 100px; height: 100px;
  background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
  opacity: 0.1;
  pointer-events: none;
}

.position-card .card-title {
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
}

.position-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0.5rem 0;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  text-align: center;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  /* Custom Scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.table-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-container::-webkit-scrollbar-track {
  background: transparent;
}
.table-container::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}
.table-container::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

tr:last-child td {
  border-bottom: none;
}

/* Utilities */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: #f59e0b; }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-4 { margin-top: 1rem; }

/* Collapsible Animation */
.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out, opacity 0.3s ease-out, margin 0.3s ease;
  opacity: 0;
  margin-top: 0;
}

.collapsible-content.open {
  max-height: 1000px; /* Sufficiently large value */
  opacity: 1;
  margin-top: 1rem;
}

/* Tooltip */
.tooltip-container {
  position: relative;
  display: inline-block;
  margin-left: 0.25rem;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--border-color);
  color: var(--text-muted);
  font-size: 10px;
  cursor: help;
}

.tooltip-content {
  visibility: hidden;
  width: 250px;
  background-color: var(--bg-card);
  color: var(--text-main);
  text-align: left;
  border-radius: 6px;
  padding: 0.75rem;
  position: absolute;
  z-index: 100;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.3s;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: normal;
  line-height: 1.4;
}

.tooltip-container:hover .tooltip-content {
  visibility: visible;
  opacity: 1;
}

/* Loading */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.8); /* Fond sombre semi-transparent */
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 3px solid rgba(212, 175, 55, 0.3);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
}

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

/* Chart Container */
.chart-container {
  position: relative;
  height: 400px;
  width: 100%;
}

/* Guide Page Specifics */
.guide-content {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.8;
}

.guide-content h2 {
  color: var(--primary);
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.guide-content p {
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.ad-slot {
  background: var(--bg-body);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  margin: 2rem 0;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Footer */
.footer {
  margin-top: auto;
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  .config-panel {
    position: static;
    width: 100%;
  }
  .main-grid.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  .main-grid.sidebar-collapsed .config-panel {
    width: 100%;
    padding: 1.5rem;
  }
  .main-grid.sidebar-collapsed .config-panel form,
  .main-grid.sidebar-collapsed .config-panel .card-header h2 {
    display: block; /* On ne collapse pas sur mobile */
  }
  .sidebar-toggle {
    display: none !important;
  }
}

/* --- Tarteaucitron Customization --- */
/* Banner Background */
#tarteaucitronAlertBig {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-top: 2px solid var(--primary) !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2) !important;
    font-family: 'Inter', sans-serif !important;
}

/* Text Colors */
#tarteaucitronDisclaimerAlert, 
#tarteaucitronDisclaimerAlert b {
    color: var(--text-main) !important;
}

/* Buttons */
#tarteaucitronPersonalization, 
#tarteaucitronClosePanel {
    background-color: var(--bg-body) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
}

#tarteaucitronPersonalization:hover, 
#tarteaucitronClosePanel:hover {
    background-color: var(--border-color) !important;
}

/* CTA Buttons (Accept/Deny) */
button.tarteaucitronCTAButton {
    background-color: var(--primary) !important;
    color: #1e293b !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    padding: 10px 20px !important;
}

button.tarteaucitronCTAButton:hover {
    background-color: var(--primary-hover) !important;
    transform: translateY(-1px);
}

button.tarteaucitronCTAButton.tarteaucitronDeny {
    background-color: #000000 !important;
    border: 1px solid #000000 !important;
    color: #ffffff !important;
}

button.tarteaucitronCTAButton.tarteaucitronDeny:hover {
    background-color: #333333 !important;
    color: #ffffff !important;
    border-color: #333333 !important;
}

/* Panel (when opened) */
#tarteaucitronRoot #tarteaucitron {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

#tarteaucitronRoot .tarteaucitronTitle {
    color: var(--primary) !important;
}

#tarteaucitronRoot .tarteaucitronBorder {
    border-color: var(--border-color) !important;
    background-color: var(--bg-body) !important;
    color: var(--text-main) !important;
}

#tarteaucitronRoot .tarteaucitronAllow {
    background-color: var(--success) !important;
}

#tarteaucitronRoot .tarteaucitronDeny {
    background-color: var(--danger) !important;
}
