:root {
    /* Palette de couleurs sobre et moderne (Slate / Indigo) */
    --primary: #4f46e5;       /* Indigo 600 */
    --primary-hover: #4338ca; /* Indigo 700 */
    --bg-page: #f8fafc;       /* Gris très clair (Slate 50) */
    --bg-card: #ffffff;
    --text-main: #0f172a;     /* Slate 900 */
    --text-muted: #64748b;    /* Slate 500 */
    --border: #e2e8f0;        /* Slate 200 */
    --danger: #ef4444;        /* Red 500 */
    --radius: 12px;           /* Arrondis plus doux */
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    margin: 0;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* --- LAYOUT GLOBAL --- */

.app-container {
    width: 100%;
    max-width: 1400px; /* Élargi pour accueillir 6 colonnes */
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* --- PANNEAU DE CONTROLE --- */

.control-panel {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    /* Ombre très douce et diffuse */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

h1 {
    margin: 0 0 2rem 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

h1::before {
    content: '';
    display: block;
    width: 6px;
    height: 24px;
    background: var(--primary);
    border-radius: 4px;
}

/* --- INPUTS & UPLOAD --- */

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 2rem;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

input.url {
    width: 100%;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
    color: var(--text-main);
}

input.url:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-upload {
    position: relative;
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-upload:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
}

/* --- OPTIONS & CHECKBOXES --- */

.options-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.option-item {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 0;
    transition: 0.2s;
}

.checkbox-wrapper:hover label { color: var(--primary); }

input[type="checkbox"] {
    accent-color: var(--primary);
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
}

.checkbox-wrapper label {
    font-size: 0.95rem;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-main);
    cursor: pointer;
}

input[type=range] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--primary);
}

#custom-ratio {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    font-size: 0.9rem;
    background: #f8fafc;
}

/* --- RATIOS CHIPS --- */

.ratios-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 2.5rem;
}

.ratio-chip {
    padding: 8px 16px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.ratio-chip:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: var(--text-main);
}

.ratio-chip.selectionned {
    background: #eef2ff;
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 600;
}

/* --- FOOTER ACTIONS --- */

.actions-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    align-items: center;
}

button.primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 32px;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}

button.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.4);
}

button.danger {
    background: transparent;
    color: var(--danger);
    border: none;
    padding: 12px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

button.danger:hover {
    opacity: 0.7;
    background: transparent;
}

/* --- GRILLE DE RESULTATS (6 COLONNES) --- */

#part-content-inner {
    display: grid;
    /* C'est ici que la magie opère : 6 colonnes */
    grid-template-columns: repeat(6, 1fr); 
    gap: 1.5rem;
    width: 100%;
}

/* Responsive : On réduit le nombre de colonnes sur petits écrans */
@media (max-width: 1200px) {
    #part-content-inner { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 800px) {
    #part-content-inner { grid-template-columns: repeat(2, 1fr); }
}

.card {
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    /* Style sobre : pas d'ombre par défaut, juste une bordure fine */
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    flex-direction: column;
}

.card:hover {
    /* L'ombre apparaît au survol */
    transform: translateY(-4px);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1);
    border-color: #cbd5e1;
    z-index: 10;
}

.card .image {
    /* Hauteur fixe pour uniformiser la grille */
    height: 180px; 
    width: 100%;
    background: #f1f5f9; /* Fond gris si image transparente */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Remplit bien la case */
    transition: transform 0.3s;
}

.card:hover img {
    transform: scale(1.05); /* Petit zoom sympa */
}

.card .image-infos {
    position: absolute;
    top: 8px; /* On met les infos en haut */
    left: 8px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.card:hover .image-infos { opacity: 1; }

.card .buttons {
    display: flex;
    border-top: 1px solid var(--border);
    background: #fff;
}

.card .buttons button {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.card .buttons button.download { 
    color: var(--primary); 
    border-right: 1px solid var(--border); 
}
.card .buttons button.download:hover { background: #eef2ff; }

.card .buttons button.delete { color: var(--danger); }
.card .buttons button.delete:hover { background: #fef2f2; }

/* --- MODALE PREVIEW --- */

#part-preview {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.8); /* Fond sombre bleuté */
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

#part-preview-content {
    background: white;
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

#preview-image {
    flex: 1;
    background: #0f172a; /* Slate 900 */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

/* Grille de fond pour la transparence dans la preview */
#preview-image::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0.1;
    background-image: radial-gradient(#64748b 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

#preview-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

#preview-actions {
    height: 80px;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
    background: white;
}

#founds {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

#founds span {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    background: white;
    color: var(--text-muted);
}

#founds span:hover {
    border-color: var(--primary);
    color: var(--primary);
}

#founds span.selectionned {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#preview-actions #buttons {
    display:flex; 
    align-items:center;
    gap:12px;
}

#preview-actions button {
    padding: 10px 24px;
    border-radius: var(--radius);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}

button.return { 
    background: #f1f5f9; 
    color: var(--text-main); 
}
button.return:hover { background: #e2e8f0; }

button.crop { 
    background: var(--primary); 
    color: white; 
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}
button.crop:hover { background: var(--primary-hover); }