:root {
    --color-bg: #f4f6f8;
    --color-surface: #ffffff;
    --color-border: #dde2e7;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-success: #16a34a;
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* Top navigation */
.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 8px;
    gap: 24px;
}
/* Sous ~860px, le menu ne tient plus sur une seule ligne : la navigation passe sur sa
   propre ligne, sous l'enseigne et le menu utilisateur. Evite que la barre ne fasse
   defiler toute la page horizontalement (constate sur mobile et tablette). */
@media (max-width: 860px) {
    .topbar-inner { justify-content: space-between; }
    .main-nav { order: 3; flex-basis: 100%; }
}
.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; }
.brand-nom { font-weight: 700; font-size: 20px; color: var(--color-text); letter-spacing: -0.02em; }
.brand-tld { color: #0d9488; }

/* Accroche : tiree au hasard a chaque chargement, visiteurs publics uniquement. */
.brand-accroche {
    margin: 0;
    padding-left: 14px;
    border-left: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 13px;
    font-style: italic;
    white-space: nowrap;
}
@media (max-width: 700px) { .brand-accroche { display: none; } }
.main-nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.main-nav a {
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-weight: 500;
}
.main-nav a:hover { background: var(--color-bg); text-decoration: none; }
.main-nav a.active { background: #eef2ff; color: var(--color-primary); }
.user-menu { display: flex; align-items: center; gap: 12px; color: var(--color-text-muted); }

/* Cards / panels */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { margin: 0; font-size: 22px; }

/* Stat tiles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-tile .stat-value { font-size: 28px; font-weight: 700; }
.stat-tile .stat-label { color: var(--color-text-muted); font-size: 13px; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group.full { grid-column: 1 / -1; }
label { font-weight: 600; font-size: 13px; color: var(--color-text-muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=tel], select, textarea {
    padding: 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.hint { color: var(--color-text-muted); font-size: 12px; }
.error-text { color: var(--color-danger); font-size: 12px; }

/* Checkbox row */
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type=checkbox] { width: auto; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--color-bg);
    color: var(--color-text);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-link { background: none; border: none; padding: 0; color: var(--color-primary); font-weight: 500; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.actions-row { display: flex; gap: 8px; margin-top: 20px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); text-align: left; font-size: 14px; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: #fafbfc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); }
.table-wrap table { border: none; }
.table-wrap .table-wrap { border: none; }

/* En-tetes de colonnes triables */
th .sort-link {
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
th .sort-link:hover { color: var(--color-primary); text-decoration: none; }
th .sort-arrow { font-size: 9px; line-height: 1; color: var(--color-primary); }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-erreur { background: #fee2e2; color: #991b1b; }
.badge-best { background: #fef3c7; color: #92400e; }

/* Filters */
.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 16px;
}
.filters .form-group { margin-bottom: 0; min-width: 160px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* Login */
.login-wrap {
    max-width: 380px;
    margin: 80px auto;
}
.login-wrap h1 { text-align: center; margin-bottom: 24px; }

.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--color-border); font-size: 13px; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }

.section-title { font-size: 16px; font-weight: 700; margin: 28px 0 12px; }

/* Comparateur (front) */
.devise-select-form { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.devise-select-form .form-group { margin-bottom: 0; min-width: 260px; }

/* Liste des devises avec drapeaux (remplace le select natif quand JS est actif) */
.devise-picker { position: relative; min-width: 260px; }
.devise-picker-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 32px 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.devise-picker-trigger::after {
    content: "";
    position: absolute;
    right: 12px;
    top: 50%;
    width: 0;
    height: 0;
    margin-top: -2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--color-text-muted);
    pointer-events: none;
}
.devise-picker-trigger:focus-visible,
.devise-picker-list:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.devise-picker-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.devise-picker-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
}
.devise-picker-option:hover,
.devise-picker-option.is-active { background: #eef2ff; }
.devise-picker-option[aria-selected="true"] { font-weight: 600; }

.devise-flag {
    width: 20px;
    height: 15px;
    flex: none;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}
/* Drapeau accolé à un libellé dans un tableau : aligné sur le texte, pas sur la ligne de base */
td .devise-flag { vertical-align: -3px; margin-right: 8px; }

/* Logo de banque : hauteur fixe, largeur libre — les logos vont du carré au très large.
   La largeur maximale evite qu'un logo panoramique ne pousse la colonne. */
.banque-logo {
    height: 22px;
    width: auto;
    max-width: 90px;
    object-fit: contain;
    vertical-align: -6px;
    margin-right: 10px;
}

.devise-code { font-weight: 600; font-variant-numeric: tabular-nums; }
.devise-libelle { color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.row-best-achat td.col-achat, tr.row-best-vente td.col-vente { font-weight: 700; color: var(--color-success); }
.cotation-note { color: var(--color-text-muted); font-size: 14px; margin: 0 0 12px; }

/* Date de relevé antérieure au jour : cours non actualisés par la banque */
.date-perimee { color: #d97706; font-weight: 600; cursor: help; }

/* Graphique d'historique */
.graphique-barre { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; margin-bottom: 12px; }
.graphique-onglets { display: flex; flex-wrap: wrap; gap: 4px; }
.graphique-onglets a {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 500;
}
.graphique-onglets a:hover { background: var(--color-bg); text-decoration: none; }
.graphique-onglets a.actif { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

.graphique-cadre { overflow-x: auto; }
.graphique { display: block; width: 100%; min-width: 520px; height: auto; }
.graphique .g-grille { stroke: var(--color-border); stroke-width: 1; }
.graphique .g-axe { fill: var(--color-text-muted); font-size: 11px; font-family: inherit; }
.graphique circle { cursor: help; }

.graphique-legende { display: flex; flex-wrap: wrap; gap: 18px; list-style: none; margin: 0 0 10px; padding: 0; font-size: 13px; color: var(--color-text-muted); }
.graphique-legende li { display: flex; align-items: center; gap: 7px; }
.g-puce { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* Avertissement legal sous le tableau du comparateur */
.avertissement {
    margin-top: 16px;
    padding: 12px 16px;
    border-left: 3px solid var(--color-border);
    background: var(--color-surface);
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-size: 13px;
}

/* Colonne "dernier traitement" de la liste des banques */
td.col-traitement { white-space: nowrap; }
td.col-traitement .badge[title] { cursor: help; }
.traitement-date { display: block; color: var(--color-text-muted); font-size: 12px; margin-top: 2px; }
.taux-value { font-variant-numeric: tabular-nums; }

/* Traitement */
.detail-toggle { cursor: pointer; }
.detail-row { display: none; }
.detail-row.open { display: table-row; }
