:root {
    --primary: #8FBC8F;
    --primary-dark: #6B8E6B;
    --primary-light: #A8D5A8;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text-dark: #1f2937;
    --text-light: #6b7280;
    --bg-light: #f9fafb;
    --border: #e5e7eb;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    min-height: 100vh;
    padding: 0;
    overflow-x: hidden;
}

/* MOBILE FIRST - Header */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: var(--shadow-lg);
    color: white;
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.logo {
    font-size: 1.25rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info {
    display: none;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.875rem;
}

.user-name {
    font-weight: 600;
}

.user-email {
    opacity: 0.8;
    font-size: 0.75rem;
}

/* Navigation principale */
.main-nav {
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 73px;
    z-index: 999;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-link {
    padding: 0.75rem 1.5rem;
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.3s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    background: var(--bg-light);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.nav-link.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    touch-action: manipulation;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(143, 188, 143, 0.4);
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 8px rgba(143, 188, 143, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: var(--primary-light);
    color: white;
    border-color: var(--primary-light);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-success:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.btn-danger {
    background: var(--danger);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-danger:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-icon {
    padding: 0.75rem;
    border-radius: 50%;
    width: 44px;
    height: 44px;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-2px);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Auth Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    padding: 1rem;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.875rem;
}

.form-input {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(143, 188, 143, 0.2), var(--shadow-md);
    transform: translateY(-1px);
}

/* Upload Zone */
.upload-zone {
    border: 3px dashed var(--border);
    border-radius: 16px;
    padding: 2rem 1rem;
    text-align: center;
    transition: all 0.3s;
    cursor: pointer;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #ffffff 0%, #f9fafb 100%);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.upload-zone:hover {
    border-color: var(--primary);
    background: linear-gradient(145deg, #f9fafb 0%, #ffffff 100%);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.upload-zone.dragging {
    border-color: var(--primary);
    background: rgba(143, 188, 143, 0.1);
    box-shadow: var(--shadow-lg);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Canvas */
#signatureCanvas, #createSignatureCanvas {
    border: 2px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    height: 200px;
    cursor: crosshair;
    display: block;
    margin: 1rem auto;
    background: white;
    touch-action: none;
    box-shadow: var(--shadow-md);
    transition: all 0.3s;
}

#signatureCanvas:hover, #createSignatureCanvas:hover {
    box-shadow: var(--shadow-lg);
}

.canvas-controls {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 1rem 0;
    justify-content: center;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: white;
    padding: 0.5rem;
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-sm);
}

.tab {
    padding: 0.875rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: #4b5563;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s;
    font-size: 1rem;
}

.tab:hover {
    color: var(--primary);
    background: var(--bg-light);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(143, 188, 143, 0.1);
    border-radius: 8px 8px 0 0;
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Saved Signatures Grid */
.signatures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.signature-item {
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.signature-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--primary-light);
}

.signature-item:active {
    transform: scale(0.98);
}

.signature-item.selected {
    border-color: var(--primary);
    background: rgba(143, 188, 143, 0.1);
    box-shadow: var(--shadow-lg);
}

.signature-preview {
    width: 100%;
    height: 80px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.signature-name {
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 0.5rem;
}

.signature-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    cursor: pointer;
}

/* History */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 0.75rem;
}

.history-info {
    flex: 1;
}

.history-filename {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-light);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success);
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger);
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border-left: 4px solid #3b82f6;
}

/* Loading */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Position Controls */
.position-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-label {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
}

.control-input {
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.control-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Responsive - Tablet */
@media (min-width: 768px) {
    .container {
        padding: 2rem;
    }

    .card {
        padding: 2rem;
    }

    .app-header {
        padding: 1.5rem 2rem;
    }

    .logo {
        font-size: 1.5rem;
    }

    .user-info {
        display: flex;
    }

    #signatureCanvas, #createSignatureCanvas {
        height: 250px;
    }

    .signatures-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* Responsive - Desktop */
@media (min-width: 1024px) {
    .modal-content {
        max-width: 500px;
    }

    .upload-zone {
        padding: 3rem 2rem;
    }

    #signatureCanvas, #createSignatureCanvas {
        height: 300px;
    }
}

/* Print */
@media print {
    .app-header, .btn, .tabs { display: none; }
}

/* ============================================
   MODE SOMBRE
   ============================================ */

body.dark-mode {
    --text-dark: #f9fafb;
    --text-light: #d1d5db;
    --bg-light: #1f2937;
    --border: #374151;
}

body.dark-mode {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

body.dark-mode .app-header {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
}

body.dark-mode .main-nav {
    background: #374151;
    border-bottom: 1px solid #4b5563;
}

body.dark-mode .nav-link {
    color: #d1d5db;
}

body.dark-mode .nav-link.active {
    background: #4b5563;
    color: white;
}

body.dark-mode .nav-link:hover {
    background: #4b5563;
}

body.dark-mode .container {
    background: #1f2937;
}

body.dark-mode .card {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

body.dark-mode .card-title {
    color: #f9fafb;
    border-bottom-color: #4b5563;
}

body.dark-mode .control-input,
body.dark-mode .control-select {
    background: #1f2937;
    border-color: #4b5563;
    color: #f9fafb;
}

body.dark-mode .control-input:focus,
body.dark-mode .control-select:focus {
    border-color: var(--primary);
    background: #111827;
}

body.dark-mode .modal-content {
    background: #374151;
    color: #f9fafb;
}

body.dark-mode .modal-header {
    border-bottom-color: #4b5563;
}

body.dark-mode .modal-footer {
    border-top-color: #4b5563;
}

body.dark-mode .form-group label {
    color: #d1d5db;
}

body.dark-mode .form-control {
    background: #1f2937;
    border-color: #4b5563;
    color: #f9fafb;
}

body.dark-mode .form-control:focus {
    border-color: var(--primary);
    background: #111827;
}

body.dark-mode .upload-zone {
    background: #1f2937;
    border-color: #4b5563;
}

body.dark-mode .upload-zone:hover {
    background: #111827;
    border-color: var(--primary);
}

body.dark-mode .signature-item,
body.dark-mode .history-item {
    background: #1f2937;
    border-color: #4b5563;
}

body.dark-mode .signature-item:hover,
body.dark-mode .history-item:hover {
    background: #111827;
    border-color: var(--primary);
}

body.dark-mode .detail-label {
    color: #9ca3af;
}

body.dark-mode .detail-value {
    color: #f9fafb;
}

body.dark-mode .stat-card {
    background: #1f2937;
    border-color: #4b5563;
}

body.dark-mode .preference-label {
    color: #f9fafb;
}

body.dark-mode .preference-desc {
    color: #9ca3af;
}

body.dark-mode .alert {
    background: #1f2937;
    border-color: #4b5563;
}

body.dark-mode .page-header {
    color: #f9fafb;
}

body.dark-mode .page-header .subtitle {
    color: #d1d5db;
}

body.dark-mode .danger-zone {
    background: #374151;
    border-color: #dc2626;
}

body.dark-mode .danger-item {
    background: #1f2937;
    border-color: #4b5563;
}

body.dark-mode .danger-label {
    color: #fca5a5;
}

body.dark-mode .danger-desc {
    color: #d1d5db;
}

/* Canvas et signatures - Fond blanc forcé en mode sombre */
body.dark-mode #signatureCanvas,
body.dark-mode #createSignatureCanvas {
    background: white !important;
    border-color: #9ca3af;
}

body.dark-mode .signature-preview {
    background: white;
    padding: 0.5rem;
    border-radius: 8px;
}

body.dark-mode .signature-item img {
    background: white;
    padding: 0.5rem;
    border-radius: 8px;
}
