:root {
    --blue-dark: #0d3b66;
    --blue-main: #1565c0;
    --blue-pale: #e3ecf7;
    --gray-bg: #f5f7fa;
    --gray-border: #d9e0e8;
    --text: #1c2733;
    --danger: #e53935;
}

* { box-sizing: border-box; }

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

.topbar {
    background: var(--blue-dark);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 0;
    padding: 0.75rem 1.5rem;
}
.topbar .brand { color: #fff; text-decoration: none; font-weight: 600; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; row-gap: 0.4rem; }
.topbar nav a {
    color: #dce8fb;
    text-decoration: none;
    margin-left: 1.25rem;
    font-size: 0.95rem;
}
.topbar nav a:hover { color: #fff; }
.topbar nav .nav-user { color: #9fb8dc; margin-left: 1.25rem; font-size: 0.9rem; }

.footbar {
    background: var(--blue-dark);
    color: #9fb8dc;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.9rem 1.5rem;
    font-size: 0.8rem;
    margin-top: 2rem;
}
.footbar-summary { color: #dce8fb; font-size: 0.85rem; line-height: 1.4; }
.footbar-stats { display: flex; gap: 1.5rem; flex-wrap: wrap; color: #9fb8dc; }

main { max-width: 1300px; margin: 0 auto; padding: 1.5rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.page-head h1 { margin: 0; font-size: 1.4rem; color: var(--blue-dark); }

.page-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.flash-list { margin-bottom: 1rem; }
.flash { padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem; }
.flash-success { background: #e3f4e6; color: #1e7d34; border: 1px solid #b7e0c0; }
.flash-error { background: #fdeaea; color: #b71c1c; border: 1px solid #f3b9b9; }

.btn {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--gray-border);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
}
.btn:hover { background: var(--blue-pale); }
.btn-primary { background: var(--blue-main); color: #fff; border-color: var(--blue-main); }
.btn-primary:hover { background: #0d47a1; }
.btn-danger { color: var(--danger); border-color: #f3b9b9; }
.btn-danger:hover { background: #fdeaea; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--blue-main); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.search-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search-bar input[type=text] {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--gray-border);
    border-radius: 6px;
}
.search-bar select { padding: 0.5rem; border: 1px solid var(--gray-border); border-radius: 6px; }

.status-summary { font-size: 0.9rem; color: #45505c; margin-bottom: 0.75rem; }

.dashboard-bar { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.dash-item {
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
}
a.dash-item:hover { opacity: 0.9; }
.dash-critical { background: #e53935; }
.dash-warning { background: #fb8c00; }
.dash-info { background: var(--blue-main); }
.dashboard-ok { background: #e3f4e6; color: #1e7d34; font-weight: 500; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

thead th a { color: var(--blue-dark); text-decoration: none; }
thead th a:hover { text-decoration: underline; }
.badge { color: #fff; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }

.table-wrap { overflow-x: auto; background: #fff; border-radius: 8px; border: 1px solid var(--gray-border); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; table-layout: auto; }
thead th {
    background: var(--blue-pale);
    color: var(--blue-dark);
    text-align: left;
    padding: 0.6rem 0.7rem;
    position: sticky;
    top: 0;
    white-space: nowrap;
}
tbody td { padding: 0.55rem 0.7rem; border-top: 1px solid var(--gray-border); }
tbody tr:hover { background: #fafcff; }
.row-actions { white-space: nowrap; }
.empty { text-align: center; color: #8a94a0; padding: 1.5rem; }

/* Colonnes qui ont besoin de plus de place / de ne pas se couper */
.col-name { min-width: 200px; }
.col-status { min-width: 120px; white-space: nowrap; }
.badge { white-space: nowrap; }

.record-form { background: #fff; border: 1px solid var(--gray-border); border-radius: 8px; padding: 1.25rem; overflow-x: hidden; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
    min-width: 0;
}
.form-grid label { display: flex; flex-direction: column; font-size: 0.85rem; color: #45505c; gap: 0.3rem; min-width: 0; }
.form-grid label.full, .form-grid fieldset.full { grid-column: 1 / -1; }
.form-grid input, .form-grid textarea, .form-grid select {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--gray-border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}
.location-fields { border: 1px solid var(--gray-border); border-radius: 6px; padding: 0.75rem 1rem; min-width: 0; }
.location-fields legend { padding: 0 0.4rem; color: var(--blue-dark); font-weight: 600; }
.location-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; min-width: 0; }
.location-grid label { min-width: 0; }
.location-grid select { min-width: 0; text-overflow: ellipsis; }
.hint { font-size: 0.8rem; color: #8a94a0; margin: 0.5rem 0 0; }
a.hint { color: var(--blue-main); text-decoration: none; display: inline-block; }
a.hint:hover { text-decoration: underline; }

.barcode-preview { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; }
.barcode-preview img { max-width: 260px; border: 1px solid var(--gray-border); border-radius: 6px; background: #fff; padding: 0.4rem; }
.image-preview img { max-width: 180px; max-height: 180px; border: 1px solid var(--gray-border); border-radius: 6px; margin-top: 0.4rem; object-fit: contain; }
.image-upload-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.image-upload-row input[type=file] { max-width: 100%; }

.nav-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}
.nav-position { font-size: 0.85rem; color: #45505c; min-width: 3.5rem; text-align: center; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: #fff; }
.btn-disabled { opacity: 0.4; pointer-events: none; }

.plain-fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
.plain-fieldset:disabled .barcode-preview,
.plain-fieldset:disabled .image-preview,
.plain-fieldset:disabled a.hint { opacity: 0.7; }

.about-card { background: #fff; border: 1px solid var(--gray-border); border-radius: 8px; padding: 1.25rem; max-width: 560px; }
.about-table { border-collapse: collapse; margin: 0.75rem 0; }
.about-table td { padding: 0.4rem 0.8rem 0.4rem 0; }
.about-table td:first-child { color: #45505c; }

.import-form { display: flex; gap: 0.6rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }

.orphan-list { list-style: none; padding: 0; margin: 0; max-height: 220px; overflow-y: auto; border: 1px solid var(--gray-border); border-radius: 6px; }
.orphan-list li { padding: 0.35rem 0.6rem; border-top: 1px solid var(--gray-border); font-size: 0.85rem; }
.orphan-list li:first-child { border-top: none; }
.orphan-list label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

.scan-reader { max-width: 480px; margin: 0 auto; }

.chat-layout { display: flex; gap: 1.25rem; align-items: flex-start; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-sidebar {
    width: 180px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid var(--gray-border);
    border-radius: 8px;
    padding: 1rem;
}
.chat-sidebar h2 { font-size: 0.95rem; margin: 0 0 0.6rem; color: var(--blue-dark); }
.chat-active-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.chat-active-list li { display: flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0; }
.chat-online-dot { width: 8px; height: 8px; border-radius: 50%; background: #43a047; flex-shrink: 0; }

.chat-messages {
    background: #fff;
    border: 1px solid var(--gray-border);
    border-radius: 8px;
    padding: 1rem;
    height: 55vh;
    min-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.chat-msg { max-width: 75%; background: var(--blue-pale); border-radius: 10px; padding: 0.5rem 0.75rem; align-self: flex-start; }
.chat-msg-mine { align-self: flex-end; background: #dcefe0; }
.chat-msg-meta { font-size: 0.75rem; color: #45505c; margin-bottom: 0.2rem; display: flex; gap: 0.4rem; align-items: baseline; }
.chat-msg-text { font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; }

.chat-form { display: flex; gap: 0.6rem; margin-top: 0.75rem; }
.chat-form input[type=text] {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--gray-border);
    border-radius: 6px;
    font-size: 0.95rem;
}

@media (max-width: 700px) {
    .chat-layout { flex-direction: column; }
    .chat-sidebar { width: 100%; }
    .chat-messages { height: 45vh; }
}
.scan-result {
    max-width: 480px;
    margin: 1.5rem auto 0;
    background: #fff;
    border: 1px solid var(--gray-border);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
}
.scan-result h2 { margin: 0 0 0.5rem; color: var(--blue-dark); }
.scan-actions { display: flex; gap: 0.6rem; justify-content: center; margin: 1rem 0; flex-wrap: wrap; }
.scan-actions .btn { font-size: 1.1rem; padding: 0.5rem 1rem; }
.scan-resume { display: block; margin: 0.5rem auto 0; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { background: #fff; border: 1px solid var(--gray-border); border-radius: 10px; padding: 2rem; width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { margin: 0 0 0.2rem; color: var(--blue-dark); font-size: 1.3rem; }
.login-form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1rem; text-align: left; }
.login-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: #45505c; gap: 0.3rem; }
.login-form input { padding: 0.55rem 0.7rem; border: 1px solid var(--gray-border); border-radius: 6px; font-size: 0.95rem; }
.login-form .btn { margin-top: 0.4rem; }

.form-actions { margin-top: 1.25rem; display: flex; gap: 0.6rem; }

.zones-grid { display: flex; flex-direction: column; gap: 1rem; max-width: 640px; }
.zone-card { background: #fff; border: 1px solid var(--gray-border); border-radius: 8px; padding: 1.25rem; min-width: 0; overflow-x: hidden; }
.zone-card h2 { margin: 0 0 0.75rem; font-size: 1.1rem; color: var(--blue-dark); }
.zone-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 0.85rem; table-layout: fixed; }
.zone-table td { padding: 0.45rem 0.3rem; border-top: 1px solid var(--gray-border); overflow: hidden; }
.zone-table td:first-child { text-align: center; color: #45505c; font-variant-numeric: tabular-nums; }
.zone-table td:last-child { padding-right: 0; overflow: visible; }
.inline-form { display: flex; gap: 0.5rem; min-width: 0; }
.inline-form input[type=text] { flex: 1; min-width: 0; padding: 0.4rem 0.6rem; border: 1px solid var(--gray-border); border-radius: 5px; }
.add-location-form { display: flex; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }
.add-location-form input { padding: 0.5rem 0.6rem; border: 1px solid var(--gray-border); border-radius: 5px; min-width: 0; }
.add-location-form input[name=code] { width: 60px; flex: 0 0 60px; }
.add-location-form input[name=name] { flex: 1 1 160px; min-width: 120px; }

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .location-grid { grid-template-columns: 1fr; }
    .zones-grid { max-width: 100%; }
    .topbar { padding: 0.65rem 1rem; }
    .topbar nav a, .topbar nav .nav-user { margin-left: 0; margin-right: 1rem; }
    main { padding: 1rem; }
    .page-head h1 { font-size: 1.2rem; }
}

/* Liste des articles : tableau -> cartes empilées sur petit écran */
@media (max-width: 640px) {
    .table-wrap { overflow-x: visible; border: none; background: transparent; }
    table { border: none; }
    thead { display: none; }

    tbody tr {
        display: block;
        background: #fff;
        border: 1px solid var(--gray-border);
        border-radius: 8px;
        margin-bottom: 0.75rem;
        padding: 0.7rem 0.9rem;
    }
    tbody tr:hover { background: #fff; }

    tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.3rem 0;
        border-top: 1px solid #eef1f5;
        text-align: right;
    }
    tbody td:first-of-type { border-top: none; }
    tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--blue-dark);
        text-align: left;
        flex-shrink: 0;
        font-size: 0.8rem;
    }

    /* Le nom sert d'en-tête de carte : pas de label, plus grand, à gauche */
    tbody td.col-name {
        justify-content: flex-start;
        border-top: none;
        padding-bottom: 0.5rem;
        margin-bottom: 0.3rem;
        border-bottom: 1px solid #eef1f5;
    }
    tbody td.col-name::before { display: none; }
    tbody td.col-name a { font-size: 1.05rem; font-weight: 600; }

    /* Colonne Id peu utile au quotidien : masquée sur mobile */
    tbody td[data-label="Id"] { display: none; }

    tbody td.row-actions {
        justify-content: flex-end;
        gap: 0.5rem;
        border-top: 1px solid #eef1f5;
        padding-top: 0.6rem;
        margin-top: 0.3rem;
    }
    tbody td.row-actions::before { display: none; }

    .status-summary { font-size: 0.85rem; }
}

/* Sauvegardes (page Maintenance) : tableau -> cartes sur petit écran */
@media (max-width: 560px) {
    .backups-table, .backups-table tbody, .backups-table tr, .backups-table td { display: block; width: auto; }
    .backups-table thead { display: none; }
    .backups-table tr {
        border: 1px solid var(--gray-border);
        border-radius: 8px;
        margin-bottom: 0.6rem;
        padding: 0.6rem 0.8rem;
    }
    .backups-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.3rem 0;
        border-top: 1px solid #eef1f5;
        text-align: right;
    }
    .backups-table td:first-child { border-top: none; }
    .backups-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--blue-dark);
        text-align: left;
        flex-shrink: 0;
        font-size: 0.8rem;
    }
    .backups-table td[data-label="Fichier"] { word-break: break-all; }
    .backups-table td.row-actions {
        justify-content: flex-end;
        border-top: 1px solid #eef1f5;
        padding-top: 0.5rem;
        margin-top: 0.2rem;
    }
    .backups-table td.row-actions::before { display: none; }
}
