/* ============================================================
   TradingApp Design System - COMPOSANTS - V1
   ============================================================
   Importe ds-vars.css en premier dans la base.html.
   Ce fichier contient les composants reutilisables, partages
   par les 3 apps (Hub, RSS, Portefeuille). Ne mettre ici QUE
   ce qui est commun. Les surcharges specifiques a une app vont
   dans le style.css de l'app.
   ============================================================ */

/* ---------- Reset doux ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: var(--weight-semibold); color: var(--text); }
p { margin: 0; }

button { font-family: inherit; font-size: inherit; }

code, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
code {
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  color: var(--text);
  border: 1px solid var(--border);
}

/* ============================================================
   LOGO - Wordmark "TradingApp" (Direction 2)
   ============================================================ */
.wordmark {
  font-family: var(--font-sans);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--text);
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-md);
  white-space: nowrap;
  line-height: 1;
}
.wordmark .wm-trading { color: var(--text); }
.wordmark .wm-app { color: var(--accent); }
.wordmark .wm-suffix {
  color: var(--text-muted);
  font-weight: var(--weight-regular);
  font-size: var(--text-sm);
}

/* Variantes par app */
.wordmark.wm--rss .wm-app       { color: var(--app-rss); }
.wordmark.wm--portfolio .wm-app { color: var(--app-portfolio); }

/* Tailles */
.wordmark.wm--xl  { font-size: var(--text-3xl); letter-spacing: -0.02em; }
.wordmark.wm--xl .wm-suffix { font-size: var(--text-md); }
.wordmark.wm--lg  { font-size: var(--text-xl); }
.wordmark.wm--lg .wm-suffix { font-size: var(--text-base); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5);
}
.topbar.app--hub        { box-shadow: 0 2px 0 0 var(--app-hub); }
.topbar.app--rss        { box-shadow: 0 2px 0 0 var(--app-rss); }
.topbar.app--portfolio  { box-shadow: 0 2px 0 0 var(--app-portfolio); }

.topbar__left { display: flex; align-items: center; gap: var(--space-5); }
.topbar__right { display: flex; align-items: center; gap: var(--space-2); }

.topbar__nav {
  display: flex; gap: var(--space-1);
}
.topbar__nav a {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: var(--transition-fast);
}
.topbar__nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.topbar__nav a.active { color: var(--text); background: var(--bg-hover); }

@media (max-width: 540px) {
  .topbar { height: 52px; padding: 0 var(--space-4); }
  .topbar__nav { display: none; }
  .topbar__left { gap: var(--space-3); }
  .wordmark .wm-suffix { display: none; }
}

/* ============================================================
   BOUTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  user-select: none;
  min-height: 36px;
  line-height: 1.2;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn.is-loading { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent); color: var(--accent-contrast);
  font-weight: var(--weight-semibold);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); text-decoration: none; }

.btn-secondary {
  background: var(--bg-elevated); color: var(--text); border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); text-decoration: none; }

.btn-ghost {
  background: transparent; color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); text-decoration: none; }

.btn-danger {
  background: var(--negative); color: #fff;
  font-weight: var(--weight-semibold);
}
.btn-danger:hover:not(:disabled) { background: #DC2626; text-decoration: none; }

/* Tailles */
.btn-sm { padding: 6px 12px; font-size: var(--text-sm); min-height: 28px; }
.btn-lg { padding: 14px 24px; font-size: var(--text-md); min-height: 48px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; }

@media (max-width: 540px) {
  .btn { font-size: var(--text-md); min-height: 44px; }
  .btn-sm { font-size: var(--text-sm); min-height: 36px; }
  .btn-icon { width: 44px; height: 44px; }
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: var(--transition-fast);
}
.card-clickable { cursor: pointer; }
.card-clickable:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.card-compact  { padding: var(--space-4); }
.card-spacious { padding: var(--space-6); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-3);
}
.card-body { color: var(--text-muted); font-size: var(--text-sm); line-height: 1.6; }
.card-footer {
  margin-top: var(--space-4); padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex; gap: var(--space-2); justify-content: flex-end;
}

@media (max-width: 540px) {
  .card { padding: var(--space-4); }
}

/* ============================================================
   APP ICON (style outline pour les cards d'app du Hub)
   ============================================================ */
.app-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.app-icon svg { width: 28px; height: 28px; }

/* Couleurs par app (outline soft) */
.app-icon.color--hub {
  color: var(--app-hub);
  border-color: rgba(22,163,74,0.30);
  background: rgba(22,163,74,0.08);
}
.app-icon.color--rss {
  color: var(--app-rss);
  border-color: rgba(59,130,246,0.30);
  background: rgba(59,130,246,0.08);
}
.app-icon.color--portfolio {
  color: var(--app-portfolio);
  border-color: rgba(168,85,247,0.30);
  background: rgba(168,85,247,0.08);
}
.app-icon.color--cal      { color: var(--text-muted); }
.app-icon.color--docs     { color: var(--text-muted); }
.app-icon.color--neutral  { color: var(--text-muted); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  line-height: 1.5;
}
.badge-positive { background: var(--positive-soft); color: var(--positive); }
.badge-negative { background: var(--negative-soft); color: var(--negative); }
.badge-warning  { background: var(--warning-soft); color: var(--warning); }
.badge-info     { background: var(--info-soft); color: var(--info); }
.badge-neutral  { background: var(--bg-hover); color: var(--text-muted); }

/* ============================================================
   FORMULAIRES
   ============================================================ */
.field {
  display: flex; flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.field-label, .field label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}
.field .helper {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.input, .select, .textarea,
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="search"] {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: var(--transition-fast);
  min-height: 40px;
  width: 100%;
}
.input:focus-visible, .select:focus-visible, .textarea:focus-visible,
.field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}
.field.has-error .input,
.field.has-error input { border-color: var(--negative); }

.textarea { min-height: 96px; resize: vertical; }

.select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

@media (max-width: 540px) {
  .input, .select, .textarea,
  .field input { font-size: var(--text-md); min-height: 44px; }
}

/* Checkbox / radio (apparence custom) */
.check, .checkbox-row {
  display: inline-flex; align-items: center;
  gap: var(--space-2);
  cursor: pointer; user-select: none;
  font-size: var(--text-sm);
  color: var(--text);
}
.check input[type="checkbox"],
.check input[type="radio"],
.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ============================================================
   FLASH MESSAGES
   ============================================================ */
.flash-list {
  display: flex; flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.flash-list-page {
  max-width: 1100px;
  margin: var(--space-4) auto 0 auto;
  padding: 0 var(--space-5);
}
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid;
  border-left-width: 3px;
}
.flash-success {
  background: var(--positive-soft);
  border-color: var(--positive);
  color: var(--positive);
}
.flash-error {
  background: var(--negative-soft);
  border-color: var(--negative);
  color: var(--negative);
}
.flash-warn, .flash-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning);
}
.flash-info, .flash-message {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-8);
}

@media (max-width: 540px) {
  .main-content { padding: var(--space-6) var(--space-4) var(--space-7); }
  .flash-list-page { padding: 0 var(--space-4); }
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  padding: var(--space-5);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-xs);
  border-top: 1px solid var(--border);
}

/* ============================================================
   TABLEAUX
   ============================================================ */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}
.ds-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.ds-table thead { background: var(--surface); }
.ds-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.ds-table th.num, .ds-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.ds-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition-fast);
}
.ds-table tbody tr:last-child { border-bottom: none; }
.ds-table tbody tr:hover { background: var(--bg-hover); }
.ds-table td { padding: 12px 16px; }

.ds-table.table-compact th,
.ds-table.table-compact td { padding: 8px 12px; }

/* Helpers de colorisation financiere (neutres - reutilisables hors tableau) */
.gain { color: var(--positive); }
.loss { color: var(--negative); }
.ticker { font-family: var(--font-mono); font-weight: var(--weight-medium); }

/* ============================================================
   UTILITAIRES legers
   ============================================================ */
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* Live clock dans la topbar (utilise par le Hub) */
.live-clock {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  padding: 4px var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.live-clock::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
