/* Aligné sur supervision_at/nouveau/templates/base.html */
:root {
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --primary: #0f172a;
    --accent-blue: #0284c7;
    --accent-green: #10b981;
    --accent-green-hover: #059669;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    margin: 0;
    padding: 8px 10px;
    color: var(--text-main);
}

.container {
    width: 100%;
    max-width: none;
    margin: 0;
    background: var(--bg-card);
    padding: 14px 16px 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    min-height: calc(100vh - 16px);
    box-sizing: border-box;
}

.container.container-narrow {
    max-width: 440px;
    margin: 0 auto;
    min-height: auto;
}

.portal-header {
    margin-bottom: 14px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 12px;
    text-align: left;
}
.portal-header-guest {
    padding-bottom: 8px;
    margin-bottom: 10px;
}

.portal-header-top {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    justify-content: flex-start;
    width: 100%;
}

.portal-header-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
    flex: 1 1 auto;
}

.brand-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
    font-size: 1.25em;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: -0.025em;
}
.brand-logo { height: 32px; width: auto; object-fit: contain; }
.brand-logo-lg { height: 40px; }

.active-users-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    transition: all 0.2s ease;
}
.active-users-dot {
    width: 8px;
    height: 8px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
    animation: portal-pulse 2s infinite;
}
@keyframes portal-pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.session-user-badge {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 6px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    max-width: min(420px, 100%);
}
.session-user-badge strong { font-weight: 800; color: #1d4ed8; }

.nav-menu {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
    margin-top: 10px;
    padding-top: 0;
}

.nav-btn {
    background-color: #f1f5f9;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 7px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.8em;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.nav-btn:hover { background-color: #e2e8f0; color: var(--text-main); }
.nav-btn.active {
    background-color: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
    box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);
}
.nav-btn.logout {
    color: #991b1b;
    background-color: #fee2e2;
    border-color: #fecaca;
}
.nav-btn.logout:hover { background-color: #fecaca; color: #7f1d1d; }

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    margin-left: auto;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
}
.menu-toggle-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-main);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}
.menu-toggle.is-open .menu-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.menu-toggle.is-open .menu-toggle-bar:nth-child(2) { opacity: 0; }
.menu-toggle.is-open .menu-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

@media (min-width: 769px) {
    .menu-toggle { display: none !important; }
    .nav-menu { display: flex !important; }
}

@media (max-width: 768px) {
    body { padding: 6px 8px; }
    .container { padding: 12px; border-radius: 8px; min-height: calc(100vh - 12px); }
    .menu-toggle { display: inline-flex; }
    .portal-header-badges {
        flex: 1 1 100%;
        order: 3;
    }
    .brand-title { order: 1; }
    .menu-toggle { order: 2; }
    .nav-menu {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border-color);
    }
    .nav-menu.open { display: flex; }
    .nav-btn { width: 100%; justify-content: flex-start; padding: 12px 14px; font-size: 0.95em; }
    .session-user-badge { max-width: 100%; font-size: 0.72rem; }
    .active-users-badge { font-size: 0.72rem; }
    .session-user-badge span { word-break: break-all; }
}

.portal-content { min-height: 120px; }

.page-header {
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.page-header h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.02em;
}
.page-header p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}
.card h2 {
    margin: 0 0 10px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

.muted { color: var(--text-muted); font-size: 0.88rem; }

.btn, button.btn {
    display: inline-block;
    background: var(--accent-blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.btn:hover { filter: brightness(0.95); }
.btn-secondary {
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.error {
    background-color: var(--badge-red-bg, #fee2e2);
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85em;
    margin-bottom: 12px;
}
.ok {
    background: #ecfdf5;
    color: #047857;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
input[type=email], input[type=password], input[type=text], input[type=search], select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 10px;
    font-family: inherit;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}
table, .billing-inner-table {
    width: 100%;
    border-collapse: collapse;
    background-color: #ffffff;
    font-size: 0.85em;
}
th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}
tr:hover td { background-color: #f8fafc; }

/* Dashboard KPI (style proche supervision) */
.dash-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.dash-kpi {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 16px;
}
.dash-kpi-label {
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 6px;
}
.dash-kpi-value { font-size: 1rem; font-weight: 700; color: var(--text-main); line-height: 1.35; }
.dash-kpi-forfait { min-width: 0; }
.dash-service-list {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.45;
}
.dash-service-list li { margin-bottom: 4px; }
.dash-service-list li:last-child { margin-bottom: 0; }
.dash-kpi-value.dash-balance-due { color: #c2410c; }
.dash-kpi-value.dash-balance-ok { color: #15803d; }
.dash-quick-link { margin-top: 8px; font-size: 0.82rem; }
.dash-quick-link a { color: var(--accent-blue); font-weight: 600; text-decoration: none; }
.dash-quick-link a:hover { text-decoration: underline; }

/* Facturation */
.billing-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
}
.billing-tab {
    background-color: #f1f5f9;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 7px 12px;
    border-radius: 6px 6px 0 0;
    font-size: 0.8em;
    font-weight: 600;
    text-decoration: none;
}
.billing-tab.active {
    background: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
}
.billing-card { border-radius: 0 8px 8px 8px; margin-top: 0; }
.billing-tab:not(.active):hover { background: #e2e8f0; color: var(--text-main); }

.consolidation-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: space-between;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}
.consolidation-balance-label { font-size: 0.72em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.consolidation-balance-value { font-size: 1.35rem; font-weight: 800; color: #c2410c; }
.consolidation-balance-value.balance-zero { color: var(--accent-blue); }
.consolidation-balance-secondary { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.consolidation-counts { font-size: 0.82rem; color: var(--text-muted); margin-top: 6px; }
.consolidation-pdf-actions { margin-top: 10px; }
.portal-pdf-btn {
    display: inline-block;
    background: var(--accent-blue);
    color: #fff !important;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none;
}
.portal-pdf-btn:hover { filter: brightness(1.05); }
.portal-pdf-link {
    color: var(--accent-blue);
    font-weight: 700;
    text-decoration: none;
    font-size: 0.85rem;
}
.portal-pdf-link:hover { text-decoration: underline; }
.billing-table-wrap { max-height: 62vh; overflow: auto; }
.billing-inner-table .num { text-align: right; }
.account-statement-payment-row td { background: #f0fdf4 !important; }
.account-statement-unpaid-invoice td { background: #fffbeb !important; }
.account-statement-paid { color: #15803d; font-weight: 700; }
.payment-type-pill {
    background: #ede9fe;
    color: #5b21b6;
    padding: 3px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.82rem;
}
.billing-payment-summary {
    margin: 0 0 12px;
    padding: 8px 14px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    font-size: 0.85em;
    color: #166534;
}
/* Test de vitesse */
.portal-speedtest-layout .portal-content { max-width: 960px; }
.speedtest-plan-list { margin: 0; padding-left: 1.2rem; line-height: 1.5; }
.speedtest-plan-list li { margin-bottom: 10px; }
.speedtest-plan-speed { display: block; margin-top: 4px; color: var(--accent-blue); font-size: 0.95rem; }
.speedtest-plan-addr { display: block; font-size: 0.85rem; margin-top: 2px; }
.speedtest-plan-high {
    margin: 12px 0 0; padding: 10px 12px; background: #fff7ed; border: 1px solid #fdba74;
    border-radius: 8px; color: #9a3412; font-size: 0.9rem; font-weight: 600;
}
.speedtest-big-row {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: center; margin-bottom: 12px;
}
.speedtest-big-block {
    background: linear-gradient(180deg, #f0f9ff 0%, #fff 100%);
    border: 2px solid #bae6fd; border-radius: 12px; padding: 20px 12px;
}
.speedtest-big-label {
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted); font-weight: 800; margin-bottom: 8px;
}
.speedtest-big-value {
    font-size: clamp(2.5rem, 8vw, 3.75rem); font-weight: 900; line-height: 1;
    color: #0369a1; font-variant-numeric: tabular-nums;
}
.speedtest-big-unit { font-size: 1.1rem; font-weight: 700; color: #64748b; margin-top: 6px; }
.speedtest-status { text-align: center; margin: 8px 0 0; font-size: 0.88rem; }
.speedtest-rerun {
    display: block; margin: 12px auto 0; padding: 10px 18px; border: none; border-radius: 8px;
    background: var(--accent-blue); color: #fff; font-weight: 700; cursor: pointer; font-size: 0.9rem;
}
.speedtest-rerun:hover { filter: brightness(1.05); }
.speedtest-iframe-wrap {
    position: relative; width: 100%; min-height: 420px; border-radius: 10px; overflow: hidden;
    border: 1px solid var(--border-color); background: #0f172a;
}
.speedtest-iframe-wrap iframe {
    position: absolute; inset: 0; width: 100%; height: 100%; min-height: 420px; border: 0;
}
.speedtest-history-wrap { max-height: 280px; overflow: auto; margin-top: 8px; }
.speedtest-history-table .num { white-space: nowrap; }
.speedtest-history-hint { margin: 0 0 4px; font-size: 0.88rem; }
.speedtest-iframe-hint { margin-bottom: 10px; }
.speedtest-iframe-fallback { margin-top: 10px; font-size: 0.85rem; }
.speedtest-notes-card {
    margin-top: 20px; margin-bottom: 24px; padding: 20px 22px;
    background: linear-gradient(180deg, #fef3c7 0%, #fffbeb 100%);
    border: 3px solid #f59e0b; border-radius: 12px;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
}
.speedtest-notes-card h2 {
    margin: 0 0 14px; font-size: 1.15rem; color: #92400e;
}
.speedtest-notes-list {
    margin: 0; padding-left: 1.25rem; color: #78350f; font-size: 1rem; line-height: 1.55;
}
.speedtest-notes-list li { margin-bottom: 14px; }
.speedtest-notes-list li:last-child { margin-bottom: 0; }
.speedtest-notes-list strong { color: #451a03; }
@media (max-width: 520px) {
    .speedtest-big-row { grid-template-columns: 1fr; }
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.75em;
    display: inline-block;
}
.status-open { background: var(--badge-yellow-bg, #fef3c7); color: #92400e; }
.status-paid { background: #d1fae5; color: #047857; }

.login-shell { max-width: 100%; margin: 8px 0 0; }
.login-card { margin-top: 12px; }
.login-brand { text-align: center; margin-bottom: 12px; }
.login-brand img { max-width: 180px; height: auto; }
.login-brand h1 { margin: 8px 0 0; font-size: 1.2em; color: var(--primary); }
