/* ── Variables ─────────────────────────────────────────── */
:root {
    --accent:       #312783;
    --accent-light: #e8e6f5;
    --danger:       #E30613;
    --bg:           #F2F2F7;
    --bg-card:      #FFFFFF;
    --bg-input:     #F2F2F7;
    --border:       #E5E5EA;
    --text-primary: #1D1D1B;
    --text-secondary:#8E8E93;
    --text-tertiary:#C7C7CC;
    --radius-sm:    8px;
    --radius-md:    12px;
    --radius-lg:    20px;
}

[data-theme="dark"] {
    --bg:           #1C1C1E;
    --bg-card:      #2C2C2E;
    --bg-input:     #3A3A3C;
    --border:       #48484A;
    --text-primary: #FFFFFF;
    --text-secondary:#8E8E93;
    --text-tertiary:#48484A;
    --accent:       #6C63FF;
    --accent-light: #2D2A5E;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

/* ── Screens ────────────────────────────────────────────── */
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.screen.hidden { display: none; }
.screen.active { display: flex; }

/* ── Login ──────────────────────────────────────────────── */
.login-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px 24px;
    max-width: 420px;
    margin: 0 auto;
    width: 100%;
}
.login-logo { text-align: center; margin-bottom: 40px; }
.logo-square {
    width: 64px; height: 64px;
    background: var(--accent);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 22px; font-weight: 700;
    margin: 0 auto 12px;
}
.logo-name { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.logo-sub  { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

.login-form h1 { font-size: 28px; font-weight: 600; margin-bottom: 4px; }
.login-form .sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 28px; }

/* ── Field group ────────────────────────────────────────── */
.field-group { margin-bottom: 14px; }
.field-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;

}
.field-group input,
.field-group textarea,
.field-group select {
    width: 100%;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
    transition: box-shadow 0.2s;
    -webkit-appearance: none;
}
.field-group input:focus,
.field-group textarea:focus {
    box-shadow: 0 0 0 2px var(--accent);
}
.field-group textarea { resize: vertical; min-height: 70px; }

.row-2 { display: flex; gap: 10px; }
.row-2 .field-group { flex: 1; }

/* ── Pills ──────────────────────────────────────────────── */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pills-col { flex-direction: column; }
.pill {
    background: var(--bg-input);
    color: var(--text-primary);
    border-radius: 20px;
    padding: 7px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;

    border: 1.5px solid var(--border);
}
.pill:hover { border-color: var(--accent); }
.pill.active {
    background: var(--accent);
    color: #fff;
    font-weight: 500;
}

/* ── Checks ─────────────────────────────────────────────── */
.checks { display: flex; gap: 8px; flex-wrap: wrap; }
.check-item {
    background: var(--bg-input);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    border: 1.5px solid transparent;
}
.check-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
    border-color: var(--accent);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
    font-family: inherit;
    margin-top: 6px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { opacity: 0.8; }

.btn-secondary {
    flex: 1;
    background: var(--bg-input);
    color: var(--accent);
    border: 1.5px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.btn-clear {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 13px;
    cursor: pointer;
    margin-top: 6px;
    padding: 0;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
    background: var(--bg-card);
    border-bottom: 0.5px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.btn-back, .btn-icon {
    background: none;
    border: none;
    font-size: 13px;
    color: var(--accent);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    font-weight: 500;
}
.topbar-info { flex: 1; }
.topbar-title { font-size: 14px; font-weight: 500; }
.topbar-sub   { font-size: 12px; color: var(--text-secondary); }

/* ── Progress ───────────────────────────────────────────── */
.progress-wrap { padding: 8px 16px 0; background: var(--bg-card); }
.progress-bar  {
    height: 2px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}
.step-dots {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 8px 0 6px;
}
.step-dot {
    height: 4px;
    border-radius: 4px;
    background: var(--border);
    transition: all 0.3s;
    width: 4px;
}
.step-dot.active { width: 18px; background: var(--accent); }
.step-dot.done   { background: var(--accent); opacity: 0.35; }

/* ── Fiche meta ─────────────────────────────────────────── */
.fiche-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 0.5px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}
.fiche-meta span:first-child { font-weight: 500; color: #7B74C5; }
.autosave { font-size: 11px; }

/* ── Steps ──────────────────────────────────────────────── */
.steps-container { flex: 1; overflow-y: auto; padding: 16px; }
.step.hidden { display: none; }
.section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 14px;
}



/* ── Nav buttons ────────────────────────────────────────── */
.nav-buttons {
    display: flex;
    gap: 10px;
    padding: 12px 16px 24px;
    background: var(--bg-card);
    border-top: 0.5px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* ── Signature canvas ───────────────────────────────────── */
#signature-canvas {
    width: 100%;
    max-width: 100%;
    height: 120px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    display: block;
    cursor: crosshair;
    touch-action: none;
}

/* ── Recap ──────────────────────────────────────────────── */
.recap-row {
    display: flex;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 0.5px solid var(--border);
    font-size: 14px;
}
.recap-row .k { color: var(--text-secondary); }
.recap-row .v { font-weight: 500; color: var(--text-primary); }

.info-box {
    background: var(--accent-light);
    color: var(--accent);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    margin-top: 14px;
}

/* ── Confirmation ───────────────────────────────────────── */
.confirm-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    max-width: 420px;
    margin: 0 auto;
    width: 100%;
    gap: 10px;
}
.confirm-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 28px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 8px;
}
.confirm-wrap h2 { font-size: 22px; font-weight: 600; }
.confirm-wrap p  { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.mail-badge {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

/* ── Misc ───────────────────────────────────────────────── */
.req { color: var(--danger); }
.badge-new {
    font-size: 10px;
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    margin-left: 4px;
    vertical-align: middle;
}
.error-msg {
    background: #fde8e8;
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 10px;
}
.hidden { display: none !important; }
.hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* ── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 0.5px solid var(--border);
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 100;
    display: flex; align-items: center; justify-content: center;
}

/* ── Photos ─────────────────────────────────────────────── */
.photos-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.btn-photo {
    flex: 1;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-photo:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.photos-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.photo-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1.5px solid var(--border);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-thumb .btn-delete-photo {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.photos-count {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* ── Responsive desktop ─────────────────────────────────── */
@media (min-width: 600px) {
    #screen-form  { max-width: 480px; margin: 0 auto; }
    #screen-login { max-width: 480px; margin: 0 auto; }
    body { background: var(--bg); }
}

/* ── Historique ─────────────────────────────────────────── */
.fiche-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.fiche-card:hover {
    border-color: var(--accent);
}

.fiche-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.fiche-card-numero {
    font-weight: 600;
    color: var(--accent);
    font-size: 14px;
}

.fiche-card-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.fiche-card-client {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.fiche-card-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.fiche-card-badge {
    display: inline-block;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    margin-top: 6px;
}

.loading-msg {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 40px 0;
}

.empty-msg {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 40px 0;
}
/* ── Loading overlay ────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;
}

.loading-overlay.hidden { display: none; }

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-overlay p {
    color: #fff;
    font-size: 15px;
    font-weight: 500;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
