/* ==========================================================================
   Crypto Trading Bot — Design system sobre / moderne
   Refonte complète (09/2026) : remplace l'ancien thème dégradé violet /
   emojis omniprésents par une interface claire, neutre, orientée données.
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #f8f9fb;
    --border: #e4e7ec;
    --text: #101828;
    --text-muted: #667085;
    --text-faint: #98a2b3;

    --primary: #2f5fe0;
    --primary-dark: #2547b3;
    --primary-soft: #eaf0fe;

    --success: #12875a;
    --success-soft: #e6f6ee;
    --danger: #d92d20;
    --danger-soft: #fdeceb;
    --warning: #b54708;
    --warning-soft: #fef6e6;
    --neutral-soft: #eef0f3;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 24px;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1240px;
    margin: 0 auto;
}

a { color: var(--primary); }

/* ---------- Header ---------- */

header {
    background: var(--surface);
    padding: 18px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

h1 {
    color: var(--text);
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ---------- Layout / Cards ---------- */

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 18px;
}

.card {
    background: var(--surface);
    padding: 22px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    gap: 10px;
}

h2 {
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.card-subtitle {
    color: var(--text-faint);
    font-size: 12px;
    margin-top: 2px;
}

.wide { grid-column: span 2; }

/* ---------- Stat grid ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.stat-box {
    padding: 14px 16px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
    font-weight: 600;
}

.stat-value {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.price-row {
    display: flex;
    gap: 20px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.price-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.price-item strong {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ---------- Badges / Pills ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--text-muted);
    white-space: nowrap;
}

.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.testnet-badge { display: none; }

/* ---------- Guardrails (plafond capital + stop journalier + alertes) ---------- */

.guardrails-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.guardrail {
    padding: 14px 16px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.guardrail-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
    gap: 8px;
}

.guardrail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.guardrail-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.progress-track {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--primary);
    transition: width 0.4s ease;
}

.progress-fill.success { background: var(--success); }
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger  { background: var(--danger); }

.guardrail-note {
    margin-top: 8px;
    font-size: 11.5px;
    color: var(--text-faint);
}

.alert-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 12px;
    font-size: 13px;
}

.alert-status-row .label {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Auto-trading toggle ---------- */

.auto-trading-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border);
    transition: .25s;
    border-radius: 999px;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .25s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--success);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

#autoTradingLabel {
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
}

/* ---------- Buttons ---------- */

button {
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

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

.btn-danger {
    background: var(--surface);
    color: var(--danger);
    border-color: var(--danger-soft);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-faint);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

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

tbody tr:hover { background: var(--surface-alt); }

.cell-muted { color: var(--text-muted); }
.cell-empty { color: var(--text-faint); text-align: center; padding: 24px 12px; }

.pnl-positive { color: var(--success); font-weight: 600; }
.pnl-negative { color: var(--danger); font-weight: 600; }

/* ---------- Footer note ---------- */

.data-note {
    margin-top: 18px;
    font-size: 11.5px;
    color: var(--text-faint);
    text-align: right;
}

/* ---------- Loading overlay ---------- */

.loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(16, 24, 40, 0.55);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    border: 3px solid rgba(255,255,255,0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: white;
    margin-top: 16px;
    font-size: 14px;
}

/* ---------- Login page (partagé avec login.php) ---------- */

.login-body {
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    background: var(--surface);
    padding: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 380px;
}

.login-header {
    text-align: center;
    margin-bottom: 26px;
}

.login-header h1 {
    color: var(--text);
    font-size: 19px;
    margin-bottom: 6px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 13px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.error-message {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
}

.btn-login {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-login:hover { background: var(--primary-dark); }

.login-footer {
    text-align: center;
    margin-top: 18px;
    color: var(--text-faint);
    font-size: 11.5px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .guardrails-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    body { padding: 12px; }
    .dashboard { grid-template-columns: 1fr; }
    .wide { grid-column: span 1; }
    header { flex-direction: column; align-items: stretch; }
    .header-controls { justify-content: space-between; }
    table { min-width: 640px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .card { padding: 16px; }
    h1 { font-size: 17px; }
}
