/**
 * Portfolio Manager — couche visuelle au-dessus de Bootstrap
 * Simple, lisible, mobile-first
 */

:root {
  --pm-bg: #f4f6f9;
  --pm-surface: #ffffff;
  --pm-border: rgba(15, 23, 42, 0.08);
  --pm-text: #0f172a;
  --pm-muted: #64748b;
  --pm-accent: #0d9488;
  --pm-accent-2: #0f766e;
  --pm-nav-from: #0f172a;
  --pm-nav-via: #134e4a;
  --pm-nav-to: #0f766e;
  --pm-radius: 12px;
  --pm-radius-sm: 8px;
  --pm-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
  --pm-shadow-lg: 0 4px 6px rgba(15, 23, 42, 0.04), 0 16px 40px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --pm-bg: #0c1222;
    --pm-surface: #141c2f;
    --pm-border: rgba(248, 250, 252, 0.08);
    --pm-text: #f1f5f9;
    --pm-muted: #94a3b8;
    --pm-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --pm-shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.25), 0 16px 40px rgba(0, 0, 0, 0.4);
  }

  body.bg-light {
    background-color: var(--pm-bg) !important;
    color: var(--pm-text);
  }

  .card {
    background-color: var(--pm-surface);
    border-color: var(--pm-border);
    color: var(--pm-text);
  }

  .text-muted {
    color: var(--pm-muted) !important;
  }

  /* Bootstrap text utilities can be too dark on dark bg */
  .text-body,
  .text-dark {
    color: var(--pm-text) !important;
  }

  .text-secondary {
    color: var(--pm-muted) !important;
  }

  .text-success {
    color: #34d399 !important;
  }

  .text-primary {
    color: #60a5fa !important;
  }

  a {
    color: #7dd3fc;
  }

  a:hover {
    color: #bae6fd;
  }

  .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--pm-text);
    --bs-table-border-color: var(--pm-border);
    color: var(--pm-text) !important;
  }

  .table-dark {
    --bs-table-bg: #1e293b;
    --bs-table-color: #f8fafc;
  }

  .table tbody td {
    color: var(--pm-text) !important;
  }

  .asset-symbol {
    color: var(--pm-text) !important;
  }

  .form-control,
  .form-select {
    background-color: rgba(15, 23, 42, 0.6);
    border-color: var(--pm-border);
    color: var(--pm-text);
  }

  .form-control:focus,
  .form-select:focus {
    background-color: rgba(15, 23, 42, 0.75);
    color: var(--pm-text);
  }
}

/* Typo & base */
html {
  -webkit-text-size-adjust: 100%;
}

body.bg-light {
  background-color: var(--pm-bg) !important;
  color: var(--pm-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}

h1, h2, h3, .h1 {
  letter-spacing: -0.02em;
}

/* Navbar */
.navbar.bg-gradient {
  background: linear-gradient(
    125deg,
    var(--pm-nav-from) 0%,
    var(--pm-nav-via) 45%,
    var(--pm-nav-to) 100%
  ) !important;
  box-shadow: var(--pm-shadow);
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.navbar-brand {
  font-weight: 700;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
}

/* Pill badge (header) */
.pill {
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.pill--glass {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Cartes */
.card {
  border: 1px solid var(--pm-border);
  border-radius: var(--pm-radius);
  box-shadow: var(--pm-shadow);
  overflow: hidden;
}

.summary-card {
  border-radius: var(--pm-radius);
  box-shadow: var(--pm-shadow-lg);
}

.card-header.bg-gradient {
  background: linear-gradient(
    125deg,
    var(--pm-nav-from) 0%,
    var(--pm-nav-via) 50%,
    var(--pm-nav-to) 100%
  ) !important;
  border: none;
  color: #fff;
  padding: 1rem 1.25rem;
}

.card-header.bg-gradient h3 {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
}

/* Stats (résumé) */
.stat {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  text-align: left;
  padding: 0.5rem 0;
}

.stat__icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--pm-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.stat__icon--success {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.stat__icon--primary {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
}

.stat__icon--info {
  background: rgba(14, 165, 233, 0.15);
  color: #0284c7;
}

@media (prefers-color-scheme: dark) {
  .stat__icon--success {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
  }
  .stat__icon--primary {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
  }
  .stat__icon--info {
    background: rgba(56, 189, 248, 0.2);
    color: #38bdf8;
  }
}

.stat__body {
  min-width: 0;
}

.stat__value {
  font-size: clamp(1.25rem, 4vw, 1.65rem);
  font-weight: 700;
  line-height: 1.2;
}

.stat__sub {
  font-size: 1rem;
  font-weight: 600;
}

/* Avatars symboles */
.asset-avatar {
  --av1: #0d9488;
  --av2: #0f766e;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--av1), var(--av2));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

.asset-avatar__mono {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  text-transform: uppercase;
}

.asset-symbol {
  font-size: 0.95rem;
}

.asset-sub {
  font-size: 0.75rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* (Badge soft supprimé) — plus de distinction stock/etf/fund dans l’UI */

/* Prix */
.price-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 140px;
  padding: 0.15rem 0.5rem;
  background: rgba(15, 23, 42, 0.04);
  border-radius: var(--pm-radius-sm);
  border: 1px solid var(--pm-border);
}

.price-chip i {
  opacity: 0.6;
  font-size: 0.75rem;
}

.price-chip .form-control {
  border: none;
  background: transparent;
  padding-left: 0;
  min-height: auto;
  font-variant-numeric: tabular-nums;
}

@media (prefers-color-scheme: dark) {
  .price-chip {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* Quantité (compact comme le prix) */
.qty-chip {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 96px;
  max-width: 140px;
  padding: 0.15rem 0.5rem;
  background: rgba(15, 23, 42, 0.04);
  border-radius: var(--pm-radius-sm);
  border: 1px solid var(--pm-border);
}

.qty-chip .form-control {
  border: none;
  background: transparent;
  min-height: auto;
  padding: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.qty-chip .form-control[readonly] {
  cursor: default;
}

@media (prefers-color-scheme: dark) {
  .qty-chip {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* Boutons d’action */
.action-buttons .btn {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Tableau — desktop */
.table-hover tbody tr:hover {
  background-color: rgba(13, 148, 136, 0.06);
}

.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  white-space: nowrap;
}

/* Tableau — mobile : cartes empilées */
@media (max-width: 767.98px) {
  .table-responsive {
    border-radius: var(--pm-radius);
    overflow: visible;
  }

  .table-responsive .table thead {
    display: none;
  }

  .table-responsive .table tbody tr {
    display: block;
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--pm-border);
    border-radius: var(--pm-radius);
    background: var(--pm-surface);
    box-shadow: var(--pm-shadow);
  }

  .table-responsive .table tbody td {
    display: grid;
    grid-template-columns: minmax(100px, 38%) 1fr;
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 0.55rem 0;
    border: none;
    text-align: right;
  }

  .table-responsive .table tbody td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--pm-muted);
    text-align: left;
  }

  .table-responsive .table tbody td[data-label="Symbol"] {
    grid-template-columns: 1fr;
    text-align: left;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--pm-border);
    margin-bottom: 0.25rem;
  }

  .table-responsive .table tbody td[data-label="Symbol"]::before {
    margin-bottom: 0.35rem;
  }

  .table-responsive .table tbody td[data-label="Symbol"] > .d-flex {
    margin-top: 0.25rem;
  }

  /* Ligne vide / message */
  .table-responsive .table tbody tr td[colspan] {
    display: block;
    text-align: center;
    grid-template-columns: 1fr;
  }

  .table-responsive .table tbody tr td[colspan]::before {
    display: none;
  }

  .asset-sub {
    white-space: normal;
    max-width: none;
  }

  .action-buttons {
    justify-content: flex-end;
    width: 100%;
  }

  .price-chip {
    max-width: none;
    justify-content: flex-end;
    margin-left: auto;
  }

  .qty-chip {
    max-width: none;
    justify-content: flex-end;
    margin-left: auto;
  }
}

/* Boutons page d’accueil — pleine largeur confortable sur mobile */
@media (max-width: 575.98px) {
  .container.mt-5 {
    margin-top: 1.25rem !important;
  }

  .row.mb-4 h2 {
    font-size: 1.35rem;
  }
}

/* Formulaire add.php */
.card.shadow-lg {
  box-shadow: var(--pm-shadow-lg) !important;
}

.form-control-lg:focus,
.form-select-lg:focus {
  border-color: var(--pm-accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.2);
}

.btn-success {
  background: linear-gradient(180deg, #14b8a6 0%, var(--pm-accent-2) 100%);
  border: none;
}

.btn-success:hover {
  filter: brightness(1.05);
}

.btn-info {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: #0369a1;
}

.btn-info:hover {
  background: rgba(14, 165, 233, 0.28);
  color: #0c4a6e;
}

@media (prefers-color-scheme: dark) {
  .btn-info {
    color: #7dd3fc;
    border-color: rgba(125, 211, 252, 0.35);
  }
  .btn-info:hover {
    color: #e0f2fe;
    background: rgba(14, 165, 233, 0.25);
  }
}

/* Accessibilité */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
