/* ── Fabric Local Sales System — Global Styles ────────────────────── */

:root {
    --fls-primary: #1a3a5c;
    --fls-primary-dark: #122a43;
    --fls-bg: #f4f6f9;
    --fls-card-bg: #ffffff;
    --fls-border: #e5e7eb;
    --fls-muted: #64748b;
    --fls-radius: 10px;
    --fls-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    background: var(--fls-bg);
    color: #1f2937;
}

/* ── General cards / controls ─────────────────────────────────────── */
.card {
    border: 1px solid var(--fls-border);
    border-radius: var(--fls-radius);
    box-shadow: var(--fls-shadow);
}

.btn,
.form-control,
.form-select,
.Select-control {
    min-height: 38px;
}

.form-control,
.form-select {
    font-size: 14px;
}

label,
.form-label {
    font-weight: 600;
    color: #334155;
}

.text-muted {
    color: var(--fls-muted) !important;
}

/* ── Sidebar (desktop) ────────────────────────────────────────────── */
.sidebar-link {
    color: rgba(255,255,255,0.8) !important;
    border-radius: 6px !important;
    margin-bottom: 2px;
    padding: 9px 12px !important;
    transition: background 0.15s;
}
.sidebar-link:hover,
.sidebar-link.active {
    background: rgba(255,255,255,0.15) !important;
    color: #fff !important;
}
.sidebar-brand {
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* ── Mobile offcanvas sidebar ─────────────────────────────────────── */
.mobile-offcanvas .offcanvas-header {
    background: var(--fls-primary);
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}
.mobile-offcanvas .offcanvas-header .btn-close {
    filter: invert(1) grayscale(1) brightness(2);
    opacity: 0.8;
}
.mobile-offcanvas .offcanvas-body {
    background: var(--fls-primary);
    padding: 0;
}

/* ── KPI cards ────────────────────────────────────────────────────── */
.dashboard-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.dashboard-kpi-grid .kpi-card {
    margin-bottom: 0;
    min-height: 112px;
}
.kpi-card {
    border-left: 4px solid var(--fls-primary);
    background: var(--fls-card-bg);
    border-radius: var(--fls-radius);
    padding: 16px 18px;
    box-shadow: var(--fls-shadow);
    margin-bottom: 16px;
    height: 100%;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}
.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--fls-primary);
    line-height: 1.1;
}
.kpi-label {
    font-size: 12px;
    color: var(--fls-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.kpi-icon {
    color: rgba(26, 58, 92, 0.18);
    font-size: 30px;
}
.kpi-card.orange { border-left-color: #e67e22; }
.kpi-card.orange .kpi-value, .kpi-card.orange .kpi-icon { color: #e67e22; }
.kpi-card.green  { border-left-color: #27ae60; }
.kpi-card.green  .kpi-value, .kpi-card.green .kpi-icon { color: #27ae60; }
.kpi-card.red    { border-left-color: #e74c3c; }
.kpi-card.red    .kpi-value, .kpi-card.red .kpi-icon { color: #e74c3c; }
.kpi-card.purple { border-left-color: #8e44ad; }
.kpi-card.purple .kpi-value, .kpi-card.purple .kpi-icon { color: #8e44ad; }

/* ── Chart cards ──────────────────────────────────────────────────── */
.chart-card {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.chart-card .card-body { padding: 14px 16px; }
.chart-card h6 { color: #1a3a5c; }
.dash-chart { width: 100%; }

/* ── Inventory clickable type cards ───────────────────────────────── */
.inv-card-clickable { cursor: pointer; height: 100%; }
.inv-card-clickable .card {
    transition: border-color .15s, box-shadow .15s;
    border: 1px solid #e9ecef;
}
.inv-card-clickable:hover .card {
    border-color: #1a3a5c;
    box-shadow: 0 2px 10px rgba(26,58,92,0.12);
}

/* ── Page header ──────────────────────────────────────────────────── */
.page-header {
    background: var(--fls-card-bg);
    border: 1px solid var(--fls-border);
    border-radius: var(--fls-radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: var(--fls-shadow);
}
.page-header h4 {
    color: var(--fls-primary);
    font-weight: 700;
    margin: 0;
    font-size: 20px;
}
.page-title-block small {
    line-height: 1.35;
}
.page-header-action .btn {
    white-space: nowrap;
}

/* ── Filter / action helpers ──────────────────────────────────────── */
.filter-card {
    border-left: 4px solid var(--fls-primary);
}
.filter-card-title {
    color: var(--fls-primary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.action-bar .btn {
    min-width: 96px;
}
.soft-badge {
    font-weight: 600;
    padding: 5px 8px;
}

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-state-card {
    border: 1px dashed #cbd5e1;
    background: #fff;
}
.empty-icon {
    font-size: 34px;
    color: var(--fls-primary);
}

/* ── Status badges ────────────────────────────────────────────────── */
.status-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
    display: inline-block;
}
.status-DRAFT          { background: #ecf0f1; color: #7f8c8d; }
.status-CONFIRMED      { background: #d5f5e3; color: #1e8449; }
.status-DISPATCHED     { background: #d6eaf8; color: #2471a3; }
.status-IN_PREPARATION { background: #fef9e7; color: #d68910; }
.status-ISSUED         { background: #d6eaf8; color: #1a5276; }
.status-CLOSED         { background: #eaecee; color: #566573; }
.status-CANCELLED      { background: #fadbd8; color: #922b21; }
.status-REJECTED       { background: #fadbd8; color: #922b21; }
.status-ACTIVE         { background: #d5f5e3; color: #1e8449; }
.status-BLOCKED        { background: #fadbd8; color: #922b21; }

/* WhatsApp inbox */
.wa-qr {
    width: 180px;
    max-width: 100%;
    border: 1px solid var(--fls-border);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
}
.wa-conv-list {
    display: grid;
    gap: 5px;
    max-height: calc(100vh - 330px);
    min-height: 180px;
    overflow-y: auto;
    padding-right: 3px;
}
.wa-conv-item {
    width: 100%;
    border: 1px solid var(--fls-border) !important;
    border-radius: 6px !important;
    background: #fff !important;
    color: #1f2937 !important;
    padding: 8px 9px !important;
    display: grid !important;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    min-height: 62px;
    overflow: hidden;
    box-shadow: none !important;
}
.wa-conv-item.active,
.wa-conv-item:hover {
    border-color: #25d366 !important;
    background: #f3fbf6 !important;
}
.wa-conv-item.active {
    box-shadow: inset 3px 0 0 #1b9a59 !important;
}
.wa-conv-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e7f5ed;
    color: #167447;
    font-size: 11px;
    font-weight: 800;
    flex: 0 0 34px;
}
.wa-conv-main {
    display: block;
    min-width: 0;
    overflow: hidden;
}
.wa-conv-top,
.wa-conv-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}
.wa-conv-title {
    color: var(--fls-primary);
    display: block;
    min-width: 0;
    font-size: 13px;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wa-conv-time {
    color: #64748b;
    flex: 0 0 auto;
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
}
.wa-conv-preview {
    color: var(--fls-muted);
    display: block;
    min-width: 0;
    font-size: 11.5px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}
.wa-conv-unread {
    flex: 0 0 auto;
    min-width: 19px;
    padding: 3px 5px;
    font-size: 9px;
}
.wa-conv-unread-placeholder {
    flex: 0 0 0;
}
.wa-chat-card {
    min-height: 70vh;
}

/* Manager approval inbox */
.approval-toolbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 180px;
    gap: 10px;
    margin-bottom: 12px;
}
.approval-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--fls-border);
    background: #fff;
    margin-bottom: 12px;
}
.approval-summary-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-right: 1px solid var(--fls-border);
    min-width: 0;
}
.approval-summary-item:last-child { border-right: 0; }
.approval-summary-item small,
.approval-summary-item strong { display: block; }
.approval-summary-item small { color: var(--fls-muted); font-size: 11px; }
.approval-summary-item strong { color: var(--fls-primary); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.approval-summary-icon { color: #1b8a55; font-size: 18px; }
.approval-queue {
    background: #fff;
    border: 1px solid var(--fls-border);
    overflow: hidden;
}
.approval-table th {
    background: #f7f9fb;
    color: #526174;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    border-bottom-width: 1px;
}
.approval-table td { vertical-align: middle; padding-top: 9px; padding-bottom: 9px; }
.approval-customer { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval-actions-col { width: 112px; }
.approval-order-context > div {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 14px;
    background: #f7f9fb;
    border-left: 3px solid #1b8a55;
}
.approval-order-context span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval-mobile-item {
    background: #fff;
    border: 1px solid var(--fls-border);
    border-left: 3px solid #1b8a55;
    padding: 11px;
    margin-bottom: 7px;
}
.approval-mobile-values { border-top: 1px solid #edf0f2; padding-top: 7px; margin-top: 7px; }
.wa-chat-header {
    background: #fff;
    border-bottom: 1px solid var(--fls-border);
}
.wa-message-list {
    min-height: 48vh;
    max-height: 58vh;
    overflow-y: auto;
    background: #eef5f1;
    border: 1px solid var(--fls-border);
    border-radius: 8px;
    padding: 12px;
}
.wa-message-row {
    display: flex;
    margin-bottom: 8px;
}
.wa-bubble {
    max-width: min(76%, 620px);
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
    overflow-wrap: anywhere;
}
.wa-bubble.in {
    background: #fff;
}
.wa-bubble.out {
    background: #d9fdd3;
}
.wa-message-text {
    white-space: pre-wrap;
}
.wa-message-time,
.wa-message-status {
    color: #64748b;
    font-size: 10px;
}
.wa-media-preview {
    display: block;
    max-width: 260px;
    max-height: 220px;
    border-radius: 6px;
    margin-bottom: 6px;
}
.wa-media-link {
    display: inline-block;
    margin-bottom: 4px;
}
.wa-audio-wrap {
    min-width: min(320px, 68vw);
    margin-bottom: 6px;
}
.wa-media-label {
    display: block;
    color: #475569;
    margin-bottom: 4px;
}
.wa-audio-player {
    display: block;
    width: 100%;
    max-width: 320px;
}
.wa-video-player {
    display: block;
    width: min(320px, 68vw);
    max-height: 260px;
    border-radius: 6px;
    margin-bottom: 6px;
    background: #0f172a;
}
.wa-compose {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    align-items: stretch;
}
.wa-textbox {
    resize: vertical;
    min-height: 42px;
}

/* ── Stock badges ─────────────────────────────────────────────────── */
.stock-badge { font-size: 12px; font-weight: 700; }
.stock-ok    { color: #27ae60; }
.stock-low   { color: #e67e22; }
.stock-zero  { color: #e74c3c; }

/* ── Tables ───────────────────────────────────────────────────────── */
.order-line-table th { background: var(--fls-primary); color: #fff; font-size: 12px; }
.order-line-table td { vertical-align: middle; }

.table th {
    font-size: 12px;
    white-space: nowrap;
    background: #f8fafc;
    color: #334155;
}
.table td {
    vertical-align: middle;
    font-size: 13px;
}
.numeric-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Make app tables scrollable on small screens */
.table-responsive, .bg-white {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Mobile record cards ──────────────────────────────────────────── */
.mobile-record-card {
    border-left: 4px solid var(--fls-primary);
}
.mobile-card-title {
    color: var(--fls-primary);
    font-size: 14px;
}
.mobile-card-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px solid #f1f5f9;
}
.mobile-card-row:last-child {
    border-bottom: 0;
}
.mobile-card-label {
    color: var(--fls-muted);
    font-size: 12px;
}
.mobile-card-value {
    font-weight: 600;
    text-align: right;
    font-size: 12px;
}
.mobile-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.mobile-card-actions .btn {
    flex: 1 1 auto;
}

/* ── ════════════════════════════════════════════════════════════════ */
/* ── MOBILE RESPONSIVE  (< 768px)                                    */
/* ── ════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {

    .mobile-topbar {
        min-height: 48px;
    }

    /* Content fills full width — no sidebar offset */
    .main-content {
        margin-left: 0 !important;
        padding: 12px 10px !important;
    }

    /* Hide desktop sidebar */
    #sidebar-container {
        display: none !important;
    }

    /* Page header stacks gracefully */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px;
        margin-bottom: 12px;
        padding: 12px;
    }
    .page-header h4 { font-size: 17px; }
    .page-header-action,
    .page-header-action .btn {
        width: 100%;
    }

    /* KPI value smaller on mobile */
    .kpi-value { font-size: 22px; }
    .kpi-card  { padding: 12px 14px; }
    .kpi-icon  { font-size: 24px; }

    /* Cards take less padding */
    .card-body { padding: 12px !important; }

    /* Filter rows: add spacing between stacked cols */
    .card-body .row > * { margin-bottom: 6px; }
    .filter-card .btn { width: 100%; }

    /* Tables: ensure horizontal scroll */
    .table-responsive { overflow-x: auto; }
    table.table { min-width: 520px; }

    /* Modal: full width on very small screens */
    .modal-xl, .modal-lg { max-width: 98vw !important; margin: 4px auto !important; }
    .modal-body { padding: 12px !important; max-height: 80vh; overflow-y: auto; }

    /* Order entry lines — keep compact */
    .border-start.border-primary { border-left-width: 2px !important; }

    /* Pagination bar: stack on mobile */
    .pagination-bar .col-md-5,
    .pagination-bar .col-md-7 { text-align: left !important; }

    /* Dash dcc.Dropdown — prevent overflow */
    .Select-menu-outer { max-width: 100vw; }

    /* Buttons in button groups — smaller on mobile */
    .btn-group .btn { padding: 3px 7px; font-size: 12px; }

    /* Order entry form specifics */
    .order-entry-header .row > .col { margin-bottom: 10px; }

    /* Radio items: stack vertically on mobile */
    .form-check { display: block; margin-bottom: 6px; }
    .form-check-inline { display: block !important; margin-right: 0; }

    /* Labels and inputs: full width */
    .form-control, .form-select, .Select-control { width: 100%; }
    label { font-size: 13px; font-weight: 600; margin-bottom: 4px; }

    /* Stock badge: wrap text */
    .badge { white-space: normal; word-break: break-word; }

    .wa-chat-card {
        min-height: auto;
    }
    .wa-conv-list {
        max-height: 42vh;
    }
    .approval-toolbar {
        grid-template-columns: 1fr;
    }
    .approval-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .approval-summary-item:nth-child(2) { border-right: 0; }
    .approval-summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--fls-border); }
    .approval-order-context > div {
        grid-template-columns: 1fr;
        gap: 3px;
    }
    .wa-message-list {
        min-height: 42vh;
        max-height: 52vh;
    }
    .wa-bubble {
        max-width: 88%;
    }
    .wa-compose {
        grid-template-columns: 44px 1fr;
    }
    .wa-compose .btn-success {
        grid-column: 1 / -1;
        width: 100%;
    }

    /* Totals row: display as stacked cards */
    .oe-total-display {
        border-top: 1px solid #e9ecef;
        padding-top: 8px;
        margin-top: 8px;
    }

    /* Action helpers */
    .action-bar,
    .mobile-stack-actions {
        flex-direction: column;
    }
    .action-bar .btn,
    .mobile-stack-actions .btn {
        width: 100%;
    }

    /* Sticky mobile actions for transaction pages */
    .mobile-sticky-actions {
        position: sticky;
        bottom: 0;
        z-index: 1010;
        background: #fff;
        border: 1px solid var(--fls-border);
        border-radius: 10px 10px 0 0;
        padding: 8px;
        margin: 12px -2px 0 -2px;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
        display: grid;
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .mobile-sticky-actions .btn {
        width: 100%;
        min-height: 42px;
    }
}

/* ── Extra small screens (<480px) ─────────────────────────────────── */
@media (max-width: 479px) {
    .text-muted.small { font-size: 11px; }
    .form-control, .form-select { padding: 6px 8px; font-size: 13px; }
    .btn-sm { padding: 4px 8px; font-size: 12px; }
    .page-header h4 { font-size: 16px; }
    .border-start.border-primary { margin-bottom: 12px; }
    .card-body { padding: 8px !important; }
    .modal-body .row > .col { margin-bottom: 8px; }
}

/* ── Tablet (768px – 991px) ───────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 991px) {
    .main-content {
        margin-left: 220px;
        padding: 15px !important;
    }
    .kpi-value { font-size: 22px; }
    .kpi-card  { padding: 12px 14px; }
}

/* ── ════════════════════════════════════════════════════════════════ */
/* ── PRINT styles                                                     */
/* ── ════════════════════════════════════════════════════════════════ */

@media print {
    body { font-size: 12px; background: #fff !important; }
    #page-content, .main-content {
        margin-left: 0 !important;
        padding: 10px !important;
    }
    .mobile-topbar,
    #sidebar-container,
    .no-print { display: none !important; }
    .card { border: 1px solid #ccc !important; box-shadow: none !important; }
    .page-header { border-bottom: 2px solid #000; margin-bottom: 12px; }
    .page-header h4 { font-size: 16px; font-weight: 700; }
    .kpi-card { display: none !important; }
    .chart-card, #dash-charts { display: none !important; }
    table { width: 100%; border-collapse: collapse; font-size: 11px; }
    table th {
        background: var(--fls-primary) !important; color: #fff !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    table td, table th { border: 1px solid #999; padding: 4px 6px; }
    .border-start {
        border-left: 3px solid var(--fls-primary) !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
}
