:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-bg: #f4f6f9;
    --color-sidebar: #1e293b;
    --color-sidebar-active: #2563eb;
    --color-text: #1f2937;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

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

.sidebar {
    width: 220px;
    background: var(--color-sidebar);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    font-size: 1.4rem;
    font-weight: 700;
    padding: 1.2rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: .5rem;
}

.sidebar-nav a {
    color: #cbd5e1;
    padding: .65rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .15rem;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--color-sidebar-active);
    color: #fff;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--color-muted);
}

.content {
    padding: 1.5rem;
}

/* Auth page */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    flex-direction: column;
    gap: 1rem;
}

.auth-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    padding: 2rem;
    width: 100%;
    max-width: 360px;
}

.auth-card h1 {
    margin-top: 0;
    font-size: 1.4rem;
    text-align: center;
}

/* Cards */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

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

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.stat-card .stat-label {
    color: var(--color-muted);
    font-size: .875rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 500;
    font-size: .9rem;
}

.form-control {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .95rem;
    background: #fff;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 180px;
}

.field-highlight {
    border: 2px solid var(--color-primary);
    background: #fff8e1;
    font-weight: 600;
}

.field-error {
    border: 2px solid var(--color-danger) !important;
    background: #fee2e2;
}

.prepare-totals-row td {
    background: #f1f5f9;
    border-top: 2px solid var(--color-border);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: .55rem 1.1rem;
    border-radius: var(--radius);
    background: var(--color-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: .9rem;
    text-align: center;
}

.btn:hover {
    background: var(--color-primary-dark);
}

.btn-sm {
    padding: .3rem .65rem;
    font-size: .8rem;
}

.btn-secondary {
    background: #6b7280;
}

.btn-secondary:hover {
    background: #4b5563;
}

/* Saisie de commande */
.qty-controls-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: .6rem;
}

.qty-control {
    display: flex;
    align-items: stretch;
    gap: .25rem;
}

.qty-control[hidden] {
    display: none;
}

.qty-control input {
    text-align: center;
}

.qty-control .btn {
    flex-shrink: 0;
    padding: .55rem .7rem;
}

.qty-control {
    width: 100%;
    min-width: 130px;
}

.qty-control input {
    width: auto;
    min-width: 40px;
    flex: 1 1 auto;
    font-size: 1.05rem;
    font-weight: 600;
    padding: .55rem .4rem;
}

.qty-control .btn {
    font-size: 1.1rem;
    line-height: 1;
    min-width: 40px;
}

#products-table th:nth-child(2),
#products-table td:nth-child(2),
#products-table th:nth-child(3),
#products-table td:nth-child(3) {
    width: 150px;
    max-width: 150px;
}

#products-table td:nth-child(3) .qty-control {
    min-width: 0;
    max-width: 150px;
    width: 150px;
}

#products-table {
    width: auto;
}

#products-table th:nth-child(1),
#products-table td:nth-child(1) {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#products-table th:nth-child(4),
#products-table td:nth-child(4),
#products-table th:nth-child(5),
#products-table td:nth-child(5),
#products-table th:nth-child(6),
#products-table td:nth-child(6) {
    width: 100px;
    max-width: 100px;
    text-align: center;
    padding-left: .75rem;
    padding-right: .75rem;
}

#products-table td:nth-child(5) .unit-price-input {
    width: 80px;
    min-width: 0;
    text-align: center;
}

@media (max-width: 768px) {
    .app {
        flex-direction: column;
        min-height: auto;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }

    .sidebar-brand {
        border-bottom: none;
        border-right: 1px solid rgba(255,255,255,.1);
        flex-shrink: 0;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .sidebar-nav a {
        white-space: nowrap;
    }

    .qty-control {
        min-width: 130px;
    }

    .qty-control input {
        font-size: 1.2rem;
        min-width: 40px;
    }

    .qty-control .btn {
        min-width: 44px;
        padding: .6rem .8rem;
    }
}

.unit-label {
    align-self: center;
    font-size: .85rem;
    color: var(--color-muted);
    white-space: nowrap;
}

.unit-label[hidden] {
    display: none;
}

.card-header .form-control {
    width: auto;
}

.btn-danger {
    background: var(--color-danger);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-success {
    background: var(--color-success);
}

.btn-purple {
    background: #7c3aed;
    color: #fff;
}
.btn-purple:hover {
    background: #6d28d9;
}

.btn-success-light {
    background: #86efac;
    color: #14532d;
}
.btn-success-light:hover {
    background: #4ade80;
}

.btn-bordeaux {
    background: #9b1c1c;
    color: #fff;
}
.btn-bordeaux:hover {
    background: #7f1d1d;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

.table-scroll {
    overflow-x: auto;
}

.table-scroll table {
    width: auto;
    min-width: 100%;
}

th, td {
    text-align: left;
    padding: .65rem .75rem;
    border-bottom: 1px solid var(--color-border);
    font-size: .9rem;
}

th {
    color: var(--color-muted);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th.sortable:hover {
    color: var(--color-text);
}

th.sortable::after {
    content: '\2195';
    margin-left: .35rem;
    opacity: .35;
}

th.sortable.sort-asc::after {
    content: '\2191';
    opacity: 1;
}

th.sortable.sort-desc::after {
    content: '\2193';
    opacity: 1;
}

tr:hover td {
    background: #fafbfc;
}

.actions {
    display: flex;
    gap: .4rem;
}

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
}

/* Badges */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-draft { background: #e5e7eb; color: #374151; }
.badge-demande_tarif { background: #ede9fe; color: #5b21b6; }
.badge-precommande { background: #fae8ff; color: #86198f; }
.badge-confirmed { background: #dbeafe; color: #1e40af; }
.badge-preparing { background: #fef3c7; color: #92400e; }
.badge-shipped { background: #dcfce7; color: #166534; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

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

.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.mb-0 { margin-bottom: 0; }
.badge-termine { background: #cffafe; color: #155e75; }

.password-field {
    position: relative;
    display: flex;
}

.password-field .form-control {
    flex: 1;
    padding-right: 2.5rem;
}

.password-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.25rem;
    opacity: 0.6;
}

.password-toggle:hover {
    opacity: 1;
}
