:root {
    --blue: #1f3864;
    --blue-light: #2e75b6;
    --bg: #f4f6f8;
    --border: #dde3e8;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: #1c1c1c;
}
.topbar {
    background: var(--blue);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.2rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.topbar-brand { font-weight: 700; letter-spacing: 0.03em; }
.topbar-nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar-nav a { color: #fff; text-decoration: none; opacity: 0.9; }
.topbar-nav a:hover { opacity: 1; text-decoration: underline; }
.topbar-user { opacity: 0.85; font-size: 0.9rem; }

.topbar-nav a.active { text-decoration: underline; font-weight: 600; opacity: 1; }

.content { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1 { color: var(--blue); font-size: 1.5rem; }
h2 { color: var(--blue-light); font-size: 1.1rem; }

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8rem;
}
.form-grid label.full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; font-size: 0.85rem; color: #444; gap: 0.25rem; }
input, select, textarea, button {
    font: inherit;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}
button {
    background: var(--blue-light);
    color: #fff;
    border: none;
    cursor: pointer;
    padding: 0.6rem 1rem;
    grid-column: 1 / -1;
    justify-self: start;
}
button:hover { background: var(--blue); }

.table { width: 100%; border-collapse: collapse; min-width: 700px; }
.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.table th { color: #fff; background: var(--blue-light); }
.actions-cell { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.inline-form select { min-width: 120px; }

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--blue);
}
.login-box {
    background: #fff;
    padding: 2rem;
    border-radius: 10px;
    width: 100%;
    max-width: 340px;
}
.login-box h1 { margin: 0 0 0.2rem; }
.login-sub { color: #666; margin-top: 0; margin-bottom: 1.2rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.8rem; }
.login-box button { width: 100%; }
.error { color: #b00000; }
.success { color: #1f7a1f; font-weight: 600; }

.btn-secondary {
    background: #fff;
    color: var(--blue-light);
    border: 1px solid var(--blue-light);
}
.btn-secondary:hover { background: #eef3f8; }
a.btn-secondary {
    display: inline-block;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
}

.signature-pad {
    display: block;
    width: 100%;
    max-width: 600px;
    height: 180px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: #fff;
    touch-action: none;
}
.signature-actions { margin-top: 0.4rem; }
.signature-actions button { grid-column: auto; }

/* --- Dashboard --- */
.muted { color: #777; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}
.stat-tile {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.stat-number { font-size: 1.8rem; font-weight: 700; color: var(--blue); }
.stat-label { font-size: 0.85rem; color: #666; }

.stat-row-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .stat-row-4 { grid-template-columns: repeat(4, 1fr); } }

.status-breakdown { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.status-chip {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: #eef1f4;
    color: #444;
}
.status-chip.status-a_facturer, .status-chip.status-facture { background: #e6f4ea; color: #1f7a1f; }
.status-chip.status-en_cours { background: #fff4d9; color: #8a6400; }

.intervention-list { display: flex; flex-direction: column; gap: 0.6rem; }
.intervention-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 0.8rem;
}
.intervention-time {
    font-weight: 700;
    color: var(--blue);
    white-space: nowrap;
    font-size: 0.9rem;
}
.intervention-main { flex: 1; min-width: 0; }
.intervention-client { font-weight: 600; }
.intervention-address, .intervention-employee { font-size: 0.85rem; color: #666; }
.intervention-status {
    font-size: 0.78rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: #eef1f4;
    color: #444;
    white-space: nowrap;
}
.intervention-status.status-a_facturer, .intervention-status.status-facture { background: #e6f4ea; color: #1f7a1f; }
.intervention-status.status-en_cours { background: #fff4d9; color: #8a6400; }
.intervention-cerfa-link {
    font-size: 0.8rem;
    color: var(--blue-light);
    text-decoration: none;
    border: 1px solid var(--blue-light);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    white-space: nowrap;
}
.intervention-cerfa-link:hover { background: #eef3f8; }
.intervention-links { display: flex; flex-direction: column; gap: 0.3rem; }
.actions-row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-top: 0.8rem; }
.actions-row form { margin: 0; }
.actions-row button { padding: 0.6rem 1rem; }

.btn-block {
    display: block;
    text-align: center;
    background: var(--blue-light);
    color: #fff;
    text-decoration: none;
    padding: 0.85rem 1rem;
    border-radius: 8px;
    font-weight: 600;
}
.btn-block:hover { background: var(--blue); }

/* --- Bottom nav (mobile) --- */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    z-index: 10;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.bottom-nav a {
    flex: 0 0 auto;
    min-width: 4.5rem;
    text-align: center;
    padding: 0.7rem 0.5rem;
    color: var(--blue);
    text-decoration: none;
    font-size: 0.72rem;
    white-space: nowrap;
}
.bottom-nav a.active { font-weight: 700; background: #eef3f8; }

/* --- Mobile breakpoint --- */
@media (max-width: 640px) {
    .topbar-nav a { display: none; }
    .topbar-user { font-size: 0.85rem; }
    .content { padding-bottom: 4.5rem; }

    .bottom-nav { display: flex; }

    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table { min-width: 0; }
    .table tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 0.8rem;
        padding: 0.4rem 0.6rem;
    }
    .table td {
        border-bottom: none;
        padding: 0.35rem 0;
        display: flex;
        justify-content: space-between;
        gap: 0.6rem;
        text-align: right;
    }
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
        text-align: left;
    }
    .table td.actions-cell { display: block; }
    .table td.actions-cell::before { display: block; margin-bottom: 0.3rem; }
    .actions-cell { flex-direction: column; align-items: stretch; }

    .intervention-item { flex-wrap: wrap; }
    .intervention-main { flex-basis: 100%; order: 1; }
    .intervention-time { order: 0; }
    .intervention-status { order: 2; }
    .intervention-links { order: 3; flex-direction: row; margin-left: auto; }
}
