/* ============================================================
   BillPilot — Professional Blue/Slate Theme
   Bootstrap 5 CSS variable overrides + custom layout styles
   ============================================================ */

/* --- Brand Palette --- */
:root {
    --bp-primary: #2563eb;
    --bp-primary-hover: #1d4ed8;
    --bp-primary-light: #dbeafe;
    --bp-sidebar-bg: #0f172a;
    --bp-sidebar-hover: #1e293b;
    --bp-sidebar-active: #1e3a5f;
    --bp-sidebar-text: #94a3b8;
    --bp-sidebar-text-active: #ffffff;
    --bp-sidebar-width: 250px;
    --bp-topbar-height: 56px;
    --bp-body-bg: #f1f5f9;
    --bp-card-border: #e2e8f0;
    --bp-text-heading: #0f172a;
    --bp-text-body: #334155;
    --bp-text-muted: #64748b;
}

/* --- Bootstrap Overrides --- */
body {
    background-color: var(--bp-body-bg);
    color: var(--bp-text-body);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--bp-text-heading);
}

.text-muted {
    color: var(--bp-text-muted) !important;
}

.btn-primary {
    background-color: var(--bp-primary);
    border-color: var(--bp-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--bp-primary-hover);
    border-color: var(--bp-primary-hover);
}

.btn-outline-primary {
    color: var(--bp-primary);
    border-color: var(--bp-primary);
}
.btn-outline-primary:hover, .btn-outline-primary:focus {
    background-color: var(--bp-primary);
    border-color: var(--bp-primary);
    color: #fff;
}

a {
    color: var(--bp-primary);
}
a:hover {
    color: var(--bp-primary-hover);
}

/* --- Sidebar --- */
.bp-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--bp-sidebar-width);
    background: var(--bp-sidebar-bg);
    z-index: 1030;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.25s ease;
}

.bp-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 1.25rem 1.25rem 1rem;
    text-decoration: none;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}
.bp-sidebar-brand:hover {
    color: #fff;
}

.bp-sidebar-brand .brand-icon {
    width: 32px;
    height: 32px;
    background: var(--bp-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bp-sidebar-brand .brand-icon svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

.bp-nav {
    list-style: none;
    padding: 0.5rem 0.75rem;
    margin: 0;
    flex: 1;
}

.bp-nav-item {
    margin-bottom: 2px;
}

.bp-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--bp-sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
.bp-nav-link:hover {
    background: var(--bp-sidebar-hover);
    color: #e2e8f0;
}
.bp-nav-link.active {
    background: var(--bp-sidebar-active);
    color: var(--bp-sidebar-text-active);
}
.bp-nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}
.bp-nav-link.active svg {
    opacity: 1;
}

.bp-nav-section {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 1.25rem 0.75rem 0.375rem;
}

.bp-sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid #1e293b;
    flex-shrink: 0;
}

.bp-user-info {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.5rem;
    border-radius: 6px;
    color: var(--bp-sidebar-text);
    font-size: 0.8125rem;
}

.bp-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.bp-user-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #cbd5e1;
}

.bp-logout-btn {
    background: none;
    border: none;
    color: var(--bp-sidebar-text);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bp-logout-btn:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

/* --- Org Switcher --- */
.bp-org-switcher {
    padding: 0 0.75rem 0.5rem;
    position: relative;
}

.bp-org-switcher-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    background: var(--bp-sidebar-hover);
    border: 1px solid #334155;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    text-align: left;
}
.bp-org-switcher-btn:hover {
    background: #334155;
    border-color: #475569;
}

.bp-org-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--bp-sidebar-text);
}

.bp-org-current-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bp-org-chevron {
    flex-shrink: 0;
    color: var(--bp-sidebar-text);
    transition: transform 0.2s ease;
}
.bp-org-switcher.open .bp-org-chevron {
    transform: rotate(180deg);
}

.bp-org-dropdown {
    display: none;
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    top: 100%;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    z-index: 1040;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    max-height: 280px;
    overflow-y: auto;
}
.bp-org-switcher.open .bp-org-dropdown {
    display: block;
}

.bp-org-list {
    padding: 0.375rem;
}

.bp-org-item {
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: background 0.1s ease;
}
.bp-org-item:hover {
    background: #334155;
}
.bp-org-item.active {
    background: rgba(37, 99, 235, 0.15);
}

.bp-org-switch-form {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.bp-org-item-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    padding: 0.4375rem 0.5rem;
    background: none;
    border: none;
    color: #cbd5e1;
    font-size: 0.8125rem;
    cursor: pointer;
    text-align: left;
}
.bp-org-item-btn:hover {
    color: #fff;
}

.bp-org-check {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--bp-primary);
}

.bp-org-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bp-role-badge {
    font-size: 0.625rem;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.bp-role-admin {
    background: rgba(37, 99, 235, 0.2);
    color: #93c5fd;
}
.bp-role-reviewer {
    background: rgba(234, 179, 8, 0.2);
    color: #fde68a;
}
.bp-role-viewer {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
}

.bp-org-star {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s ease;
}
.bp-org-star:hover {
    color: #fbbf24;
}
.bp-org-star.is-default {
    color: #fbbf24;
}

.bp-org-create-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    color: var(--bp-sidebar-text);
    font-size: 0.8125rem;
    text-decoration: none;
    border-top: 1px solid #334155;
}
.bp-org-create-link:hover {
    color: #e2e8f0;
    background: #334155;
}

/* Org dropdown scrollbar */
.bp-org-dropdown::-webkit-scrollbar {
    width: 4px;
}
.bp-org-dropdown::-webkit-scrollbar-track {
    background: transparent;
}
.bp-org-dropdown::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 2px;
}

/* --- Main Content --- */
.bp-main {
    margin-left: var(--bp-sidebar-width);
    min-height: 100vh;
}

/* Unauthenticated pages (login/register) use full width */
.bp-main-full {
    margin-left: 0;
}

/* --- Page Header --- */
.bp-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.bp-page-header h2 {
    margin-bottom: 0.125rem;
    font-size: 1.5rem;
    font-weight: 700;
}
.bp-page-header .bp-page-subtitle {
    color: var(--bp-text-muted);
    font-size: 0.875rem;
    margin-bottom: 0;
}

/* --- Cards --- */
.card {
    border: 1px solid var(--bp-card-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card-header {
    background-color: #fff;
    border-bottom: 1px solid var(--bp-card-border);
    font-weight: 600;
}

/* Stat cards */
.bp-stat-card {
    border: 1px solid var(--bp-card-border);
    border-radius: 8px;
    background: #fff;
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s ease;
}
.bp-stat-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.bp-stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bp-text-muted);
    margin-bottom: 0.25rem;
}
.bp-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0;
}

/* --- Loading state --- */
.bp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--bp-text-muted);
}
.bp-loading .spinner-border {
    width: 1.25rem;
    height: 1.25rem;
    border-width: 2px;
}

/* --- Alert / Error consistency --- */
.alert {
    border-radius: 8px;
    border: none;
    font-size: 0.875rem;
}
.alert-success {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.alert-danger {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.alert-warning {
    background-color: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}
.alert-info {
    background-color: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* --- Empty state --- */
.bp-empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--bp-text-muted);
}
.bp-empty-state svg {
    opacity: 0.4;
    margin-bottom: 1rem;
}
.bp-empty-state p {
    margin-bottom: 0.5rem;
}

/* --- Tables --- */
.table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bp-text-muted);
}

/* --- Badge polish --- */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.3em 0.6em;
    border-radius: 4px;
}

/* --- Breadcrumb --- */
.breadcrumb {
    font-size: 0.8125rem;
    margin-bottom: 0;
}
.breadcrumb-item + .breadcrumb-item::before {
    color: var(--bp-text-muted);
}

/* --- Responsive: tablet and below --- */
@media (max-width: 991.98px) {
    .bp-sidebar {
        transform: translateX(-100%);
    }
    .bp-sidebar.show {
        transform: translateX(0);
    }
    .bp-main {
        margin-left: 0;
    }
    .bp-mobile-toggle {
        display: flex !important;
    }
    .bp-sidebar-overlay {
        display: block;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1029;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }
    .bp-sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }
}

@media (min-width: 992px) {
    .bp-mobile-toggle {
        display: none !important;
    }
    .bp-sidebar-overlay {
        display: none !important;
    }
}

/* --- Mobile top bar --- */
.bp-mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 1020;
    background: var(--bp-sidebar-bg);
    padding: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
}
@media (max-width: 991.98px) {
    .bp-mobile-topbar {
        display: flex;
    }
}
.bp-mobile-topbar .brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.125rem;
}
.bp-mobile-toggle {
    background: none;
    border: none;
    color: #94a3b8;
    padding: 0.25rem;
    cursor: pointer;
}
.bp-mobile-toggle:hover {
    color: #fff;
}

/* --- Confidence highlighting (review detail) --- */
.confidence-high { }
.confidence-medium { border-left: 3px solid #fbbf24 !important; }
.confidence-low { border-left: 3px solid #ef4444 !important; }

/* --- PDF viewer controls --- */
.pdf-controls {
    background: #1e293b;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 8px 8px 0 0;
}
.pdf-controls button, .pdf-controls span { color: #fff; }
#pdf-container {
    background: #334155;
    min-height: 600px;
    position: relative;
}
#pdf-canvas {
    display: block;
    margin: 0 auto;
}

/* --- Upload drop zone --- */
#drop-zone {
    border: 2px dashed var(--bp-card-border) !important;
    border-radius: 8px;
    transition: border-color 0.2s ease, background 0.2s ease;
}
#drop-zone:hover, #drop-zone.drag-over {
    border-color: var(--bp-primary) !important;
    background-color: var(--bp-primary-light) !important;
}

/* Full-page drag overlay */
#drag-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(13, 110, 253, 0.08);
    border: 3px dashed var(--bp-primary);
    pointer-events: none;
}
#drag-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}
#drag-overlay-content {
    background: #fff;
    border-radius: 12px;
    padding: 2rem 3rem;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    text-align: center;
    color: var(--bp-primary);
    font-size: 1.1rem;
    font-weight: 600;
}

/* --- Processing row animation --- */
.bp-processing-row {
    border-left: 3px solid var(--bp-primary) !important;
    animation: bp-pulse 2s ease-in-out infinite;
}
@keyframes bp-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

/* --- Review detail line items --- */
.line-item-row {
    border: 1px solid var(--bp-card-border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.line-item-row.confidence-medium { border-color: #fbbf24; }
.line-item-row.confidence-low { border-color: #ef4444; }

/* --- Review field group --- */
.field-group { margin-bottom: 0.75rem; }
.field-group label { font-size: 0.8rem; color: var(--bp-text-muted); margin-bottom: 0.15rem; }
.confidence-badge { font-size: 0.7rem; }

/* --- Keyboard shortcut hints --- */
kbd {
    font-size: 0.7rem;
    padding: 0.1rem 0.35rem;
    background: #e2e8f0;
    color: #334155;
    border-radius: 3px;
    border: 1px solid #cbd5e1;
}

/* --- Scrollbar styling --- */
.bp-sidebar::-webkit-scrollbar {
    width: 4px;
}
.bp-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.bp-sidebar::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 2px;
}
