/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #7209b7;
    --success: #06d6a0;
    --danger: #ef476f;
    --warning: #ffd166;
    --dark: #1a1a2e;
    --dark-light: #16213e;
    --gray: #6c757d;
    --gray-light: #adb5bd;
    --white: #ffffff;
    --bg: #0f0f1a;
    --bg-primary: #0f0f1a;
    --card-bg: #1a1a2e;
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #adb5bd;
    --border-radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg);
    color: var(--white);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 100px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--dark) 0%, var(--dark-light) 100%);
    padding: 20px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 16px;
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: 20px;
}

.search-container input {
    width: 100%;
    padding: 16px 50px 16px 20px;
    font-size: 16px;
    background: var(--card-bg);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    color: var(--white);
    transition: border-color 0.3s;
}

.search-container input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-container input::placeholder {
    color: var(--gray-light);
}

.btn-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--gray-light);
    cursor: pointer;
    padding: 8px;
    display: none;
}

.search-container input:not(:placeholder-shown) + .btn-icon {
    display: block;
}

/* Pieces List */
.pieces-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.piece-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.piece-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.piece-card:active {
    transform: scale(0.98);
}

.piece-card-info {
    flex: 1;
    min-width: 0;
}

.piece-card-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.piece-card-details {
    font-size: 0.85rem;
    color: var(--gray-light);
}

.piece-card-ref {
    color: var(--primary);
    font-family: monospace;
}

.piece-card-location {
    display: block;
    margin-top: 4px;
    color: var(--gray);
}

.piece-card-author {
    display: block;
    margin-top: 4px;
    color: var(--primary);
    font-size: 0.8rem;
    font-style: italic;
}

.piece-card-qty {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
    font-size: 1.2rem;
    font-weight: 700;
    min-width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 12px;
    flex-shrink: 0;
}

.piece-card-qty.low-stock {
    background: linear-gradient(135deg, var(--danger), #d63384);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray);
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 20px;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 0.9rem;
    color: var(--gray-light);
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--dark-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Scan Button */
.scan-button {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
    border: none;
    border-radius: 50px;
    padding: 18px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(67, 97, 238, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 99;
}

.scan-button:hover {
    transform: translateX(-50%) scale(1.05);
}

.scan-button:active {
    transform: translateX(-50%) scale(0.95);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--gray-light);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Scanner Modal */
.scanner-modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.scanner-reader {
    flex: 1;
    min-height: 300px;
    max-height: 50vh;
    background: #000;
    position: relative;
    overflow: hidden;
}

.scanner-reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* Ligne de scan animée */
.scanner-reader::after {
    content: '';
    position: absolute;
    left: 10%;
    right: 10%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--primary), var(--secondary), var(--primary), transparent);
    animation: scanLine 2s linear infinite;
    box-shadow: 0 0 10px var(--primary);
}

@keyframes scanLine {
    0% { top: 20%; }
    50% { top: 80%; }
    100% { top: 20%; }
}

.scanner-hint {
    text-align: center;
    padding: 16px;
    color: var(--gray-light);
    font-size: 0.9rem;
}

/* Photo Capture Button */
.photo-capture {
    padding: 20px;
    text-align: center;
}

.photo-hint {
    color: var(--warning);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.btn-photo {
    background: linear-gradient(135deg, var(--success), #00a884);
    color: var(--white);
    border: none;
    padding: 16px 32px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-photo:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(6, 214, 160, 0.4);
}

.btn-photo:active {
    transform: scale(0.98);
}

/* Manual Entry */
.manual-entry {
    padding: 16px 20px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.manual-hint {
    text-align: center;
    color: var(--gray);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.manual-input-group {
    display: flex;
    gap: 10px;
}

.manual-input-group input {
    flex: 1;
    padding: 14px 16px;
    font-size: 16px;
    background: var(--dark);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--white);
}

.manual-input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.manual-input-group button {
    padding: 14px 24px;
}

/* Piece Info in Modal */
.piece-info {
    padding: 20px;
    text-align: center;
    background: rgba(67, 97, 238, 0.1);
}

.piece-name {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.piece-details {
    font-size: 0.9rem;
    color: var(--gray-light);
}

.modal-question {
    padding: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* Quantity Buttons */
.quantity-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 0 20px 20px;
}

.qty-btn {
    background: var(--dark);
    border: 2px solid var(--primary);
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 600;
    padding: 16px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.qty-btn:hover {
    background: var(--primary);
    color: var(--white);
}

.qty-btn:active {
    transform: scale(0.95);
}

/* Custom Quantity */
.custom-quantity {
    display: flex;
    gap: 10px;
    padding: 0 20px 20px;
}

.custom-quantity input {
    flex: 1;
    padding: 14px 16px;
    font-size: 16px;
    background: var(--dark);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--white);
}

.custom-quantity input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Forms */
form {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--gray-light);
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    background: var(--dark);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--white);
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group input[readonly] {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gray-light);
}

/* Input with button */
.input-with-btn {
    display: flex;
    gap: 8px;
}

.input-with-btn input {
    flex: 1;
}

.btn-ai {
    background: linear-gradient(135deg, #10a37f, #1a7f64);
    color: var(--white);
    border: none;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-ai:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(16, 163, 127, 0.4);
}

.btn-ai:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-ai.loading svg {
    animation: spin 1s linear infinite;
}

.ai-status {
    font-size: 0.8rem;
    margin-top: 6px;
    color: var(--gray-light);
}

.ai-status.success {
    color: var(--success);
}

.ai-status.error {
    color: var(--danger);
}

/* Vehicle Badges */
.vehicle-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.vehicle-badge {
    background: var(--dark);
    border: 2px solid var(--gray);
    color: var(--gray-light);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.vehicle-badge:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.vehicle-badge.selected {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    color: var(--white);
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
    border: none;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-full {
    width: 100%;
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
    border: none;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-danger:hover {
    background: #d63956;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.form-actions button {
    flex: 1;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--dark-light);
    color: var(--white);
    padding: 14px 24px;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 90%;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--success);
    color: #000;
}

.toast.error {
    background: var(--danger);
}

/* Responsive */
@media (max-width: 400px) {
    .quantity-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .piece-card {
        padding: 14px;
    }
    
    .piece-card-name {
        font-size: 1rem;
    }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .app-container {
        padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }
    
    .scan-button {
        bottom: calc(30px + env(safe-area-inset-bottom));
    }
}

/* =====================================================
   NEW STYLES - V2
   ===================================================== */

/* Header with actions */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions .btn-icon {
    position: static;
    transform: none;
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    padding: 8px;
    color: var(--gray-light);
}

.header-actions .btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

.user-info {
    font-size: 0.8rem;
    color: var(--gray-light);
    margin-right: 8px;
}

.btn-admin {
    background: rgba(114, 9, 183, 0.3) !important;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar .search-container {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.export-buttons {
    display: flex;
    gap: 8px;
}

.btn-export {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px 14px;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--dark-light);
    color: var(--white);
    border-color: var(--primary);
}

/* Modal sizes */
.modal-large {
    max-width: 500px;
}

.modal-small {
    max-width: 350px;
}

.modal-overlay {
    z-index: 1100;
}

/* Location Selects */
.location-selects {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.location-select {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    background: var(--dark);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--white);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23adb5bd'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
}

.location-select:focus {
    outline: none;
    border-color: var(--primary);
}

.location-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.location-select option {
    background: var(--dark);
    color: var(--white);
}

/* Form group for selects */
.form-group select {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    background: var(--dark);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--white);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23adb5bd'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 24px;
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Admin Panel */
.admin-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
}

.admin-tab {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 14px 20px;
    font-size: 0.95rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.admin-tab:hover {
    color: var(--white);
}

.admin-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.admin-tab-content {
    display: none;
    padding: 20px;
}

.admin-tab-content.active {
    display: block;
}

.admin-toolbar {
    margin-bottom: 16px;
}

.btn-small {
    padding: 10px 16px;
    font-size: 0.9rem;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.admin-list-item {
    background: var(--dark);
    border-radius: var(--border-radius);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.admin-list-item-info {
    flex: 1;
}

.admin-list-item-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.admin-list-item-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.admin-list-item-actions {
    display: flex;
    gap: 8px;
}

.btn-icon-small {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

.btn-icon-small.danger:hover {
    background: rgba(239, 71, 111, 0.3);
    color: var(--danger);
}

/* Locations Tree */
.locations-tree {
    padding-left: 0;
}

.location-item {
    margin-bottom: 8px;
}

.location-item-header {
    background: var(--dark);
    border-radius: var(--border-radius);
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.location-item-header:hover {
    border-color: var(--primary);
}

.location-item-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.location-level {
    font-size: 0.7rem;
    background: var(--primary);
    color: var(--white);
    padding: 2px 6px;
    border-radius: 4px;
}

.location-children {
    margin-left: 20px;
    margin-top: 8px;
    padding-left: 12px;
    border-left: 2px solid var(--border-color);
}

/* Badge role */
.badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
}

.badge-admin {
    background: rgba(114, 9, 183, 0.3);
    color: var(--secondary);
}

.badge-user {
    background: rgba(67, 97, 238, 0.3);
    color: var(--primary);
}

/* Empty admin list */
.admin-list-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 500px) {
    .location-selects {
        grid-template-columns: 1fr;
    }
    
    .export-buttons {
        width: 100%;
        justify-content: flex-end;
    }
    
    .toolbar {
        flex-direction: column;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
}
