/* =========================================================================
   Books Sell — design system
   Plain CSS (no framework). Tokens + layout shell + components.
   ========================================================================= */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-weak: #eef2ff;

    --success: #16a34a;
    --success-hover: #15803d;
    --warning: #d97706;
    --danger: #dc2626;

    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #64748b;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .07);
    --shadow: 0 4px 16px rgba(15, 23, 42, .07);
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, .18);

    --topbar-h: 62px;
    --sidebar-w: 252px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
}

/* ---------- Typography ---------- */
.content h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -.02em;
    margin: 0 0 4px;
}

.content h2 {
    font-size: 17px;
    font-weight: 650;
    margin: 0 0 12px;
}

.content section+section,
.content .table-wrap+* {
    margin-top: 0;
}

/* The intro paragraph right under a page title becomes a subtitle */
.content>h1+p {
    margin: 0 0 22px;
    color: var(--muted);
    max-width: 70ch;
}

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

.small {
    font-size: 12.5px;
}

.muted.small,
.small.muted {
    color: var(--muted);
}

.link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.link:hover {
    text-decoration: underline;
}

/* ---------- Buttons ---------- */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s, color .15s;
}

button:hover,
.btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

button:active,
.btn:active {
    transform: translateY(1px);
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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

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

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--primary-weak);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* ---------- Forms ---------- */
input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}

input::placeholder {
    color: #94a3b8;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-weak);
}

select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

/* =========================================================================
   App shell : sidebar + topbar + content
   ========================================================================= */
.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    height: var(--topbar-h);
    padding: 0 20px;
    color: #fff;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -.01em;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    flex-shrink: 0;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -.03em;
}

.sidebar-nav {
    flex: 1;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
}

.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--sidebar-muted);
    padding: 14px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 9px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .85;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-foot {
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    font-size: 12px;
    color: var(--sidebar-muted);
    flex-shrink: 0;
}

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 35;
}

.main-area {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 22px;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border);
}

.nav-toggle {
    display: none;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    padding: 6px;
    border-radius: 8px;
}

.nav-toggle:hover {
    background: var(--surface-2);
    border-color: var(--border);
}

.topbar-brand {
    display: none;
    font-weight: 700;
    font-size: 16px;
}

.topbar-spacer {
    flex: 1;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip form {
    margin: 0;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-weak);
    color: var(--primary);
    font-weight: 700;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-weight: 600;
    font-size: 13.5px;
}

.user-role {
    font-size: 11.5px;
    color: var(--muted);
    text-transform: capitalize;
}

.logout-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 7px 12px;
    font-weight: 500;
    font-size: 13px;
}

.logout-btn:hover {
    background: var(--surface-2);
    color: var(--danger);
    border-color: var(--danger);
}

.content {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px;
    flex: 1;
}

/* =========================================================================
   Auth (login) layout
   ========================================================================= */
.auth-body {
    background:
        radial-gradient(1200px 500px at 100% -10%, #e0e7ff 0%, transparent 55%),
        radial-gradient(1000px 500px at -10% 110%, #dbeafe 0%, transparent 55%),
        var(--bg);
    min-height: 100vh;
}

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 410px;
    background: var(--surface);
    padding: 32px 30px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.login-head {
    text-align: center;
    margin-bottom: 22px;
}

.login-head .brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    font-size: 18px;
    margin-bottom: 14px;
}

.login-head h1 {
    font-size: 22px;
    margin: 0 0 6px;
}

.login-head p {
    margin: 0;
    color: var(--muted);
    font-size: 13.5px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.test-users {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.test-users-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: 10px;
}

.test-users ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.test-users li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--muted);
}

/* =========================================================================
   Cards, stats, dashboard
   ========================================================================= */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 26px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.stat-value {
    font-size: 28px;
    font-weight: 750;
    letter-spacing: -.02em;
    margin: 6px 0 2px;
}

.stat-hint {
    font-size: 12px;
    color: var(--muted);
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 18px;
    margin-top: 8px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
}

.area-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.area-card h2 {
    margin: 4px 0 0;
    font-size: 17px;
}

.area-card p {
    margin: 0;
    color: var(--muted);
    font-size: 13.5px;
    flex: 1;
}

.area-card .btn,
.area-card a.btn-outline {
    align-self: flex-start;
    margin-top: 8px;
}

.area-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--primary-weak);
    color: var(--primary);
}

.area-icon svg {
    width: 22px;
    height: 22px;
}

.area-coursier {
    background: #dbeafe;
    color: #1d4ed8;
}

.area-envoyeur {
    background: #ccfbf1;
    color: #0f766e;
}

.area-admin {
    background: #ede9fe;
    color: #6d28d9;
}

.area-profil {
    background: #fef3c7;
    color: #b45309;
}

/* =========================================================================
   Flash / alerts
   ========================================================================= */
.flash,
.alert {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 14px;
    border: 1px solid transparent;
}

.flash-success {
    background: #dcfce7;
    color: #166534;
    border-color: #bbf7d0;
}

.flash-error,
.alert {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}

.flash-warning {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    -webkit-overflow-scrolling: touch;
}

.data-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13.5px;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    white-space: nowrap;
}

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

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
    z-index: 1;
}

.data-table .cell-ad,
.data-table .cell-book {
    white-space: normal;
    min-width: 190px;
    max-width: 290px;
}

.data-table .ad-title {
    font-weight: 600;
}

.data-table form {
    margin: 0;
}

.status-select {
    width: auto;
    min-width: 165px;
    padding: 8px 30px 8px 11px;
    font-size: 13px;
    font-weight: 500;
}

.thumb {
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 8px;
}

/* =========================================================================
   Badges & role pills
   ========================================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    background: #e2e8f0;
    color: #475569;
    white-space: nowrap;
}

.badge-new {
    background: #e2e8f0;
    color: #475569;
}

.badge-processed {
    background: #dbeafe;
    color: #1e40af;
}

.badge-momox_done {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-candidate {
    background: #fef3c7;
    color: #92400e;
}

.badge-open {
    background: #dcfce7;
    color: #166534;
}

.badge-taken {
    background: #fef9c3;
    color: #854d0e;
}

.badge-delivered {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-sent {
    background: #ccfbf1;
    color: #115e59;
}

.badge-bad {
    background: #fee2e2;
    color: #991b1b;
}

.badge-momox_title_mismatch {
    background: #ffedd5;
    color: #9a3412;
}

.badge-momox {
    background: #cffafe;
    color: #155e75;
    text-transform: capitalize;
}

.badge-gibert {
    background: #fce7f3;
    color: #9d174d;
    text-transform: capitalize;
}

.role-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: capitalize;
    background: var(--primary-weak);
    color: var(--primary);
}

.role-admin {
    background: #ede9fe;
    color: #6d28d9;
}

.role-coursier {
    background: #dbeafe;
    color: #1d4ed8;
}

.role-envoyeur {
    background: #ccfbf1;
    color: #0f766e;
}

/* =========================================================================
   Ad cards (coursier / envoyeur)
   ========================================================================= */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 18px;
    margin-top: 14px;
}

.ad-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: box-shadow .18s, transform .18s;
}

.ad-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.ad-card-img {
    width: 100%;
    height: 168px;
    object-fit: cover;
    background: var(--surface-2);
}

.ad-card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: 1;
}

.ad-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.ad-card-body h3 {
    margin: 0;
    font-size: 15.5px;
    line-height: 1.3;
}

.ad-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
    flex-wrap: wrap;
}

.price {
    font-weight: 700;
    color: var(--text);
    font-size: 15px;
}

.book-list {
    margin: 2px 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.book-list li {
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.book-li-title {
    font-weight: 600;
}

.ad-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: auto;
    padding-top: 4px;
}

.ad-card-actions form {
    margin: 0;
}

/* =========================================================================
   Envoyeur extras
   ========================================================================= */
.kv {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 13px;
}

.ad-ref {
    border-top: 1px solid var(--border);
    padding-top: 9px;
    margin-top: 2px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.send-form {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.send-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 120px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
}

.send-form button {
    width: 100%;
}

/* =========================================================================
   Profile
   ========================================================================= */
.profile-section {
    margin-top: 30px;
}

.profile-card {
    margin-top: 4px;
}

.profile-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.avatar-lg {
    width: 52px;
    height: 52px;
    font-size: 20px;
}

.profile-name {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.profile-details {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.profile-details div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.profile-details dt {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.profile-details dd {
    margin: 0;
    font-weight: 600;
    word-break: break-word;
}

.simple-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.simple-list li {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 13px 15px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

/* =========================================================================
   Empty states
   ========================================================================= */
.placeholder {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 34px 22px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    margin-top: 12px;
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open~.nav-overlay,
    .nav-overlay.open {
        display: block;
    }

    .main-area {
        margin-left: 0;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .topbar-brand {
        display: inline-flex;
        align-items: center;
        gap: 9px;
    }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .content {
        padding: 18px 16px;
    }

    .user-meta {
        display: none;
    }

    .logout-label {
        display: none;
    }

    .logout-btn {
        padding: 8px;
    }

    .cards {
        grid-template-columns: 1fr;
    }

    .ad-grid {
        grid-template-columns: 1fr;
    }

    .content h1 {
        font-size: 21px;
    }
}

@media (max-width: 420px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   Admin — validation hiérarchique (annonce parent + livres enfants)
   ========================================================================= */
.ad-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 22px;
    overflow: hidden;
}

.ad-block-head {
    display: flex;
    gap: 18px;
    padding: 18px;
    border-bottom: 1px solid var(--border);
}

.ad-block-img {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    flex-shrink: 0;
}

.ad-block-img--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 12.5px;
    border: 1px dashed var(--border);
}

.ad-block-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.ad-block-titlerow {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.ad-block-titlerow h2 {
    margin: 0;
    font-size: 18px;
}

.ad-block-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    color: var(--text);
}

.ad-block-meta .dot {
    color: var(--muted);
}

.ad-price {
    font-weight: 700;
}

.ad-block-desc {
    margin: 0;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.5;
    max-height: 4.5em;
    overflow: auto;
    border-left: 3px solid var(--border);
    padding-left: 10px;
}

.ad-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 2px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 12.5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
}

.chip strong {
    color: var(--text);
}

.chip-ok {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

.chip-ok strong {
    color: #166534;
}

.chip-bad {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

.chip-bad strong {
    color: #991b1b;
}

.chip-warn {
    background: #ffedd5;
    border-color: #fed7aa;
    color: #9a3412;
}

.chip-warn strong {
    color: #9a3412;
}

/* Nested books table */
.nested-books {
    font-size: 13px;
}

.nested-books .book-title {
    font-weight: 600;
}

.nested-books .cell-book {
    min-width: 200px;
    max-width: 320px;
}

/* Title mismatch row */
.row-mismatch {
    background: #fff7ed;
}

.row-mismatch:hover {
    background: #ffedd5 !important;
}

/* Negative profit */
.profit-negative {
    color: var(--danger);
    font-weight: 700;
}

/* Per-book decision buttons */
.decision-form {
    display: inline-flex;
    gap: 6px;
    margin: 0;
}

.btn-mini {
    padding: 5px 11px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
}

.btn-mini:hover {
    background: var(--surface-2);
    border-color: var(--muted);
    color: var(--text);
}

.btn-mini-ok.is-active {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.btn-mini-bad.is-active {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* Ad footer + final validation */
.ad-block-foot {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 16px 18px;
    background: var(--surface-2);
}

.validate-form {
    margin: 0;
}

.btn-validate {
    background: var(--success);
    border-color: var(--success);
    padding: 11px 20px;
    font-size: 14.5px;
}

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

.btn-validate:disabled {
    background: var(--border);
    border-color: var(--border);
    color: var(--muted);
    cursor: not-allowed;
    transform: none;
}

.ad-foot-state {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    color: var(--muted);
}

/* Safe colours for a few backend automation statuses (others fall back to grey) */
.badge-momox_price_found {
    background: #dcfce7;
    color: #166534;
}

.badge-momox_no_price {
    background: #fef3c7;
    color: #92400e;
}

.badge-momox_pending,
.badge-momox_pending_duplicate {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-isbn_weak,
.badge-isbn_not_found {
    background: #ffedd5;
    color: #9a3412;
}

@media (max-width: 700px) {
    .ad-block-head {
        flex-direction: column;
    }

    .ad-block-img {
        width: 100%;
        height: 180px;
    }
}

/* =========================================================================
   Admin cockpit — patch 2 (preview, collapse, actions, image modal)
   ========================================================================= */

.zoomable {
    cursor: zoom-in;
}

.ad-image-button {
    position: relative;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
    border-radius: 14px;
    overflow: hidden;
}

.ad-image-button .ad-block-img {
    display: block;
}

.ad-image-count {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.78);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.img-modal-nav {
    position: fixed;
    top: 50%;
    z-index: 10001;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #111827;
    font-size: 38px;
    line-height: 1;
    cursor: pointer;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-modal-prev {
    left: 24px;
}

.img-modal-next {
    right: 24px;
}

.img-modal-counter {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 10001;
    transform: translateX(-50%);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.78);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

@media (max-width: 700px) {
    .img-modal-nav {
        width: 42px;
        height: 42px;
        font-size: 32px;
    }

    .img-modal-prev {
        left: 10px;
    }

    .img-modal-next {
        right: 10px;
    }

    .img-modal-counter {
        bottom: 14px;
    }
}

/* Book image preview zone (right of the ad header) */
.ad-preview {
    width: 172px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
}

.ad-preview-img {
    max-width: 100%;
    max-height: 150px;
    border-radius: 6px;
    object-fit: contain;
}

.ad-preview-empty {
    font-size: 12px;
    color: var(--muted);
}

.ad-preview-caption {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    word-break: break-word;
}

/* Collapse / expand toolbar */
.ad-block-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.toggle-books {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 13px;
}

.toggle-books:hover {
    background: var(--surface-2);
    border-color: var(--muted);
}

.ad-books.is-collapsed {
    display: none;
}

/* Header action buttons */
.ad-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.inline-form {
    margin: 0;
}

.btn-send {
    background: var(--success);
    border-color: var(--success);
    padding: 10px 18px;
}

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

.btn-send:disabled {
    background: var(--border);
    border-color: var(--border);
    color: var(--muted);
    cursor: not-allowed;
    transform: none;
}

.btn-cancel {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-cancel:hover {
    background: var(--danger);
    color: #fff;
}

.btn-close-ad {
    background: var(--text);
    border-color: var(--text);
}

.btn-close-ad:hover {
    background: #000;
    border-color: #000;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.pill-open {
    background: #dcfce7;
    color: #166534;
}

.pill-locked {
    background: #e2e8f0;
    color: #475569;
}

/* Profit cell colours (profit-negative already defined) */
.profit-positive {
    color: var(--success);
    font-weight: 700;
}

/* Clickable book rows (preview) */
.book-row {
    cursor: pointer;
}

.book-row:hover {
    background: var(--surface-2);
}

.book-row.row-selected,
.book-row.row-selected:hover {
    background: var(--primary-weak);
    box-shadow: inset 3px 0 0 var(--primary);
}

/* "Achetables" summary chip */
.chip-buy {
    background: #e0f2fe;
    border-color: #bae6fd;
    color: #075985;
}

.chip-buy strong {
    color: #075985;
}

/* Closed ad badge */
.badge-closed {
    background: #334155;
    color: #fff;
}

/* Image zoom modal */
.img-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(2, 6, 23, .82);
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.img-modal.open {
    display: flex;
}

.img-modal-img {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.img-modal-close {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 26px;
    line-height: 1;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .3);
    color: #fff;
}

.img-modal-close:hover {
    background: rgba(255, 255, 255, .25);
}

@media (max-width: 700px) {
    .ad-preview {
        width: 100%;
    }

    .ad-preview-img {
        max-height: 220px;
    }
}


.ad-header-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
    font-size: 12px;
    font-weight: 600;
}

.meta-pill strong {
    color: #0f172a;
}

.nav-section {
    margin-top: 10px;
}

.nav-section-title {
    padding: 10px 14px 6px;
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-subitem {
    padding-left: 22px;
}


.text-center {
    text-align: center;
}

.decision-cell {
    min-width: 150px;
    text-align: center;
    vertical-align: middle;
}

.decision-title {
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.decision-form {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.panel {
    margin-top: 24px;
    padding: 24px;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.panel h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 18px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-field label {
    font-weight: 700;
    color: #0f172a;
}

.form-field input {
    min-height: 46px;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    font-size: 15px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.btn-primary {
    align-self: flex-start;
    border: 0;
    border-radius: 12px;
    padding: 12px 18px;
    background: #4f46e5;
    color: white;
    font-weight: 800;
    cursor: pointer;
}

.btn-primary:hover {
    background: #4338ca;
}

.flash-success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #166534;
}

.brand-logo-img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 10px;
}