:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --danger: #e74c3c;
    --success: #27ae60;
    --warning: #f39c12;
    --bg: #f5f6fa;
    --card: #ffffff;
    --border: #e0e0e0;
    --text: #2c3e50;
    --muted: #7f8c8d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* NAV */
nav {
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-brand { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.5px; }
.nav-links { list-style: none; display: flex; gap: 0.5rem; }
.nav-links a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.4em 0.9em;
    border-radius: 4px;
    transition: background 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.15); color: white; }

/* MAIN */
main { max-width: 1000px; margin: 2rem auto; padding: 0 1.5rem; }

/* PAGE HEADER */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.page-header h1 { font-size: 1.6rem; color: var(--primary); }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* BUTTONS */
.btn {
    display: inline-block;
    padding: 0.45em 1em;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg); border-color: #bbb; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: #2980b9; border-color: #2980b9; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 0.25em 0.7em; font-size: 0.8rem; }

/* TABLE */
table { width: 100%; border-collapse: collapse; background: white;
        border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.07); }
thead { background: var(--primary); color: white; }
th { padding: 0.75em 1em; text-align: left; font-weight: 600; font-size: 0.85rem; }
td { padding: 0.75em 1em; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tfoot td { background: #f8fafc; font-size: 0.9rem; }
.tva-mention { font-size: 0.8rem; color: var(--muted); font-style: italic; }

/* BADGES */
.badge {
    display: inline-block;
    padding: 0.2em 0.7em;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
}
.badge-emise { background: #dbeafe; color: #1e40af; }
.badge-payee { background: #dcfce7; color: #166534; }
.badge-annulee { background: #fee2e2; color: #991b1b; }
.badge-brouillon { background: #f3f4f6; color: #374151; }
.badge-envoye { background: #fef9c3; color: #854d0e; }
.badge-accepte { background: #dcfce7; color: #166534; }
.badge-refuse { background: #fee2e2; color: #991b1b; }

/* CARDS */
.form-card, .detail-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    margin-bottom: 1.5rem;
}
.form-card h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--primary);
                border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

/* FORM */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
input[type="text"], input[type="email"], input[type="date"], input[type="number"],
select, textarea {
    padding: 0.5em 0.75em;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
    background: white;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}
textarea { resize: vertical; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* TABLE LIGNES (formulaire) */
#table-lignes { margin-bottom: 1rem; }
#table-lignes thead { background: #f1f5f9; }
#table-lignes th { color: var(--primary); }
#table-lignes .ligne-desc { width: 100%; min-width: 200px; }
#table-lignes .ligne-qte { width: 70px; }
#table-lignes .ligne-pu { width: 110px; }
.ligne-total { text-align: right; font-weight: 500; }

.total-bloc {
    text-align: right;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 5px;
    margin: 1rem 0;
    font-size: 1rem;
}
.total-bloc small { color: var(--muted); font-style: italic; }

/* DETAIL */
.detail-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.detail-meta label { font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
                     color: var(--muted); display: block; margin-bottom: 0.4rem; }

/* MISC */
.empty-state { color: var(--muted); padding: 2rem; text-align: center; background: white;
               border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.07); }
.empty-state a { color: var(--accent); }

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .detail-meta { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
}
