/* Premium Library Overrides */
.mobile-display-controls { display: none; }
@media (max-width: 768px) {
    .mobile-display-controls {
        display: flex;
        gap: 8px;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
    }
    .mobile-display-controls .btn {
        flex: 1 1 0;
        min-width: 0;
        white-space: normal;
    }
}
.access-mode-open { color: #166534; }
.access-mode-semi-open { color: #2563eb; }
.access-mode-closed { color: #dc2626; }
[data-theme="dark"] .access-mode-open { color: #86efac; }
[data-theme="dark"] .access-mode-semi-open { color: #93c5fd; }
[data-theme="dark"] .access-mode-closed { color: #fca5a5; }
.btn-success { background-color: #047857; color: #fff; }
.report-stat-row.text-warning,
.report-stat-row.text-warning span { color: #92400e !important; }
[data-theme="dark"] .report-stat-row.text-warning,
[data-theme="dark"] .report-stat-row.text-warning span { color: #fbbf24 !important; }
.layout-content p a:not(.btn) { text-decoration: underline; text-underline-offset: 2px; }
.table-responsive:focus-visible { outline: 3px solid var(--color-primary-hover); outline-offset: 2px; }
/* Bootstrap text utilities retain light-theme ink unless explicitly adapted. */
[data-theme="dark"] {
    --bs-secondary-color: #cbd5e1;
    --bs-body-color: #f8fafc;
    --bs-link-color: #c7d2fe;
}
[data-theme="dark"] .text-muted,
[data-theme="dark"] .small.text-muted { color: #cbd5e1 !important; }
[data-theme="dark"] .text-danger { color: #fca5a5 !important; }
[data-theme="dark"] .text-success { color: #86efac !important; }
[data-theme="dark"] code { color: #f9a8d4; }
[data-theme="dark"] .layout-content a:not(.btn) { color: #c7d2fe !important; }
[data-theme="dark"] .sidebar-nav a.active,
[data-theme="dark"] .badge-primary { color: #c7d2fe !important; }
[data-theme="dark"] .file-drop-zone-hint strong,
[data-theme="dark"] .btn-outline { color: #c7d2fe; }
[data-theme="dark"] .btn-outline:hover { color: #fff; }
.ts-control {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Branch-scoped stock review: each decision must stay readable on a phone. */
.stock-candidate-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stock-candidate {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-primary, #fff);
}
.stock-candidate h5 { margin: 0 0 8px; overflow-wrap: anywhere; }
.stock-candidate p { margin: 0 0 10px; overflow-wrap: anywhere; }
.stock-candidate code { overflow-wrap: anywhere; }
.stock-candidate textarea { width: 100%; min-height: 80px; }
.stock-review-confirm { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; }
.stock-review-confirm input { flex: 0 0 auto; margin-top: 4px; }
.stock-candidate-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stock-candidate-actions .btn { flex: 1 1 165px; white-space: normal; }
.writeoff-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: var(--spacing-lg, 24px);
}
.writeoff-charge-confirm { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; }
.writeoff-charge-confirm input { flex: 0 0 auto; margin-top: 4px; }
.ts-dropdown {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    z-index: 1050;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.ts-dropdown .option {
    color: var(--text-primary);
}
[data-theme='dark'] .ts-control {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}
[data-theme='dark'] .ts-dropdown {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}
[data-theme='dark'] .ts-control input {
    color: var(--text-primary);
}
.flatpickr-calendar {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}
.flatpickr-day.selected {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* ---------------------------------------------------------------------------
   Notification bell (portal navbar)
   --------------------------------------------------------------------------- */
.notif-bell {
    position: relative;
    display: inline-flex;
}
.notif-bell-btn {
    position: relative;
}
.notif-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--color-danger, #ef4444);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.notif-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 340px;
    max-width: calc(100vw - 24px);
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    box-shadow: var(--shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.15));
    z-index: 1100;
    overflow: hidden;
}
.notif-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.notif-panel-body {
    max-height: 380px;
    overflow-y: auto;
}
.notif-item {
    display: flex;
    gap: 10px;
    padding: 11px 14px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.notif-item:last-child {
    border-bottom: 0;
}
.notif-item:hover {
    background: var(--bg-secondary, #f8fafc);
}
.notif-item.notif-unread {
    background: color-mix(in srgb, var(--color-primary, #6366f1) 7%, transparent);
}
.notif-icon {
    flex: 0 0 20px;
    padding-top: 2px;
}
.notif-icon svg {
    width: 18px;
    height: 18px;
}
.notif-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.notif-title {
    font-weight: 600;
    font-size: 0.9rem;
}
.notif-body {
    font-size: 0.82rem;
    color: var(--text-muted, #6b7280);
}
.notif-time {
    font-size: 0.74rem;
    color: var(--text-muted, #9ca3af);
}
.notif-empty {
    margin: 0;
    padding: 26px 14px;
    text-align: center;
    color: var(--text-muted, #6b7280);
    font-size: 0.88rem;
}

/* Book editing needs full-width controls on a phone; the former inline grid stayed two-column. */
.book-editor-layout {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--spacing-lg);
}
.book-editor-layout > * { min-width: 0; }
@media (max-width: 767px) {
    .book-editor-layout { grid-template-columns: minmax(0, 1fr); }
}

.navbar-brand .brand-logo-header { display: block; width: auto; height: 2rem; max-width: 3.5rem; object-fit: contain; flex: 0 0 auto; }
.brand-logo-preview { display: block; max-width: min(100%, 20rem); max-height: 8rem; object-fit: contain; }

/* Buyer names vary; keep the mobile management header inside the viewport. */
@media (max-width: 767px) {
    .navbar-container > .flex { min-width: 0; max-width: 100%; }
    .navbar-container .navbar-brand { min-width: 0; }
    .navbar-container .navbar-brand > span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .navbar-container .navbar-brand > span > .text-muted { display: none; }
    .navbar-container .navbar-brand > svg { flex: 0 0 auto; }
}

/* Show every notification channel without a hidden horizontal table on phones. */
.notification-queue-details {
    margin-top: var(--spacing-lg, 24px);
    padding: var(--spacing-md, 16px);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
}
.notification-queue-details > summary {
    cursor: pointer;
    font-weight: 700;
}
.notification-queue-details[open] > summary { margin-bottom: var(--spacing-lg, 24px); }
@media (max-width: 767px) {
    .readiness-checks,
    .readiness-checks tbody { display: block; width: 100%; }
    .readiness-checks thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    .readiness-checks tbody tr {
        display: block;
        margin: 0 0 12px;
        padding: 12px;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: var(--radius-md, 8px);
        background: var(--bg-primary, #fff);
    }
    .readiness-checks tbody th,
    .readiness-checks tbody td {
        display: block;
        width: 100%;
        padding: 0;
        border: 0;
        overflow-wrap: anywhere;
        white-space: normal;
    }
    .readiness-checks tbody th { margin-bottom: 8px; text-align: left; }
    .readiness-checks tbody td + td { margin-top: 8px; }
    .readiness-checks tbody td:empty { display: none; }
    .readiness-checks tbody td::before {
        content: attr(data-column-label) ': ';
        color: var(--text-muted, #6b7280);
        font-weight: 600;
    }
    .notification-event-matrix,
    .notification-event-matrix tbody {
        display: block;
        width: 100%;
    }
    .notification-event-matrix thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    .notification-event-matrix tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: 12px;
        margin-bottom: 12px;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: var(--radius-md, 8px);
        background: var(--bg-primary, #fff);
    }
    .notification-event-matrix tbody th[scope="row"],
    .notification-event-matrix tbody td:first-of-type {
        grid-column: 1 / -1;
        display: block;
        padding: 0;
        border: 0;
        white-space: normal;
        background: transparent;
    }
    .notification-event-matrix tbody th[scope="row"] {
        color: var(--text-primary, #111827);
        font-size: 0.95rem;
    }
    .notification-event-matrix tbody td:first-of-type {
        color: var(--text-muted, #6b7280);
        font-size: 0.8rem;
        line-height: 1.4;
    }
    .notification-event-matrix tbody td:not(:first-of-type) {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
        min-width: 0;
        padding: 9px;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: var(--radius-sm, 6px);
    }
    .notification-event-matrix tbody td:not(:first-of-type)::before {
        content: attr(data-column-label);
        overflow-wrap: anywhere;
        font-size: 0.78rem;
    }
    .notification-event-matrix tbody td input[type="checkbox"] {
        flex: 0 0 auto;
        width: 18px;
        height: 18px;
        margin: 0;
    }
}

.notification-matrix-tools[hidden],
.notification-event-matrix tbody tr[hidden] {
    display: none !important;
}
.notification-event-matrix td[data-event="system.queue_stalled"] a {
    text-decoration: underline;
    text-underline-offset: 2px;
}
.notification-matrix-tools {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(140px, 1fr) auto;
    gap: 10px 14px;
    align-items: end;
    margin: 0 0 14px;
    padding: 14px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-primary, #fff);
}
.notification-matrix-tool label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}
.notification-matrix-tools p {
    grid-column: 1 / -1;
    margin: 0;
    line-height: 1.4;
}
#notification-matrix-count {
    font-weight: 600;
}

@media (max-width: 767px) {
    .notification-matrix-tools {
        grid-template-columns: 1fr;
        padding: 12px;
        position: sticky;
        top: 0;
        z-index: 20;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    }
    #notification-matrix-clear {
        justify-self: start;
    }
}
