/* =========================================================
   XPRO RECETTES MOBILE - PLEIN ÉCRAN TOTAL (100% LARGEUR & HAUTEUR)
   TYPOGRAPHIE & DIMENSIONS DYNAMIQUES ADAPTÉES À L'ÉCRAN
   TABLEAU CLAIR, BIEN TRACÉ ET BORDURÉ
   ========================================================= */

:root {
    --bg-page: #f1f5f9;
    --bg-main: #ffffff;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-footer: #f8fafc;
    --bg-table-header: #e2e8f0;
    --bg-table-zebra: #f8fafc;
    --bg-net-highlight: #f0f9ff;

    --border-strong: #94a3b8;
    --border-color: #cbd5e1;
    --border-cell: #e2e8f0;

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --color-green: #047857;
    --color-red: #dc2626;
    --color-blue: #0284c7;
    --color-accent: #1e40af;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    height: 100%;
    height: 100dvh;
    width: 100%;
    width: 100vw;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-page);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* =========================================================
   CONTENEUR PLEIN ÉCRAN - OCCUPE 100% DE L'ÉCRAN DU SMARTPHONE
   ========================================================= */
.app-screen {
    width: 100%;
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-main);
    overflow: hidden;
    position: relative;
}

/* =========================================================
   1. EN-TÊTE SUPÉRIEUR (TOP BAR CLAIR DYNAMIQUE)
   ========================================================= */
.app-topbar {
    height: clamp(48px, 6.8vh, 58px);
    min-height: 46px;
    background: var(--bg-header);
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(6px, 1.2vh, 10px) clamp(12px, 3vw, 18px) 0 clamp(10px, 2.5vw, 16px);
    z-index: 10;
    flex-shrink: 0;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.brand-title {
    font-size: clamp(0.95rem, 3.4vw, 1.25rem);
    font-weight: 800;
    letter-spacing: -0.2px;
    color: #1e3a8a;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: clamp(4px, 1.5vw, 8px);
    flex-shrink: 0;
}

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 clamp(6px, 1.8vw, 12px);
    height: clamp(32px, 4.8vh, 38px);
    border-radius: 7px;
    border: 1.5px solid #2563eb;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
    font-size: clamp(0.74rem, 2.2vw, 0.88rem);
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.15);
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-refresh:active {
    transform: scale(0.94);
    background: #dbeafe;
}

.btn-refresh i {
    font-size: clamp(1rem, 2.6vw, 1.2rem);
    color: #2563eb;
    font-weight: 900;
}

.btn-refresh.refreshing i {
    animation: spin 0.8s linear infinite;
}

.btn-icon {
    width: clamp(32px, 5vh, 40px);
    height: clamp(32px, 5vh, 40px);
    border-radius: 7px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: clamp(1rem, 2.6vw, 1.25rem);
    transition: all 0.15s ease;
}

.btn-icon:active {
    transform: scale(0.92);
    background: #e2e8f0;
}

.btn-logout {
    color: #475569;
    border-color: #cbd5e1;
    background: #f8fafc;
    transition: all 0.15s ease;
}

.btn-logout:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

.btn-logout:active {
    background: #e2e8f0;
    transform: scale(0.92);
}

.btn-logout i {
    font-size: clamp(1rem, 2.6vw, 1.25rem);
}

.btn-exit {
    color: #dc2626;
    border-color: #fecaca;
    background: #fef2f2;
    transition: all 0.15s ease;
}

.btn-exit:hover {
    background: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}

.btn-exit:active {
    background: #fca5a5;
    transform: scale(0.92);
}

.btn-exit i {
    font-size: clamp(1.05rem, 2.7vw, 1.3rem);
    font-weight: 900;
}

.btn-icon.refreshing {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* =========================================================
   2. BARRE DE CONTRÔLES (DATE)
   ========================================================= */
.controls-bar {
    height: clamp(38px, 5.2vh, 48px);
    min-height: 38px;
    background: #f8fafc;
    border-bottom: 1.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 clamp(6px, 2vw, 16px);
    font-size: clamp(0.78rem, 2.4vw, 0.95rem);
    flex-shrink: 0;
}

.date-selector-wrap {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1.8vw, 12px);
    width: 100%;
}

.date-input {
    background: #ffffff;
    border: 1.5px solid var(--border-strong);
    color: var(--text-primary);
    font-size: clamp(0.78rem, 2.4vw, 0.96rem);
    font-weight: 700;
    padding: 2px clamp(6px, 1.5vw, 10px);
    border-radius: 5px;
    height: clamp(28px, 4vh, 36px);
    outline: none;
}

.btn-quick-date {
    height: clamp(28px, 4vh, 36px);
    padding: 0 clamp(8px, 2vw, 14px);
    font-size: clamp(0.74rem, 2.2vw, 0.92rem);
    font-weight: 700;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
}

.btn-quick-date.active {
    background: #1e40af;
    color: #ffffff;
    border-color: #1e40af;
}

/* =========================================================
   3. ZONE CENTRALE - TABLEAU BIEN TRACÉ ET BORDURÉ
   ========================================================= */
.zero-scroll-container {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: clamp(2px, 1vw, 6px);
    background: var(--bg-main);
}

/* Cadre complet du tableau occupant 100% de la largeur */
.table-compact {
    width: 100%;
    height: 100%;
    min-height: 0;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    font-variant-numeric: tabular-nums;
    border: 1.5px solid var(--border-strong);
    border-radius: 6px;
    overflow: hidden;
    background: #ffffff;
}

/* Ligne d'en-tête du tableau */
.th-row {
    height: clamp(28px, 4vh, 38px);
    min-height: 28px;
    display: grid;
    grid-template-columns: 1.45fr 1.05fr 0.85fr 1.15fr;
    align-items: center;
    background: var(--bg-table-header);
    border-bottom: 2px solid var(--border-strong);
    font-size: clamp(0.74rem, 2.4vw, 0.98rem);
    font-weight: 800;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

/* Cellules d'en-tête */
.th-row > div {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 clamp(6px, 1.8vw, 14px);
    border-right: 1px solid var(--border-strong);
    overflow: hidden;
    white-space: nowrap;
}

.th-row > div:not(:first-child) {
    justify-content: flex-end;
}

.th-row > div:last-child {
    border-right: none;
    background: #e0f2fe;
    color: #0369a1;
}

/* Liste des lignes de données avec SCROLL VERTICAL FLUIDE */
.tb-list {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

/* Scrollbar discrète */
.tb-list::-webkit-scrollbar {
    width: 5px;
}
.tb-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}
.tb-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Ligne de site dynamique étirée occupant tout l'espace disponible (Option A) */
.tb-row {
    flex: 1 0 0;
    min-height: clamp(34px, 4.4vh, 48px);
    display: grid;
    grid-template-columns: 1.45fr 1.05fr 0.85fr 1.15fr;
    align-items: center;
    border-bottom: 1px solid var(--border-cell);
    font-size: clamp(0.78rem, 2.6vw, 1.08rem);
    background: #ffffff;
    transition: background 0.1s ease;
    width: 100%;
}

.tb-row:nth-child(even) {
    background: var(--bg-table-zebra);
}

.tb-row:active {
    background: #dbeafe !important;
}

.tb-row.empty-site {
    opacity: 0.55;
    background: #fafafa;
}

/* Cellules de données avec bordures verticales */
.tb-row > div {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 clamp(6px, 1.8vw, 14px);
    border-right: 1px solid var(--border-cell);
    overflow: hidden;
    white-space: nowrap;
}

.tb-row > div:not(:first-child) {
    justify-content: flex-end;
}

.tb-row > div:last-child {
    border-right: none;
}

/* Colonne Site sans numéro, dynamique et lisible */
.site-name {
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Valeurs chiffrées contrastées */
.val-brut {
    color: var(--color-green);
    font-weight: 700;
}

.val-dep {
    color: var(--color-red);
    font-weight: 600;
}

.val-net {
    color: #0369a1;
    font-weight: 800;
    background: var(--bg-net-highlight);
}

/* =========================================================
   MODE TUILES 2 COLONNES (CLAIRE & BORDURÉE)
   ========================================================= */
.tiles-grid {
    width: 100%;
    height: 100%;
    min-height: 0;
    flex: 1 1 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: minmax(clamp(46px, 6.5vh, 68px), 1fr);
    gap: clamp(4px, 1.2vw, 8px);
}

.tile-card {
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    padding: clamp(4px, 1.2vh, 8px) clamp(6px, 1.8vw, 12px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.tile-card.empty-site {
    opacity: 0.5;
    background: #f8fafc;
    border-color: #e2e8f0;
}

.tile-card.summary-tile {
    background: #f0fdf4;
    border-color: #86efac;
}

.tile-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.tile-title {
    font-size: clamp(0.78rem, 2.5vw, 1.1rem);
    font-weight: 700;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.tile-net {
    font-size: clamp(0.88rem, 2.8vw, 1.25rem);
    font-weight: 800;
    color: #0369a1;
    font-variant-numeric: tabular-nums;
}

.tile-bottom {
    display: flex;
    justify-content: space-between;
    font-size: clamp(0.70rem, 2.2vw, 0.95rem);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}

/* =========================================================
   4. BANDEAU DES TOTAUX (FOOTER FIXE COMPACT & RESPONSIVE FIGÉ EN BAS)
   ========================================================= */
.totals-bar-compact {
    width: 100%;
    height: clamp(50px, 7vh, 62px);
    min-height: 48px;
    background: #ffffff;
    border-top: 2.5px solid #0284c7;
    display: grid;
    grid-template-columns: 1.15fr 1.25fr 0.95fr 1.4fr;
    align-items: center;
    z-index: 20;
    box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    padding: 0 clamp(6px, 1.8vw, 12px) clamp(4px, 1vh, 8px) clamp(6px, 1.8vw, 12px);
    font-variant-numeric: tabular-nums;
}

.tot-item {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 clamp(3px, 1vw, 8px);
    border-right: 1px solid var(--border-cell);
    overflow: visible;
}

.tot-item:last-child {
    border-right: none;
    background: #f0f9ff;
}

.tot-site {
    align-items: flex-start;
}

.tot-badge {
    font-size: clamp(0.70rem, 2.2vw, 0.88rem);
    font-weight: 900;
    color: #1e3a8a;
    letter-spacing: 0.3px;
    line-height: 1.1;
}

.tot-sub {
    font-size: clamp(0.56rem, 1.7vw, 0.74rem);
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.1;
    margin-top: 2px;
}

.tot-brut, .tot-dep, .tot-net {
    align-items: flex-end;
}

.tot-label {
    font-size: clamp(0.50rem, 1.5vw, 0.68rem);
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    line-height: 1;
    margin-bottom: 2px;
}

.tot-value {
    font-size: clamp(0.72rem, 2.3vw, 1.05rem);
    font-weight: 800;
    line-height: 1.1;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.tot-value.text-green { color: var(--color-green); }
.tot-value.text-red { color: var(--color-red); }
.tot-value.text-net { color: #0369a1; font-weight: 900; }
.tot-unit { font-size: clamp(0.58rem, 1.8vw, 0.78rem); font-weight: 700; color: #0284c7; }

.tot-pill-value.green { color: var(--color-green); }
.tot-pill-value.red { color: var(--color-red); }
.tot-pill-value.gold { color: #1e40af; font-size: clamp(0.98rem, 3.4vw, 1.55rem); font-weight: 900; }

/* =========================================================
   5. ÉCRAN DE LOGIN (PLEIN ÉCRAN CLAIR & PROFESSIONNEL)
   ========================================================= */
.login-screen {
    width: 100%;
    max-width: 460px;
    margin: auto;
    padding: clamp(16px, 4vw, 32px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    background: var(--bg-page);
}

.login-card-glass {
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: clamp(20px, 4.5vw, 32px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

.login-header {
    text-align: center;
    margin-bottom: clamp(16px, 3vh, 24px);
}

.login-icon {
    width: clamp(48px, 8vh, 60px);
    height: clamp(48px, 8vh, 60px);
    margin: 0 auto clamp(8px, 1.5vh, 14px);
    background: linear-gradient(135deg, #1e40af, #0284c7);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}

.login-header h2 {
    font-size: clamp(1.2rem, 3.8vw, 1.6rem);
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 4px;
}

.login-header p {
    font-size: clamp(0.80rem, 2.4vw, 1rem);
    color: var(--text-muted);
}

.form-group {
    margin-bottom: clamp(12px, 2vh, 18px);
}

.form-label {
    display: block;
    font-size: clamp(0.76rem, 2.4vw, 0.95rem);
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.form-control-dark {
    width: 100%;
    height: clamp(40px, 5.5vh, 48px);
    padding: 0 12px;
    background: #ffffff;
    border: 1.5px solid var(--border-strong);
    border-radius: 7px;
    color: var(--text-primary);
    font-size: clamp(0.90rem, 2.8vw, 1.1rem);
    font-weight: 500;
    outline: none;
    transition: border 0.15s ease, box-shadow 0.15s ease;
}

.form-control-dark:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-primary-gradient {
    width: 100%;
    height: clamp(42px, 6vh, 50px);
    background: linear-gradient(135deg, #1e40af, #0284c7);
    border: none;
    border-radius: 7px;
    color: #ffffff;
    font-size: clamp(0.92rem, 2.8vw, 1.15rem);
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
    transition: all 0.15s ease;
}

.btn-primary-gradient:active {
    transform: scale(0.98);
}

.btn-primary-gradient:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.login-error-alert {
    background: #fef2f2;
    border: 1px solid #f87171;
    color: #991b1b;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: clamp(0.78rem, 2.4vw, 0.95rem);
    font-weight: 600;
    margin-bottom: 14px;
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.80rem, 2.5vw, 1rem);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.checkbox-dark {
    width: clamp(17px, 2.5vw, 22px);
    height: clamp(17px, 2.5vw, 22px);
    accent-color: #1e40af;
    cursor: pointer;
}
