/* ===========================
   Reset et base
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    background: linear-gradient(135deg, #242424 0%, #242424 100%);
    color: #fff;
    touch-action: manipulation;
}

/* Scrollbar personnalisée */
.input-container::-webkit-scrollbar,
.chips-container::-webkit-scrollbar {
    width: 6px;
}

.input-container::-webkit-scrollbar-track,
.chips-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.input-container::-webkit-scrollbar-thumb,
.chips-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.input-container::-webkit-scrollbar-thumb:hover,
.chips-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===========================
   Écrans
   =========================== */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #242424 0%, #242424 100%);
    transition: opacity 0.4s ease, visibility 0.4s ease;
    opacity: 0;
    visibility: hidden;
    padding: 20px;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* ===========================
   Écran d'input
   =========================== */
#input-screen {
    background: linear-gradient(135deg, #242424 0%, #242424 100%);
}

.input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    width: 100%;
    max-width: 500px;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 10px;
}

#input-screen h1 {
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    text-align: center;
    margin-bottom: 0;
    font-weight: 700;
    letter-spacing: -1px;
}

.qr-input {
    width: 100%;
    padding: 16px 18px;
    font-size: 16px;
    border: 2px solid #444;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    transition: all 0.3s ease;
    outline: none;
}

.qr-input::placeholder {
    color: #888;
}

.qr-input:focus {
    border-color: #809dfd;
    background: #809dfd10;
    box-shadow: 0 0 0 3px #809dfd10;
}

.hint {
    font-size: 12px;
    color: #999;
    text-align: center;
    margin-top: 0;
}

/* ===========================
   Sélection rapide emails
   =========================== */
.email-chips {
    width: 100%;
    margin-top: 10px;
}

.chips-label {
    font-size: 13px;
    color: #999;
    margin-bottom: 10px;
    text-align: left;
}

.dropdown-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px 0;
    transition: all 0.2s ease;
}

.dropdown-toggle:hover {
    color: #809dfd;
}

.dropdown-toggle .arrow {
    transition: transform 0.3s ease;
    font-size: 10px;
    transform: rotate(-90deg);
}

.dropdown-toggle.open .arrow {
    transform: rotate(0deg);
}

.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.chips-container.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

.chip-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chip {
    padding: 8px 14px;
    font-size: 13px;
    background: #809dfd15;
    border: 1px solid #809dfd30;
    border-radius: 20px;
    color: #809dfd;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    white-space: nowrap;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.chip:active {
    transform: scale(0.95);
    background: #96aefe25;
}

.chip:focus {
    border-color: #9fb5fc;
    box-shadow: 0 0 0 2px #a9bcfa20;
}

.favorite {
    padding: 8px 14px;
    font-size: 13px;
    background: #9c36b515;
    border: 1px solid #9c36b530;
    border-radius: 20px;
    color: #9c36b5;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    white-space: nowrap;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.favorite:active {
    transform: scale(0.95);
    background: #b649d125;
}

.favorite:focus {
    border-color: #be50d9;
    box-shadow: 0 0 0 2px #b144cc20;
}

.fav-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #b59c36;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.fav-btn:hover {
    background: #c9b04215;
    border-color: #ccc14930;
    transform: scale(1.1);
}

.fav-btn:active {
    transform: scale(0.95);
}

.fav-btn:focus {
    border-color: #cab448;
    box-shadow: 0 0 0 2px #d0c24620;
}

/* ===========================
   Écran QR code
   =========================== */
#qr-screen {
    background: #1a1a1a;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex: 1;
    width: 100%;
}

.qr-code-wrapper {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideInUp 0.5s ease-out;
}

.qr-code-wrapper canvas {
    max-width: 100%;
    height: auto;
    display: block;
}

.qr-text {
    font-size: 14px;
    color: #999;
    text-align: center;
    word-break: break-all;
    max-width: 100%;
    padding: 0 10px;
    animation: slideInUp 0.5s ease-out 0.1s backwards;
}

/* ===========================
   Contrôles
   =========================== */
.controls {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    animation: slideInUp 0.5s ease-out 0.2s backwards;
}

.btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: #809dfd;
    color: white;
}

.btn-primary:active,
.btn-primary:hover {
    background: #a2b7ff;
    transform: scale(0.98);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:active,
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.98);
}

/* ===========================
   Bannière installation PWA
   =========================== */
.install-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(150px);
    background: rgba(90, 159, 212, 0.95);
    padding: 14px 18px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.4s ease;
    max-width: 90%;
}

.install-banner.visible {
    transform: translateX(-50%) translateY(0);
}

.install-banner span {
    font-size: 14px;
    font-weight: 500;
    flex: 1;
}

.btn-small {
    padding: 6px 12px;
    background: white;
    color: #5a9fd4;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.btn-small:active {
    transform: scale(0.95);
}

/* ===========================
   Animations
   =========================== */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===========================
   Responsive Mobile
   =========================== */
@media (max-width: 480px) {
    .screen {
        padding: 16px;
    }

    #input-screen h1 {
        font-size: 2.5rem;
    }

    .input-container {
        gap: 16px;
    }

    .qr-input {
        padding: 14px 16px;
        font-size: 16px;
    }

    .chip {
        padding: 7px 12px;
        font-size: 12px;
    }

    .chips-label {
        font-size: 12px;
    }

    .controls {
        max-width: 100%;
    }

    .btn {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* ===========================
   Tablette
   =========================== */
@media (min-width: 481px) and (max-width: 1024px) {
    .input-container {
        max-width: 500px;
    }

    .qr-code-wrapper {
        max-width: 70vw;
        max-height: 70vh;
    }
}

/* ===========================
   Desktop
   =========================== */
@media (min-width: 1025px) {
    .input-container {
        max-width: 500px;
    }

    .controls {
        max-width: 500px;
    }

    .qr-code-wrapper {
        max-width: 60vw;
        max-height: 60vh;
    }

    .btn:hover {
        transform: translateY(-2px);
    }

    .chip:hover {
        background: #a5b9fc25;
        border-color: #9eb4fd;
        transform: translateY(-1px);
    }

    .favorite:hover {
        background: #b248cd25;
        border-color: #bd56d6;
        transform: translateY(-1px);
    }
}

/* ===========================
   Mode plein écran PWA
   =========================== */
@supports (display: browser) {
    body {
        display: browser;
    }
}

/* Cacher les éléments de navigation du navigateur en mode PWA */
@media (display-mode: standalone) {
    body {
        padding-top: max(env(safe-area-inset-top), 0px);
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }
}

/* Support des encoches (notch) sur les appareils mobiles */
@media (min-height: 800px) {
    #input-screen h1 {
        margin-bottom: 20px;
    }
}

/* ===========================
   Signature
   =========================== */
.signature {
    position: fixed;
    bottom: 10px;
    right: 15px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
    z-index: 1;
}
