/* =============================================================================
   Kings Mabati – Responsive CSS (Bootstrap 5 extension)
   Mobile-first design with collapsible sidebar
   ============================================================================= */

/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1a1a2e;
    --sidebar-brand-bg: #16213e;
    --brand: #0d6efd;
    --hot: #dc3545;
    --warm: #fd7e14;
    --cold: #0d6efd;
}

/* ── Temperature badges ────────────────────────────────────────────────────── */
.badge-hot  { background-color: var(--hot)  !important; color: #fff !important; }
.badge-warm { background-color: var(--warm) !important; color: #fff !important; }
.badge-cold { background-color: var(--cold) !important; color: #fff !important; }

/* ── Sidebar overlay (mobile) ──────────────────────────────────────────────── */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
}
#sidebar-overlay.show { display: block; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--sidebar-bg);
    color: #e0e0e0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

/* Mobile: sidebar hidden off-screen by default */
@media (max-width: 991.98px) {
    #sidebar {
        transform: translateX(-100%);
    }
    #sidebar.sidebar-open {
        transform: translateX(0);
    }
}

#sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background-color: var(--sidebar-brand-bg);
    border-bottom: 1px solid rgba(255,255,255,.08);
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    flex-shrink: 0;
}

#sidebar .sidebar-brand img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 4px;
}

#sidebar .nav-link {
    color: #c0c0d0;
    padding: 0.6rem 1.25rem;
    border-radius: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s;
    white-space: nowrap;
}
#sidebar .nav-link:hover { background-color: rgba(255,255,255,.07); color: #fff; }
#sidebar .nav-link.active { background-color: var(--brand); color: #fff; }

#sidebar .nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6c757d;
    padding: 1rem 1.25rem 0.25rem;
}

/* ── Main content ──────────────────────────────────────────────────────────── */
#main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
}

@media (max-width: 991.98px) {
    #main-content {
        margin-left: 0;
    }
}

/* ── Top navbar ────────────────────────────────────────────────────────────── */
#top-navbar {
    background-color: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

#top-navbar .navbar-brand-mobile {
    font-weight: 700;
    color: #1e293b;
    font-size: 1rem;
    flex: 1;
}

#btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.4rem 0.5rem;
    color: #495057;
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 0.375rem;
    transition: background 0.15s;
}
#btn-sidebar-toggle:hover { background: #f1f5f9; }

@media (max-width: 991.98px) {
    #btn-sidebar-toggle { display: inline-flex; align-items: center; }
}

/* ── Page content ──────────────────────────────────────────────────────────── */
.page-content {
    padding: 1.25rem;
    flex: 1;
}

@media (max-width: 575.98px) {
    .page-content { padding: 0.875rem; }
}

/* ── Metric / KPI cards ────────────────────────────────────────────────────── */
.metric-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
    transition: box-shadow 0.2s;
}
.metric-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.metric-card .metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
}
.metric-card .metric-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6c757d;
}

@media (max-width: 575.98px) {
    .metric-card .metric-value { font-size: 1.3rem; }
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-km { font-size: 0.875rem; }
.table-km thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: #495057;
    white-space: nowrap;
}
.table-km tbody tr { transition: background-color 0.1s; }
.table-km tbody tr:hover { background-color: #f0f4ff; }
.table-km td { vertical-align: middle; }
.table-actions .btn { padding: 0.2rem 0.45rem; font-size: 0.78rem; }

/* Horizontal scroll on small screens */
.table-responsive-stack { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card-hoverable {
    transition: box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
}
.card-hoverable:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    transform: translateY(-2px);
}

/* ── Line items table (quotation / invoice forms) ──────────────────────────── */
.line-items-table th,
.line-items-table td { padding: 0.4rem 0.5rem; vertical-align: middle; }
.line-items-table input[type="number"],
.line-items-table input[type="text"] { min-width: 70px; }
.line-items-table .subtotal-cell { font-weight: 600; white-space: nowrap; }

/* ── Totals box ────────────────────────────────────────────────────────────── */
.totals-box {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
}
.totals-box .totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.9rem;
}
.totals-box .totals-row.total-final {
    font-size: 1.05rem;
    font-weight: 700;
    border-top: 2px solid #dee2e6;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

/* ── AI Score panel ────────────────────────────────────────────────────────── */
.ai-score-panel {
    border-left: 4px solid var(--brand);
    background-color: #f0f4ff;
    border-radius: 0 0.5rem 0.5rem 0;
    padding: 1rem 1.25rem;
}
.ai-score-panel.hot  { border-left-color: var(--hot);  background-color: #fff5f5; }
.ai-score-panel.warm { border-left-color: var(--warm); background-color: #fff8f0; }
.ai-score-panel.cold { border-left-color: var(--cold); background-color: #f0f4ff; }
.ai-score-value { font-size: 2rem; font-weight: 800; line-height: 1; }

/* ── Interaction timeline ──────────────────────────────────────────────────── */
.interaction-timeline { position: relative; padding-left: 1.5rem; }
.interaction-timeline::before {
    content: '';
    position: absolute;
    left: 0.45rem; top: 0; bottom: 0;
    width: 2px;
    background-color: #dee2e6;
}
.interaction-item { position: relative; margin-bottom: 1.25rem; }
.interaction-item::before {
    content: '';
    position: absolute;
    left: -1.1rem; top: 0.35rem;
    width: 10px; height: 10px;
    border-radius: 50%;
    background-color: var(--brand);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--brand);
}

/* ── Mobile-specific helpers ───────────────────────────────────────────────── */
@media (max-width: 575.98px) {
    /* Stack action buttons vertically on very small screens */
    .table-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; justify-content: flex-end; }

    /* Reduce card padding */
    .card-body { padding: 0.875rem; }

    /* Full-width buttons on mobile */
    .btn-mobile-full { width: 100%; }

    /* Hide less important table columns on mobile */
    .d-mobile-none { display: none !important; }

    /* Smaller headings */
    h4.fw-bold { font-size: 1.1rem; }
}

@media (max-width: 767.98px) {
    /* Page header row stacks on mobile */
    .page-header-row {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    .page-header-row .btn-group-mobile {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .page-header-row .btn-group-mobile .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* ── Flash messages ────────────────────────────────────────────────────────── */
.flash-container {
    position: fixed;
    top: 1rem; right: 1rem;
    z-index: 1100;
    min-width: 280px;
    max-width: 90vw;
}

/* ── Filter bar collapse on mobile ────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .filter-bar-collapse .row { flex-direction: column; }
    .filter-bar-collapse .col-md-2,
    .filter-bar-collapse .col-md-3,
    .filter-bar-collapse .col-12 { width: 100%; }
}
