/* ============================================================
   QuoteCraft Maroc — Charte graphique
   Bleu #1E3A5F / Accent #2E6BA6 / Vert #3AA76D / Orange #E8A33D / Rouge #D64545
   ============================================================ */

:root {
    --bleu: #1E3A5F;
    --bleu-accent: #2E6BA6;
    --vert: #3AA76D;
    --orange: #E8A33D;
    --rouge: #D64545;

    --bg: #F7F9FB;
    --surface: #FFFFFF;
    --surface-2: #EEF2F6;
    --ink: #2D3436;
    --muted: #7A8288;
    --line: #E2E8EE;

    --bleu-soft: #E8EEF5;
    --vert-soft: #E6F6EE;
    --orange-soft: #FCF3E3;
    --rouge-soft: #FBEAEA;

    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 4px 16px rgba(30, 58, 95, 0.07);
    --font: "Inter", "Roboto", system-ui, sans-serif;
    --display: "Poppins", "Montserrat", system-ui, sans-serif;
    --sidebar: 240px;
}

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

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
    line-height: 1.5;
    font-size: 15px;
}

a { color: var(--bleu-accent); text-decoration: none; }
a:hover { color: var(--bleu); text-decoration: underline; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar) 1fr;
    min-height: 100vh;
}

/* ——— Sidebar ——— */
.sidebar {
    background: var(--bleu);
    color: #F0F4F8;
    padding: 1.5rem 1.1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 2rem;
    padding: 0 0.4rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: var(--bleu-accent);
    display: grid;
    place-items: center;
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
}

.brand strong {
    display: block;
    font-family: var(--display);
    font-size: 1.05rem;
    font-weight: 600;
}
.brand small { color: #A8B8C8; font-size: 0.75rem; }

.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav a {
    color: #C5D0DC;
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.92rem;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}
.nav a.active {
    background: var(--bleu-accent);
    color: #fff;
}

/* ——— Main ——— */
.main-wrap { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.4rem 2rem 0.5rem;
}
.topbar h1 {
    font-family: var(--display);
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--bleu);
    letter-spacing: -0.02em;
}
.badge-devise {
    background: var(--bleu-soft);
    color: var(--bleu);
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.78rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
}

.content { padding: 1rem 2rem 2rem; flex: 1; }
.app-footer {
    padding: 1rem 2rem 1.5rem;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ——— Cards ——— */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}
.card h2 {
    font-family: var(--display);
    font-size: 1.05rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--bleu);
}
.card-intro { color: var(--muted); margin-bottom: 1.25rem; }
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.card-header-row h2 { margin-bottom: 0; }
.muted-card { background: var(--surface-2); }

/* ——— Forms ——— */
.form-stack { display: flex; flex-direction: column; gap: 0.25rem; }
.form-grid-2, .form-grid-3, .form-grid-4 {
    display: grid;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); align-items: end; }
.layout-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.field { margin-bottom: 1rem; }
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.35rem;
}
.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.35rem;
}
.field-label-row label { margin-bottom: 0; }
.field-label-row .btn { font-weight: 500; font-size: 0.75rem; padding: 0.25rem 0.55rem; }
.req { color: var(--rouge); }
.field input, .field textarea, .field select,
.items-table input {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.8rem;
    font: inherit;
    color: var(--ink);
}
.field input:focus, .field textarea:focus, .field select:focus,
.items-table input:focus {
    outline: 2px solid rgba(46, 107, 166, 0.25);
    border-color: var(--bleu-accent);
}
.field input.readonly { background: var(--surface-2); color: var(--muted); }
.hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem; }
.field-narrow { max-width: 180px; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.5rem;
}
.filters-actions { grid-column: 1 / -1; }

/* ——— Buttons ——— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover {
    text-decoration: none;
    border-color: var(--bleu-accent);
    color: var(--bleu-accent);
}
.btn-primary {
    background: var(--bleu);
    border-color: var(--bleu);
    color: #fff;
}
.btn-primary:hover {
    background: var(--bleu-accent);
    border-color: var(--bleu-accent);
    color: #fff;
}
.btn-secondary {
    background: var(--bleu-soft);
    border-color: transparent;
    color: var(--bleu);
}
.btn-secondary:hover {
    background: #d5e0ed;
    color: var(--bleu);
    border-color: transparent;
}
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--bleu); border-color: var(--bleu-accent); }
.btn-danger { color: var(--rouge); }
.btn-danger:hover {
    background: var(--rouge-soft);
    border-color: var(--rouge);
    color: var(--rouge);
}
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.4rem; font-size: 1rem; }

/* ——— Alerts ——— */
.alert {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    border: 1px solid transparent;
    font-size: 0.92rem;
}
.alert-success { background: var(--vert-soft); color: #2a7a50; border-color: #c5ebd6; }
.alert-error { background: var(--rouge-soft); color: var(--rouge); border-color: #f0c4c4; }
.alert-warning { background: var(--orange-soft); color: #9a6b1a; border-color: #f5dfb5; }
.error-list { margin-left: 1.1rem; }

/* ——— Tables ——— */
.table-wrap { overflow-x: auto; }
.data-table, .items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.data-table th, .items-table th {
    text-align: left;
    font-family: var(--display);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--line);
}
.data-table td, .items-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.empty { color: var(--muted); padding: 1rem 0; }
.hidden { display: none !important; }

/* ——— Stats dashboard ——— */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card.accent {
    background: var(--bleu);
    border-color: var(--bleu);
    color: #fff;
}
.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
.stat-card.accent .stat-label { color: #A8C0D8; }
.stat-value {
    font-family: var(--display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--bleu);
}
.stat-card.accent .stat-value { color: #fff; }

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

/* ——— Client mode ——— */
.client-mode-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.radio-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}
.radio-pill:has(input:checked) {
    background: var(--bleu-soft);
    border-color: var(--bleu-accent);
    color: var(--bleu);
}

/* ——— Summary ——— */
.summary-card .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.summary-card .summary-row.total {
    border-bottom: none;
    margin-top: 0.35rem;
    font-size: 1.1rem;
    color: var(--vert);
    font-family: var(--display);
}

.logo-current {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}
.logo-current img {
    max-height: 48px;
    max-width: 120px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px;
    background: #fff;
}

/* ——— Status badges ——— */
.status {
    display: inline-block;
    padding: 0.22rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.status-brouillon {
    background: #E8ECF0;
    color: var(--muted);
}
.status-envoyé {
    background: var(--orange-soft);
    color: #9a6b1a;
}
.status-accepté {
    background: var(--vert-soft);
    color: var(--vert);
}
.status-refusé {
    background: var(--rouge-soft);
    color: var(--rouge);
}

.status-select {
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
}
.inline-statut { display: inline; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.notes-block {
    background: var(--surface-2);
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
}

.btn-delete-row {
    background: transparent;
    border: none;
    color: var(--rouge);
    cursor: pointer;
    font-size: 1.15rem;
    padding: 0.35rem;
    line-height: 1;
}
.btn-delete-row:hover { opacity: 0.75; }

.amount-positive, .line-total-cell .line-total {
    color: var(--vert);
    font-weight: 600;
}

/* Login / public */
.login-page, .public-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--bg);
}
.login-card { width: 100%; max-width: 420px; margin: 0; }
.login-brand { margin-bottom: 1.5rem; color: var(--ink); }
.login-brand .brand-mark { color: #fff; }
.login-brand small { color: var(--muted); }
.public-wrap { width: 100%; max-width: 900px; }
.public-title { font-family: var(--display); color: var(--bleu); font-size: 1.5rem; margin-bottom: 0.35rem; }

.sidebar-user {
    margin-top: auto;
    padding: 1rem 0.85rem 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.8rem;
    color: #A8B8C8;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.sidebar-user a { color: #fff; font-weight: 600; }
.sidebar { display: flex; flex-direction: column; }

.pdf-preview-frame {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #e8ecef;
    min-height: 70vh;
}
.pdf-preview-frame iframe {
    width: 100%;
    height: 75vh;
    border: 0;
    display: block;
}

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        height: auto;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 1rem;
    }
    .brand { margin-bottom: 0; }
    .nav { flex-direction: row; flex-wrap: wrap; width: 100%; }
    .sidebar-user { width: 100%; border-top: none; padding-top: 0; flex-direction: row; justify-content: space-between; }
    .stats-grid, .form-grid-2, .form-grid-3, .form-grid-4, .layout-2col, .detail-grid {
        grid-template-columns: 1fr;
    }
    .content, .topbar, .app-footer { padding-left: 1rem; padding-right: 1rem; }
    .actions { flex-direction: column; align-items: stretch; }
    .pdf-preview-frame iframe { height: 55vh; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
}
