@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap');

/* =====================================================
   1. VARIABLES & THEMES (CLAIR / SOMBRE)
   ===================================================== */

:root {
    --brown: #2B1D14;
    --brown-dark: #1A110B;
    --brown-light: #8B5A2B;
    --cream: #F4E8D3;
    --paper: #FCF6EA;
    --line: #D8C3A5;
    --text: #2B1D14;
    --muted: #7A6455;
    --gold: #D4A373;
}

body.dark-mode {
    --cream: #1A110B;
    --paper: #2B1D14;
    --line: #4A3B2F;
    --text: #F4E8D3;
    --brown: #D4A373;
    --brown-dark: #FCF6EA;
    --brown-light: #E0C3A5;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--cream);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.3s, color 0.3s;
}

.hidden {
    display: none !important;
}


/* =====================================================
   2. BARRE DE NAVIGATION
   ===================================================== */

.topbar {
    height: 76px;
    padding: 0 clamp(18px, 5vw, 72px);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    transition: background 0.3s;
}

.brand-mark-img {
    width: 39px;
    height: 39px;
    border-radius: 13px;
    object-fit: cover;
    border: 2px solid var(--line);
}

.brand {
    font-weight: 700;
    letter-spacing: .12em;
    font-size: 14px;
}

.brand span {
    display: block;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.theme-toggle-btn {
    background: transparent;
    border: 1.5px solid var(--text);
    cursor: pointer;
    font-size: 16px;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    color: var(--text);
}

.theme-toggle-btn:hover {
    background: rgba(139, 90, 43, 0.1);
}

.admin-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--brown-dark);
    background: rgba(139, 90, 43, 0.1);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 11px;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-button {
    font: 500 11px 'DM Sans', sans-serif;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--paper);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.history-button:hover {
    background: rgba(139, 90, 43, 0.1);
}

.text-button {
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.text-button:hover {
    text-decoration: underline;
}


/* =====================================================
   3. STRUCTURE & ACCUEIL
   ===================================================== */

.screen {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: 48px 24px 60px;
    flex: 1;
}

.home-screen {
    max-width: 720px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 140px);
}

.hero-art {
    height: 240px;
    width: 180px;
    position: relative;
    margin: 0 auto 26px;
    border-radius: 50% 50% 43% 43%;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.hero-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.eyebrow {
    color: var(--brown-light);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .15em;
    margin: 0 0 10px;
}

h1,
h2 {
    font-family: 'Playfair Display', serif;
    color: var(--brown-dark);
    margin: 0;
}

h1 {
    font-size: clamp(34px, 5vw, 48px);
    line-height: 1.12;
}

h1 span {
    color: var(--brown-light);
}

h2 {
    font-size: 23px;
}

.intro {
    max-width: 480px;
    color: var(--muted);
    line-height: 1.7;
    margin: 18px auto 28px;
}

.narrow {
    max-width: 540px;
}


/* =====================================================
   4. BOUTONS
   ===================================================== */

.primary-button,
.secondary-button,
.file-button {
    border-radius: 12px;
    padding: 14px 20px;
    font: 600 14px 'DM Sans', sans-serif;
    cursor: pointer;
    transition: .15s;
}

.primary-button {
    background: var(--brown);
    color: var(--paper);
    border: 1px solid var(--brown);
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.15);
}

.primary-button:hover {
    background: var(--brown-dark);
}

.primary-button span {
    margin-left: 14px;
    font-size: 18px;
}

.secondary-button {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
}

.secondary-button:hover {
    background: rgba(139, 90, 43, 0.1);
}

.full {
    width: 100%;
    margin-top: 22px;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin: 0 0 28px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--paper);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.back-button:hover {
    background: var(--brown);
    color: var(--paper);
}

.inline-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brown-light);
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}


/* =====================================================
   5. FORMULAIRES
   ===================================================== */

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 25px;
    margin-top: 24px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.05);
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 8px;
    color: var(--text);
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--cream);
    padding: 12px 13px;
    color: var(--text);
    font: 14px 'DM Sans', sans-serif;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--brown-light);
    box-shadow: 0 0 0 3px rgba(139, 90, 43, .15);
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

.hint {
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted);
}

.error {
    color: #d9534f;
    font-size: 13px;
}

.error:empty {
    display: none;
}

.account-prompt {
    font-size: 12px;
    color: var(--muted);
    margin: 14px 0 0;
}


/* MOT DE PASSE */

.password-field {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-field input {
    width: 100%;
    padding-right: 46px;
}

.toggle-password {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 16px;
    color: var(--text);
}

.toggle-password:hover {
    background: rgba(139, 90, 43, .1);
}


/* =====================================================
   6. ECRAN D'ATTRIBUTION
   ===================================================== */

.assign-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.step-pill {
    font-size: 10px;
    letter-spacing: .1em;
    background: rgba(139, 90, 43, .15);
    color: var(--brown-light);
    padding: 10px 12px;
    border-radius: 30px;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.upload-panel {
    margin-top: 24px;
}

.upload-icon {
    width: 37px;
    height: 37px;
    border: 1.5px solid var(--text);
    background: transparent;
    border-radius: 11px;
    display: grid;
    place-items: center;
    color: var(--text);
    font-weight: 700;
    font-size: 12px;
    margin-bottom: 14px;
}

.upload-panel p {
    font-size: 12px;
    line-height: 1.55;
    color: var(--muted);
}

code {
    background: rgba(139, 90, 43, .15);
    padding: 2px 5px;
    border-radius: 4px;
    color: var(--brown-light);
}

.file-input {
    display: none;
}

.file-button {
    display: inline-block;
    background: transparent;
    border: 1.5px solid var(--text);
    color: var(--text);
    padding: 10px 13px;
    font-size: 12px;
}

.rules-panel {
    margin-top: 18px;
}

.rules-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.import-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    margin-bottom: 8px;
}

.file-button-mini {
    font-size: 11px;
    color: var(--text);
    background: transparent;
    border: 1.5px solid var(--text);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.file-button-mini:hover {
    background: rgba(139, 90, 43, .15);
}


/* NOUVEAU : BOUTON COLLER DANS LA ZONE DE TEXTE */

.textarea-wrapper {
    position: relative;
    width: 100%;
}

.textarea-wrapper textarea {
    width: 100%;
    padding-bottom: 40px;
}

.paste-inside-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.paste-inside-btn:hover {
    background: var(--cream);
}


/* STATUT DES FICHIERS */

.file-status {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 36px;
    margin-top: 8px;
    padding: 7px 9px;
    border: 1px dashed var(--line);
    border-radius: 9px;
    background: var(--paper);
}

.file-status-icon {
    display: grid;
    place-items: center;
    width: 23px;
    height: 23px;
    flex: 0 0 23px;
    border-radius: 6px;
    border: 1.5px solid var(--text);
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.file-name {
    display: block;
    flex: 1;
    margin: 0;
    font-size: 11px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.file-status.has-file {
    border-style: solid;
    border-color: #A3B18A;
    background: rgba(163, 177, 138, .1);
}

.file-status.has-file .file-status-icon {
    color: #3A5A40;
    border-color: #3A5A40;
}

.file-status.file-error {
    border-color: #d9534f;
    background: rgba(217, 83, 79, .1);
}

.clear-file {
    border: 1.5px solid var(--text);
    border-radius: 50%;
    width: 23px;
    height: 23px;
    flex: 0 0 23px;
    color: var(--text);
    font-size: 17px;
    cursor: pointer;
    background: transparent;
}


/* MODE TIRAGE */

.mode-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.mode-button {
    display: flex;
    align-items: center;
    gap: 11px;
    text-align: left;
    padding: 14px 15px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--text);
    cursor: pointer;
    min-height: 68px;
}

.mode-button.selected {
    border: 2px solid var(--brown);
    padding: 13px 14px;
    background: rgba(139, 90, 43, .15);
}

.mode-dot {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    border: 1.5px solid var(--text);
    border-radius: 50%;
    display: grid;
    place-items: center;
}

.mode-button.selected .mode-dot {
    border-color: var(--brown);
}

.mode-button.selected .mode-dot:after {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--brown);
}

.mode-button strong,
.mode-button small {
    display: block;
}

.mode-button strong {
    font-size: 13px;
    color: var(--text);
}

.mode-button small {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}


/* =====================================================
   7. RESULTATS (PHOTO 250PX)
   ===================================================== */

.results-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 22px 0;
}

.result-card {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    align-items: start;
    gap: 24px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
}

.parrain-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.parrain-avatar {
    width: 250px;
    height: 250px;
    flex: 0 0 250px;
    border-radius: 50%;
    font-size: 60px;
    border: 4px solid var(--line);
    display: grid;
    place-items: center;
    background-color: rgba(139, 90, 43, .15);
    color: var(--text);
    font-weight: 700;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.parrain-avatar.has-photo {
    color: transparent;
}

.parrain-name {
    font-family: 'DM Sans', sans-serif;
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    overflow-wrap: anywhere;
    color: var(--text);
}

.filleuls-list {
    display: grid;
    gap: 8px;
    width: 100%;
}

.filleul-line {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(139, 90, 43, .05);
}

.filleul-number {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 50%;
    background: var(--brown);
    color: var(--paper);
    font-size: 12px;
    font-weight: 700;
}

.filleul-name {
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    overflow-wrap: anywhere;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 20px 0;
}


/* =====================================================
   8. HISTORIQUE
   ===================================================== */

.history-filters label {
    margin-top: 0;
}

.history-filters #historySearch {
    flex: 1;
}

.history-list {
    display: grid;
    gap: 12px;
    margin-top: 20px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
}

.history-item h2 {
    font-size: 18px;
    margin-bottom: 5px;
}

.history-view {
    margin-top: 0;
}


/* =====================================================
   9. MESSAGES & MODALE
   ===================================================== */

.success-message {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px solid #A3B18A;
    background: rgba(163, 177, 138, .1);
    border-radius: 10px;
    color: #3A5A40;
    font-size: 13px;
    line-height: 1.5;
}

.success-message .inline-button {
    color: #3A5A40;
    margin-left: 4px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--paper);
    padding: 25px;
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 20px;
}

.modal-content p {
    color: var(--muted);
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-actions button {
    flex: 1;
}

footer {
    text-align: center;
    padding: 18px;
    color: var(--muted);
    font-size: 11px;
    border-top: 1px solid var(--line);
}


/* =====================================================
   10. RESPONSIVE & IMPRESSION
   ===================================================== */

@media(max-width: 850px) {
    .screen {
        padding: 30px 16px 42px;
    }
    .topbar {
        height: 66px;
        padding: 0 17px;
    }
    .upload-grid,
    .rules-grid {
        grid-template-columns: 1fr;
    }
    .assign-heading {
        align-items: flex-start;
        flex-direction: column;
    }
    .result-card {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }
    .parrain-avatar {
        width: 200px;
        height: 200px;
        flex-basis: 200px;
        font-size: 48px;
    }
    .history-item {
        align-items: flex-start;
        flex-direction: column;
    }
    .result-actions {
        flex-direction: column;
    }
    .result-actions button {
        width: 100%;
    }
}

@media print {
    .topbar,
    footer,
    .upload-grid,
    .rules-panel,
    .assign-heading .step-pill,
    .results-panel .secondary-button {
        display: none !important;
    }
    body {
        background: white;
    }
    .screen {
        width: 100%;
        padding: 0;
    }
    .panel {
        box-shadow: none;
        border: 0;
    }
    .results-panel {
        display: block !important;
    }
    .back-button,
    .result-actions,
    #downloadBtn,
    .header-actions {
        display: none !important;
    }
    .result-card {
        break-inside: avoid;
        box-shadow: none;
        grid-template-columns: 200px minmax(0, 1fr);
    }
    .parrain-avatar {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
}

/* =====================================================
   MENU HAMBURGER + PIED DE PAGE PRO
   ===================================================== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    margin-left: auto;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    place-items: center;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}

.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
    transition: transform .25s, opacity .2s;
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 850px) {
    .menu-toggle { display: flex; }

    .header-actions {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        margin-left: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 16px 17px 20px;
        background: var(--paper);
        border-bottom: 1px solid var(--line);
        box-shadow: 0 14px 28px rgba(26, 17, 11, .18);
    }

    .header-actions.open { display: flex; animation: menuIn .2s ease-out; }

    .header-actions .admin-name {
        max-width: none;
        text-align: center;
        font-size: 13px;
    }

    .header-actions .history-button,
    .header-actions .text-button,
    .header-actions .theme-toggle-btn {
        width: 100%;
        height: auto;
        padding: 13px 14px;
        font-size: 14px;
        border-radius: 10px;
        border: 1px solid var(--line);
        background: transparent;
        color: var(--text);
        text-align: center;
    }

    .header-actions .theme-toggle-btn { display: flex; justify-content: center; gap: 8px; }
    .header-actions .theme-toggle-btn::after { content: "Changer de thème"; font: 500 14px 'DM Sans', sans-serif; }
}

@keyframes menuIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
}

/* ---- Pied de page ---- */
.site-footer {
    margin-top: auto;
    padding: 0;
    text-align: left;
    font-size: 13px;
    background: var(--paper);
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.footer-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 44px clamp(18px, 5vw, 72px) 30px;
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 36px;
}

.footer-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: .12em;
    font-size: 14px;
}

.footer-logo img {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid var(--line);
}

.footer-about {
    margin: 14px 0 0;
    max-width: 330px;
    line-height: 1.6;
}

.footer-col h4 {
    margin: 0 0 14px;
    color: var(--text);
    font-size: 12px;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.footer-col ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 10px;
}

.footer-col li::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 10px;
    border-radius: 50%;
    background: var(--gold);
    vertical-align: middle;
}

.footer-bottom {
    border-top: 1px solid var(--line);
}

.footer-bottom-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 18px clamp(18px, 5vw, 72px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 12px;
}

.footer-top-btn {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: 500 12px 'DM Sans', sans-serif;
    padding: 7px 14px;
    cursor: pointer;
}

.footer-top-btn:hover { background: rgba(139, 90, 43, 0.1); }

@media (max-width: 850px) {
    .footer-inner { grid-template-columns: 1fr; gap: 28px; padding-top: 34px; }
    .footer-bottom-inner { flex-direction: column; text-align: center; }
}
