/* Design System Apple-like Dark Mode */
:root {
    /* Couleurs système Apple Dark */
    --color-bg: #000000;
    --color-surface: #1C1C1E;
    --color-surface-elevated: #2C2C2E;
    --color-border: rgba(255, 255, 255, 0.1);
    --color-border-focus: #0A84FF;
    --color-text-primary: #FFFFFF;
    --color-text-secondary: #EBEBF599;
    /* ~60% white */
    --color-text-tertiary: #EBEBF54D;
    /* ~30% white */
    --color-accent: #0A84FF;
    --color-accent-hover: #409CFF;
    --color-success: #32D74B;
    --color-warning: #FF9F0A;
    --color-error: #FF453A;

    /* Ombres (Dark mode implies subtle glows or deep shadows) */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);

    /* Rayons */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', Roboto, sans-serif;
    color: var(--color-text-primary);
    line-height: 1.5;
    min-height: 100vh;
    background-color: #000;
    overflow-x: hidden;
}

/* Background Animé - Mesh Gradient */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(10, 132, 255, 0.15), transparent 50%),
        radial-gradient(circle at 10% 20%, rgba(94, 92, 230, 0.15), transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(50, 215, 75, 0.1), transparent 40%),
        radial-gradient(circle at 80% 10%, rgba(255, 159, 10, 0.1), transparent 40%);
    filter: blur(80px);
    z-index: -1;
    animation: gradientMove 20s ease infinite alternate;
    opacity: 0.8;
}

@keyframes gradientMove {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    100% {
        transform: translate(-5%, -5%) rotate(5deg);
    }
}

/* Layout principal */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: rgba(28, 28, 30, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--color-border);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

.app-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    color: var(--color-text-primary);
}

.app-icon {
    width: 28px;
    height: 28px;
    color: var(--color-accent);
}

.app-subtitle {
    font-size: 1rem;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* Main content */
.app-main {
    flex: 1;
    padding: 2rem;
}

/* Container éditeur */
.editor-container {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .editor-container {
        grid-template-columns: 1fr;
    }
}

/* Formulaire */
.editor-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-section {
    background: rgba(28, 28, 30, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: 1.6rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.form-section:hover {
    transform: translateY(-4px) scale(1.005);
    background: rgba(44, 44, 46, 0.7);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Glow effect behind active/hovered cards */
.form-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    transition: 0.5s;
    pointer-events: none;
}

.form-section:hover::before {
    left: 100%;
    transition: 0.7s;
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-primary);
}

.section-title svg {
    width: 20px;
    height: 20px;
    color: var(--color-accent);
}

/* Groupes de formulaire */
.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-row:has(> :nth-child(3)) {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 640px) {
    .form-row:has(> :nth-child(3)) {
        grid-template-columns: 1fr;
    }
}

label {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

/* Inputs */
/* Inputs - Animated Focus Ring & Underline */
.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    outline: none;
    position: relative;
}

.form-input:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
}

.form-input:focus {
    background: rgba(30, 30, 32, 0.8);
    border-color: var(--color-accent);
    box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.form-input::placeholder {
    color: var(--color-text-tertiary);
}

.form-input-mono {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    letter-spacing: 0.05em;
}

.form-hint {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
}

/* Champs automatiques */
.form-group-auto {
    opacity: 0.8;
}

.auto-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    min-height: 44px;
}

.auto-value {
    flex: 1;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.9375rem;
    color: var(--color-text-primary);
    font-weight: 500;
}

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: linear-gradient(135deg, #0A84FF 0%, #0066CC 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(10, 132, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #409CFF 0%, #0A84FF 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(10, 132, 255, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(10, 132, 255, 0.3);
}

/* Button Loading State Animation */
.btn-primary:disabled {
    cursor: wait;
    opacity: 0.8;
    background: linear-gradient(135deg, #0A84FF 0%, #0066CC 100%);
}

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

.spinner {
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-primary);
    border: 1px solid transparent;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-primary);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

/* Actions du formulaire */
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.5rem;
    flex-wrap: wrap;
}

/* Section aperçu */
.editor-preview {
    position: sticky;
    top: 100px;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.preview-title {
    font-size: 1.125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-primary);
}

.preview-title svg {
    width: 20px;
    height: 20px;
    color: var(--color-accent);
}

.preview-badge {
    padding: 0.25rem 0.625rem;
    background: rgba(50, 215, 75, 0.15);
    color: var(--color-success);
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid rgba(50, 215, 75, 0.2);
}

.preview-container {
    background: #1C1C1E;
    /* Match surface for consistency */
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    overflow: hidden;
    position: relative;
}

/* Add a subtle glare/gradient to the preview container */
.preview-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
    pointer-events: none;
}

.preview-container iframe {
    width: 100%;
    height: 600px;
    border: none;
    border-radius: var(--radius-sm);
    background: #FFFFFF;
    /* Keep preview white as it's a label */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.preview-info {
    margin-top: 1rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
    transition: all var(--transition-base);
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 500;
    font-size: 0.9375rem;
}

.toast-icon {
    width: 20px;
    height: 20px;
    color: var(--color-success);
}

/* Footer */
.app-footer {
    padding: 2rem;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--color-text-tertiary);
    border-top: 1px solid var(--color-border);
    margin-top: auto;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-section {
    animation: fadeIn 0.4s ease-out backwards;
}

.form-section:nth-child(1) {
    animation-delay: 0.05s;
}

.form-section:nth-child(2) {
    animation-delay: 0.1s;
}

.form-section:nth-child(3) {
    animation-delay: 0.15s;
}

.form-section:nth-child(4) {
    animation-delay: 0.2s;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: 1rem 0;
    }

    .app-title {
        font-size: 1.5rem;
    }

    .app-subtitle {
        font-size: 0.875rem;
    }

    .app-main {
        padding: 1rem;
    }

    .editor-container {
        gap: 1.5rem;
    }

    .form-section {
        padding: 1.25rem;
    }

    .preview-container iframe {
        height: 400px;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        width: 100%;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

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

/* Section Code-barres en premier */
.barcode-section {
    border: 1px solid rgba(10, 132, 255, 0.3);
    background: linear-gradient(135deg, rgba(10, 132, 255, 0.1) 0%, rgba(28, 28, 30, 0.4) 100%);
}

.barcode-section .section-title {
    color: var(--color-accent);
}

.barcode-section .section-title svg {
    color: var(--color-accent);
}

/* Animation du code-barres */
.barcode-input {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-align: center;
    transition: all 0.3s ease;
}

.barcode-input:focus {
    transform: scale(1.02);
    box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.25);
}

.barcode-progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 0.75rem;
    overflow: hidden;
    position: relative;
}

.barcode-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent) 0%, var(--color-success) 100%);
    border-radius: 3px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
    position: relative;
}

.barcode-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.4) 50%, transparent 100%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.barcode-counter {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.barcode-current {
    font-weight: 700;
    color: var(--color-accent);
    transition: color 0.3s ease;
}

.barcode-current.complete {
    color: var(--color-success);
    animation: pulse-success 0.5s ease;
}

@keyframes pulse-success {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.barcode-input.valid {
    border-color: var(--color-success);
    background: rgba(50, 215, 75, 0.1);
}

.barcode-input.valid:focus {
    box-shadow: 0 0 0 4px rgba(50, 215, 75, 0.2);
}

.barcode-input.invalid {
    border-color: var(--color-error);
    background: rgba(255, 69, 58, 0.1);
}


/* Modales Dark Mode */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.modal-content {
    background: #1C1C1E;
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    transform: scale(0.95);
    animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-lg {
    max-width: 900px;
}

.modal-sm {
    max-width: 400px;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--color-text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: flex-end;
}

.modal-search {
    margin-bottom: 1.5rem;
}

/* Tables dans les modales */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.data-table th {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-primary);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.cell-content {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.actions-cell {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Helpers */
.text-center {
    text-align: center;
}

.justify-center {
    justify-content: center;
}

.mb-4 {
    margin-bottom: 1rem;
}

.font-mono {
    font-family: 'SF Mono', monospace;
}

.text-secondary {
    color: var(--color-text-secondary);
}

.modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 69, 58, 0.1);
    color: var(--color-error);
}

.modal-icon svg {
    width: 32px;
    height: 32px;
}

.btn-danger {
    background: rgba(255, 69, 58, 0.15);
    color: #FF453A;
}

.btn-danger:hover {
    background: rgba(255, 69, 58, 0.25);
}

.btn-sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.8125rem;
}

/* Animations */
@keyframes modalSlideIn {
    to {
        transform: scale(1);
    }
}