:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8f0;
    --text: #1a2233;
    --text-soft: #5b6678;
    --text-muted: #8b95a7;
    --primary: #2f6df6;
    --primary-dark: #1f57d6;
    --success: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --radius: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px; line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-muted); font-size: 13px; }
.hidden { display: none !important; }
.hint { color: var(--text-soft); font-size: 13px; margin: 0 0 12px; }
.hint code, code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* ===== Topbar ============================================================ */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-center {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: 6px; margin-bottom: 22px;
}
.logo {
    height: 42px;
    width: auto;
    display: block;
    flex-shrink: 0;
    background: transparent;
}
.logo-big { height: 96px; width: auto; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
.brand-center h1 { font-size: 22px; }
.subtitle { margin: 0; color: var(--text-muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 18px; }

.btn-link {
    background: transparent; border: 0;
    color: var(--text-soft); font-size: 13px; font-weight: 500;
    cursor: pointer; padding: 6px 10px; border-radius: 8px;
    text-decoration: none;
}
.btn-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ===== Tabs ============================================================== */
.tabs {
    display: flex; gap: 4px; padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.tab {
    background: transparent; border: 0;
    padding: 14px 18px;
    font-size: 14px; font-weight: 500;
    color: var(--text-soft); cursor: pointer;
    border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 22px; }

/* ===== Layout ============================================================ */
.container {
    max-width: 1240px; margin: 24px auto; padding: 0 20px;
    display: grid; gap: 22px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.actions-inline {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

/* ===== Forms / Inputs ==================================================== */
input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input[type="datetime-local"],
input[type="number"], input[type="search"], input[type="tel"],
input[type="url"], select, textarea {
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 14px;
    color: var(--text);
    font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}
.checkbox {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 14px; color: var(--text-soft); cursor: pointer;
}
.checkbox input { width: 18px; height: 18px; }

/* ===== Buttons =========================================================== */
.btn {
    border: 0; border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: transform .05s, background .15s, box-shadow .15s;
    color: white; display: inline-block; text-align: center;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); text-decoration: none; color: white; }
.btn-success { background: var(--success); }
.btn-danger  { background: var(--danger); }
.btn-secondary { background: var(--text-soft); }
.btn-block { width: 100%; }

.btn-mini {
    background: var(--surface-2);
    color: var(--text-soft);
    border: 1px solid var(--border);
    padding: 6px 12px; border-radius: 7px;
    font-size: 13px; cursor: pointer; font-weight: 500;
    text-decoration: none;
}
.btn-mini:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.btn-mini-danger { color: var(--danger); }
.btn-mini-danger:hover { background: #fef2f2; border-color: #fecaca; }

.icon-btn {
    background: transparent; border: 0;
    color: var(--text-soft);
    font-size: 22px; cursor: pointer;
    padding: 6px 10px; border-radius: 8px;
    text-decoration: none; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

/* ===== Stats grid ======================================================== */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
}
.stat { padding: 18px; }
.stat-label {
    color: var(--text-muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: .5px;
}
.stat-value {
    font-size: 28px; font-weight: 700; margin-top: 6px;
    font-variant-numeric: tabular-nums;
}
.stat-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ===== Tables ============================================================ */
.table-wrap { overflow-x: auto; }
table.entries { width: 100%; border-collapse: collapse; font-size: 14px; }
table.entries th, table.entries td {
    text-align: left; padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.entries th {
    color: var(--text-muted); font-weight: 500; font-size: 12px;
    text-transform: uppercase; letter-spacing: .5px;
    background: var(--surface-2);
}
/* Spécifique à l'onglet Interventions : couleurs d'en-tête inversées
   (fond foncé, texte clair). */
#tab-interventions table.entries th {
    color: var(--surface-2);
    background: var(--text-muted);
}
table.entries tbody tr:hover { background: var(--surface-2); }
table.entries tbody tr.month-break:hover td { background: var(--primary-dark); }

table.entries tbody tr.month-break td {
    background: var(--primary-dark);
    color: #eff6ff;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 14px 12px 6px;
    border-top: 1px solid var(--border);
    border-bottom: 0;
}
table.entries tbody tr.month-break:first-child td { border-top: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty {
    color: var(--text-muted); text-align: center;
    padding: 28px 10px; font-style: italic;
}

/* Statut badges */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .4px;
}
.badge-a_realiser     { background: #e0e7ff; color: #3730a3; }
.badge-realisee       { background: #dcfce7; color: #166534; }
.badge-non_realisee   { background: #fee2e2; color: #991b1b; }
.badge-client_absent  { background: #fef3c7; color: #92400e; }
.badge-annulee        { background: #fee2e2; color: #991b1b; }
.badge-reportee       { background: #ede9fe; color: #5b21b6; }

/* Résultats des bons */
.badge-res-done_signature { background: #dcfce7; color: #166534; }
.badge-res-done_absent    { background: #fef3c7; color: #92400e; }
.badge-res-non_done       { background: #fee2e2; color: #991b1b; }

/* Barre de progression (avancement contrat) */
.progress {
    background: var(--surface-2);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
    min-width: 80px;
    max-width: 220px;
}
.progress-bar {
    height: 100%;
    transition: width .25s;
}
.progress-ok   { background: var(--success); }
.progress-pace { background: var(--primary); }
.progress-late { background: var(--warn); }

/* ===== Calendrier ======================================================== */
.calendar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.cal-week-col {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    min-height: 180px;
    display: flex;
    flex-direction: column;
}
.cal-week-head {
    padding: 10px 12px;
    background: #eff6ff;
    color: var(--primary-dark);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}
.cal-week-body {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}
.cal-week-empty {
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
    padding: 28px 0;
    font-size: 13px;
}
.cal-event {
    position: relative;
    background: var(--surface-2);
    color: var(--text);
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    padding: 8px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: filter 0.1s;
}
.cal-event-check {
    position: absolute;
    top: 6px;
    right: 8px;
    color: var(--success);
    font-weight: 800;
    font-size: 16px;
    line-height: 1;
}
.cal-event:hover { filter: brightness(0.95); }
.cal-event-date {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    margin-bottom: 2px;
}
.cal-event-client {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-event-meta {
    font-size: 11px;
    color: var(--text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Le fond porte la couleur du client ; le statut est rappelé par la
   couleur de la bordure gauche, pour ne pas perdre cette information. */
.cal-event.cal-realisee      { border-left-color: var(--success); }
.cal-event.cal-non_realisee  { border-left-color: var(--danger); }
.cal-event.cal-client_absent { border-left-color: var(--warn); }
.cal-event.cal-annulee, .cal-event.cal-reportee { border-left-color: var(--text-soft); }

/* ===== Modal ============================================================= */
.modal {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45);
    display: grid; place-items: center;
    z-index: 100; padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
    width: 100%; max-width: 580px;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
    overflow: hidden;
    max-height: 92vh;
    display: flex; flex-direction: column;
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 22px; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close {
    background: transparent; border: 0; font-size: 22px;
    color: var(--text-muted); cursor: pointer; line-height: 1;
}
.modal-body { padding: 18px 22px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid .form-actions {
    grid-column: 1 / -1;
    display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px;
}
.form-error {
    grid-column: 1 / -1; color: var(--danger);
    font-size: 13px; margin: 0; min-height: 18px; text-align: center;
}

/* ===== Login ============================================================= */
.login-bg {
    background:
        radial-gradient(circle at 20% 10%, rgba(47,109,246,.12), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(22,163,74,.10), transparent 40%),
        var(--bg);
    min-height: 100vh;
    display: grid; place-items: center; padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
}
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.login-help {
    margin: 20px 0 0; text-align: center;
    font-size: 12px; color: var(--text-muted); line-height: 1.7;
}

/* =========================================================================
   APPLICATION MOBILE
========================================================================== */
.mobile-app {
    background: var(--bg);
    min-height: 100vh;
    display: flex; flex-direction: column;
    padding-top: calc(56px + var(--safe-top));
    padding-bottom: calc(64px + var(--safe-bottom));
}
.mobile-topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
    background: white; border-bottom: 1px solid var(--border);
    padding: 8px 14px;
    padding-top: calc(8px + var(--safe-top));
    height: calc(56px + var(--safe-top));
    display: flex; align-items: center; justify-content: space-between;
}
.mobile-topbar-left {
    display: flex; align-items: center; gap: 8px;
}
.mobile-topbar h1 {
    margin: 0; font-size: 17px; font-weight: 600;
}
.mobile-tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: white; border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: var(--safe-bottom);
    height: calc(64px + var(--safe-bottom));
}
.mobile-tab {
    flex: 1; background: transparent; border: 0;
    font-size: 12px; color: var(--text-muted);
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    transition: color .15s;
}
.mobile-tab.active { color: var(--primary); font-weight: 600; }

#mobileView {
    flex: 1;
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
}

.m-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.m-date-sep {
    padding: 12px 4px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: capitalize;
    letter-spacing: 0.2px;
}
.m-date-sep:first-child { padding-top: 0; }

.m-int-semaine {
    color: var(--primary);
    font-weight: 500;
    margin-top: 2px;
}
.m-int-date {
    color: var(--text-soft);
    font-weight: 500;
    text-transform: capitalize;
    margin-top: 2px;
}
.m-int-notes {
    color: var(--text-soft);
    font-style: italic;
    margin-top: 2px;
    white-space: pre-wrap;
    word-break: break-word;
}

.m-search input[type="search"] {
    width: 100%;
    box-sizing: border-box;
    background: white;
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
}

.m-intervention {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform .1s, box-shadow .15s;
}
.m-intervention:active { transform: scale(.99); }
.m-int-heure {
    font-size: 22px; font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
    min-width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Icône « cleaner + raclette » qui marque la prochaine visite du client. */
.m-int-cleaner {
    width: 48px;
    height: 48px;
    color: var(--primary);
    opacity: 0.85;
}
.m-int-client {
    flex: 1;
}
.m-int-client strong { display: block; font-size: 15px; margin-bottom: 2px; }
.m-int-client small { color: var(--text-muted); display: block; }

.m-detail h2 { margin: 0 0 4px; font-size: 18px; }
.m-detail-section {
    background: white; border-radius: 12px;
    padding: 14px 16px; border: 1px solid var(--border);
}
.m-detail-section h3 {
    margin: 0 0 8px; font-size: 12px;
    text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); font-weight: 600;
}
.m-detail-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.m-detail-row span:first-child { color: var(--text-muted); }
.m-detail-row span:last-child  { font-weight: 500; text-align: right; }

.m-actions {
    display: grid; gap: 10px;
}
.m-actions .btn { padding: 14px 18px; font-size: 15px; }

.m-form {
    background: white; border-radius: 12px;
    padding: 16px; border: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 14px;
}
.m-form label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.m-form .checkbox {
    flex-direction: row; align-items: center;
    color: var(--text); font-size: 15px;
}

/* Groupe de boutons radio (3 résultats) */
.m-radio-group {
    border: 0; padding: 0; margin: 0;
    display: flex; flex-direction: column; gap: 8px;
}
.m-radio-group legend {
    font-size: 12px; color: var(--text-muted);
    font-weight: 500; padding: 0; margin-bottom: 4px;
}
.m-radio {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 14px; border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 10px; cursor: pointer;
}
.m-radio:has(input:checked) {
    border-color: var(--primary);
    background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(47, 109, 246, 0.12);
}
.m-radio input { margin-top: 2px; width: 18px; height: 18px; }
.m-radio span { display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: var(--text); }
.m-radio strong { font-weight: 600; }
.m-radio small { color: var(--text-muted); font-size: 12px; font-weight: normal; }

/* Carte de contrat (vue Mes contrats) */
.m-contrat-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 4px;
}

.signature-zone {
    border: 2px dashed var(--border);
    background: var(--surface-2);
    border-radius: 10px;
    height: 220px;
    touch-action: none;
    position: relative;
}
.signature-zone.has-sign { border-style: solid; border-color: var(--success); background: white; }
.signature-zone canvas {
    width: 100%; height: 100%;
    border-radius: 10px;
    display: block;
}
.signature-zone .sign-hint {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    color: var(--text-muted); font-size: 13px;
    pointer-events: none;
}
.signature-zone.has-sign .sign-hint { display: none; }
.signature-actions {
    display: flex; justify-content: flex-end; gap: 8px;
}

.geo-pill {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px; color: var(--text-soft);
}
.geo-pill.ok   { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.geo-pill.warn { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.geo-pill.fail { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

.toast {
    position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom));
    transform: translateX(-50%);
    background: var(--text); color: white;
    padding: 10px 18px; border-radius: 999px;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    z-index: 200; opacity: 0;
    transition: opacity .25s;
}
.toast.show { opacity: 1; }

/* ===== Responsive ======================================================== */
@media (max-width: 1024px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .topbar { padding: 12px 16px; }
    .container { padding: 0 14px; }
}
@media (max-width: 560px) {
    .summary-grid { grid-template-columns: 1fr; }
    .calendar { grid-template-columns: repeat(2, 1fr); }
    .cal-week-head { font-size: 11px; padding: 8px 6px; }
    .cal-event { font-size: 11px; padding: 6px 8px; }
}
