/* ─────────────────────────────────────────────────────────────────────────────
   finance.vanfleteren.fr — Design system inspiré de TheSiteFuse
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --blue:      #2563eb;
  --blue-dark: #1d4ed8;
  --blue-50:   #eff6ff;
  --blue-100:  #dbeafe;
  --navy:      #0f172a;
  --ok:        #16a34a;
  --ok-bg:     #dcfce7;
  --ok-text:   #166534;
  --warn:      #d97706;
  --warn-bg:   #fef3c7;
  --warn-text: #92400e;
  --err:       #dc2626;
  --err-bg:    #fee2e2;
  --err-text:  #991b1b;
  --info:      #1d4ed8;
  --info-bg:   #dbeafe;
  --info-text: #1e40af;
  --text:      #0f172a;
  --text-2:    #374151;
  --text-3:    #64748b;
  --text-4:    #94a3b8;
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --border-lt: #f1f5f9;
  --r-xs:  4px;
  --r-sm:  8px;
  --r:     12px;
  --r-lg:  16px;
  --r-xl:  24px;
  --r-full: 9999px;
  --sh-xs: 0 1px 2px rgba(0,0,0,.05);
  --sh-sm: 0 2px 6px rgba(0,0,0,.07);
  --sh:    0 4px 12px rgba(0,0,0,.09);
  --sh-lg: 0 8px 24px rgba(0,0,0,.11);
  --sh-xl: 0 16px 48px rgba(0,0,0,.14);
  --tr:    .18s cubic-bezier(.4,0,.2,1);
  --header-h: 60px;
  --sidebar-w: 220px;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 15px; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; transition: color var(--tr); }
a:hover { color: var(--blue-dark); text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.page-wrap {
  display: flex;
  min-height: 100vh;
}
.main-content {
  flex: 1;
  padding: 24px;
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  max-width: 1600px;
}
.container { max-width: 1400px; margin: 0 auto; }
.page-narrow { max-width: 760px; margin: 0 auto; padding: 32px 16px; }

/* ── Header ──────────────────────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 200;
  gap: 16px;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -.02em;
  text-decoration: none;
}
.header-logo:hover { color: #fff; text-decoration: none; }
.logo-icon {
  width: 32px; height: 32px;
  background: var(--blue);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,.8);
  font-size: .875rem;
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--blue);
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-nav a {
  color: rgba(255,255,255,.7);
  font-size: .875rem;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  transition: all var(--tr);
  text-decoration: none;
}
.header-nav a:hover,
.header-nav a.active {
  color: #fff;
  background: rgba(255,255,255,.1);
  text-decoration: none;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  padding: 16px 0;
}
.sidebar-section { margin-bottom: 8px; }
.sidebar-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-4);
  padding: 8px 16px 4px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text-2);
  font-size: .875rem;
  border-radius: 0;
  transition: all var(--tr);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: var(--blue-50);
  color: var(--blue);
  text-decoration: none;
  border-left-color: var(--blue-100);
}
.sidebar-link.active {
  background: var(--blue-50);
  color: var(--blue);
  font-weight: 600;
  border-left-color: var(--blue);
}
.sidebar-link svg, .sidebar-link .s-icon { width: 16px; height: 16px; opacity: .7; flex-shrink: 0; }
.sidebar-link.active svg, .sidebar-link.active .s-icon { opacity: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh-sm);
  padding: 20px;
}
.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .dot {
  width: 8px; height: 8px;
  border-radius: var(--r-full);
  background: var(--blue);
  flex-shrink: 0;
}

/* ── KPI Bar ─────────────────────────────────────────────────────────────────── */
.kpi-bar {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh-sm);
  overflow: hidden;
  margin-bottom: 20px;
}
.kpi-item {
  flex: 1;
  padding: 14px 16px;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.kpi-item:last-child { border-right: none; }
.kpi-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-4);
  margin-bottom: 4px;
  white-space: nowrap;
}
.kpi-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value.positive { color: var(--ok); }
.kpi-value.negative { color: var(--err); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--tr);
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--sh-sm); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-secondary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-outline { background: transparent; color: var(--blue); border-color: var(--blue); }
.btn-outline:hover { background: var(--blue-50); color: var(--blue); }
.btn-ghost { background: transparent; color: var(--text-3); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text-2); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-danger { background: var(--err-bg); color: var(--err-text); border-color: #fca5a5; }
.btn-danger:hover { background: var(--err); color: #fff; }
.btn-ok { background: var(--ok-bg); color: var(--ok-text); border-color: #86efac; }
.btn-ok:hover { background: var(--ok); color: #fff; }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; border-radius: var(--r); box-shadow: var(--sh-sm); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: .875rem;
}
.data-table th {
  background: var(--bg);
  color: var(--text-3);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table th.right, .data-table td.right { text-align: right; }
.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-lt);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--tr); }
.data-table tbody tr:hover { background: var(--blue-50); }
.data-table tfoot td {
  font-weight: 700;
  background: var(--bg);
  border-top: 2px solid var(--border);
}
.ticker-link { font-weight: 700; color: var(--blue); font-family: monospace; }
.ticker-link:hover { color: var(--blue-dark); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok  { background: var(--ok-bg);   color: var(--ok-text); }
.badge-err { background: var(--err-bg);  color: var(--err-text); }
.badge-warn{ background: var(--warn-bg); color: var(--warn-text); }
.badge-info{ background: var(--info-bg); color: var(--info-text); }
.badge-neutral { background: var(--bg); color: var(--text-3); border: 1px solid var(--border); }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-2);
}
.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--tr), box-shadow var(--tr);
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-hint { font-size: .8rem; color: var(--text-4); margin-top: 4px; }
.form-error { font-size: .8rem; color: var(--err); margin-top: 4px; }

/* ── Modals ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xl);
  width: 100%;
  max-width: 500px;
  padding: 28px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.modal-close {
  width: 28px; height: 28px;
  border: none; background: var(--bg);
  border-radius: var(--r-full);
  cursor: pointer;
  color: var(--text-3);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--tr);
}
.modal-close:hover { background: var(--err-bg); color: var(--err); }

/* ── Flash messages ──────────────────────────────────────────────────────────── */
.flash-wrap {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}
.flash {
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: .875rem;
  box-shadow: var(--sh-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slide-in .25s ease;
}
.flash.success { background: var(--ok-bg); color: var(--ok-text); border-left: 4px solid var(--ok); }
.flash.error   { background: var(--err-bg); color: var(--err-text); border-left: 4px solid var(--err); }
.flash.info    { background: var(--info-bg); color: var(--info-text); border-left: 4px solid var(--info); }
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Charts ──────────────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh-sm);
  padding: 16px;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.chart-title-text {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
}
.period-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 2px;
}
.period-tab {
  padding: 3px 10px;
  font-size: .75rem;
  font-weight: 600;
  border-radius: var(--r-xs);
  cursor: pointer;
  color: var(--text-3);
  transition: all var(--tr);
  border: none;
  background: none;
}
.period-tab.active, .period-tab:hover {
  background: var(--surface);
  color: var(--blue);
  box-shadow: var(--sh-xs);
}

/* uPlot tooltip */
.u-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--navy);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: .8rem;
  box-shadow: var(--sh-lg);
  z-index: 100;
  min-width: 160px;
  line-height: 1.7;
}
.u-tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.u-tooltip-dot {
  width: 8px; height: 8px;
  border-radius: var(--r-full);
  flex-shrink: 0;
}
.u-tooltip-val { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Grid layouts ────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

/* ── Misc ────────────────────────────────────────────────────────────────────── */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.text-positive { color: var(--ok) !important; font-weight: 600; }
.text-negative { color: var(--err) !important; font-weight: 600; }
.text-neutral  { color: var(--text-3); }
.text-sm { font-size: .8rem; }
.text-muted { color: var(--text-4); font-size: .8rem; }
.mono { font-family: 'SFMono-Regular', Consolas, monospace; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page: Ticker grid ───────────────────────────────────────────────────────── */
.ticker-grid-top {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}
.ticker-meta-card .price-main {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}
.ticker-meta-card .price-change {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 2px;
}
.ticker-metrics { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.ticker-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-lt);
  font-size: .85rem;
}
.ticker-metric-row:last-child { border-bottom: none; }
.ticker-metric-label { color: var(--text-3); }
.ticker-metric-val { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.ticker-description {
  font-size: .8rem;
  color: var(--text-3);
  line-height: 1.5;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-lt);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform var(--tr); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 16px; }
  .grid-2, .grid-1-2, .grid-2-1 { grid-template-columns: 1fr; }
  .ticker-grid-top { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .kpi-bar { flex-direction: column; }
  .kpi-item { border-right: none; border-bottom: 1px solid var(--border); }
  .kpi-item:last-child { border-bottom: none; }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
