@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --bg: #F5F3EE;
    --surface: #FFFFFF;
    --ink: #16223E;
    --ink-soft: #5B6478;
    --line: #E6E2D8;
    --accent: #F2A93B;
    --accent-deep: #C97F0E;
    --success: #2F9E67;
    --success-bg: #E4F5EC;
    --danger: #E14F4F;
    --danger-bg: #FCE9E8;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ---- En-tete "ticket de tournee" avec bord perfore ---- */
header {
    background: var(--ink);
    color: #fff;
    padding: 20px 18px 26px;
    position: sticky;
    top: 0;
    z-index: 10;
    -webkit-mask-image: radial-gradient(circle 5px at 12px 100%, transparent 5px, black 5.5px);
    mask-image: radial-gradient(circle 5px at 12px 100%, transparent 5px, black 5.5px);
    -webkit-mask-repeat: repeat-x;
    mask-repeat: repeat-x;
    -webkit-mask-position: bottom;
    mask-position: bottom;
    -webkit-mask-size: 24px 12px;
    mask-size: 24px 12px;
}
header .eyebrow {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 4px;
}
header h1 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 22px;
    letter-spacing: -0.01em;
}
header a.back { color: rgba(255,255,255,0.75); text-decoration: none; font-size: 14px; }

main { padding: 16px; max-width: 640px; margin: 0 auto; padding-bottom: 90px; }

/* ---- Cartes ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.card a { text-decoration: none; color: inherit; display: block; }
.card h2 {
    margin: 0 0 4px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 17px;
}
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.section-title {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    margin: 24px 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::after {
    content: "";
    flex: 1;
    border-bottom: 1px dashed var(--line);
}

/* ---- Boutons ---- */
.btn {
    display: inline-block;
    background: var(--ink);
    color: #fff;
    border: none;
    padding: 15px 20px;
    border-radius: var(--radius);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    width: 100%;
    cursor: pointer;
    letter-spacing: -0.01em;
}
.btn:active { background: #0e1730; }
.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn-accent { background: var(--accent-deep); }
.btn-danger { background: var(--danger); }

/* ---- Tableau de saisie ---- */
table.saisie { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
table.saisie th {
    padding: 6px 4px;
    text-align: left;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
}
table.saisie td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: left; font-size: 15px; vertical-align: middle; }
table.saisie tr:last-child td { border-bottom: none; }
table.saisie input[type=number] {
    width: 60px;
    padding: 9px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 16px;
    font-weight: 600;
    border: 1.5px solid var(--line);
    border-radius: 8px;
    text-align: center;
    background: var(--bg);
    color: var(--ink);
}
table.saisie input[type=number]:focus { border-color: var(--accent-deep); outline: none; background: #fff; }

/* ---- Jauge de stock ---- */
.gauge-cell { min-width: 90px; }
.gauge-track {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 5px;
}
.gauge-fill {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
    transition: width 0.15s ease, background 0.15s ease;
}
.gauge-fill.niveau-bas { background: var(--danger); }
.gauge-fill.niveau-moyen { background: var(--accent); }

/* ---- Badges & alertes ---- */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    background: var(--bg);
    color: var(--ink-soft);
    border: 1px solid var(--line);
}
.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-accent { background: #FDF1DC; color: var(--accent-deep); border-color: transparent; }

.alerte {
    background: var(--danger-bg);
    color: #9A2F2F;
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 14px;
    border: 1px solid #F3CFCE;
}

/* ---- Resume chiffre (stock a prevoir) ---- */
.chiffre {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
}
.total-row td:last-child { text-align: right; font-size: 17px; }

/* ---- Champs de formulaire generiques ---- */
input[type=text], input[type=date], input[type=number], select {
    width: 100%;
    padding: 12px;
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    border-radius: 8px;
    border: 1.5px solid var(--line);
    margin: 6px 0;
    background: var(--surface);
    color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--accent-deep); }
label { font-size: 13px; color: var(--ink-soft); font-weight: 500; }

details summary {
    color: var(--accent-deep);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "+ "; }
details[open] summary::before { content: "\2013 "; }

/* ---- Ligne de produit modifiable (fiche client) ---- */
details.produit-row {
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
}
details.produit-row:last-of-type { border-bottom: none; }
details.produit-row summary.produit-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
}
details.produit-row summary.produit-summary::before { content: "✏️ "; font-size: 12px; }

/* ---- En-tête de machine modifiable (fiche client) ---- */
details.machine-header summary.machine-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 17px;
    color: var(--ink);
}
