/* ================================================================
   Sigma Engineers CRM — Custom Stylesheet
   Bootstrap 5.3 overrides + Mobile App Feel
   ================================================================ */

/* ── Base ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    background: #f1f5f9;
    color: #1e293b;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--crm-primary, #2563eb); }

/* ── Layout wrapper ───────────────────────────────────────────── */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: 240px;
    transition: margin-left 0.3s ease;
}

/* ── Sidebar ──────────────────────────────────────────────────── */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background: var(--crm-sidebar, #0f172a);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-brand {
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    min-height: 64px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-logo {
    max-height: 40px;
    width: auto;
    max-width: 180px;
}

.sidebar-logo-text {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 34px;
    height: 34px;
    background: var(--crm-primary, #2563eb);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    flex-shrink: 0;
}

.brand-name {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.3);
    padding: 16px 16px 6px;
    text-transform: uppercase;
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: rgba(255,255,255,0.65);
    text-decoration: none !important;
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

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

.nav-item.active {
    color: #fff;
    background: rgba(37,99,235,0.18);
    border-left-color: var(--crm-primary, #2563eb);
    font-weight: 600;
}

.nav-item i {
    font-size: 16px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 8px 0;
    border-top: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.nav-item-logout {
    color: rgba(255,120,120,0.75) !important;
}

.nav-item-logout:hover {
    color: #f87171 !important;
    background: rgba(239,68,68,0.1) !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1040;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.show { display: block; }

/* ── Topbar ───────────────────────────────────────────────────── */

.topbar {
    position: sticky;
    top: 0;
    height: 60px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-title h5 {
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.sidebar-toggle {
    background: none;
    border: 1px solid #e2e8f0;
    padding: 5px 8px;
    color: #64748b;
    cursor: pointer;
    border-radius: 8px;
    line-height: 1;
    transition: background 0.15s;
}

.sidebar-toggle:hover { background: #f1f5f9; }

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--crm-primary, #2563eb);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    cursor: default;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.2;
    white-space: nowrap;
}

.role-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

/* ── Main Content ─────────────────────────────────────────────── */

.main-content {
    flex: 1;
    padding: 24px;
    min-height: calc(100vh - 60px);
}

/* ── Cards ────────────────────────────────────────────────────── */

.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    background: #fff;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #f1f5f9;
    padding: 16px 20px;
    font-weight: 600;
    font-size: 14px;
    border-radius: 12px 12px 0 0 !important;
    color: #0f172a;
}

.card-header .card-subtitle {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 400;
    margin-top: 2px;
}

.card-body { padding: 20px; }
.card-footer {
    background: #fafbfc;
    border-top: 1px solid #f1f5f9;
    padding: 12px 20px;
    border-radius: 0 0 12px 12px !important;
}

/* Stat Cards */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card .stat-card-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-card .stat-number {
    font-size: 30px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1;
    letter-spacing: -1px;
}

.stat-card .stat-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-top: 4px;
}

.stat-card .stat-trend {
    font-size: 12px;
    font-weight: 500;
}

.stat-card-blue   { border-left: 4px solid #2563eb; }
.stat-card-green  { border-left: 4px solid #16a34a; }
.stat-card-orange { border-left: 4px solid #d97706; }
.stat-card-red    { border-left: 4px solid #dc2626; }
.stat-card-teal   { border-left: 4px solid #0d9488; }

/* ── Tables ───────────────────────────────────────────────────── */

.table-wrapper {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    background: #fff;
}

.table {
    margin-bottom: 0;
    font-size: 13px;
}

.table thead th {
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    border-top: none;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #64748b;
    padding: 12px 16px;
    white-space: nowrap;
}

.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: #f8fafc !important; }
.table tbody tr:nth-child(even) { background: #fafbfc; }
.table td {
    padding: 12px 16px;
    vertical-align: middle;
    color: #374151;
    border-color: #f1f5f9;
}

.table-actions { white-space: nowrap; }

/* ── Buttons ──────────────────────────────────────────────────── */

.btn {
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.btn-primary {
    background: var(--crm-primary, #2563eb);
    border-color: var(--crm-primary, #2563eb);
    color: #fff;
}
.btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

.btn-success  { background: #16a34a; border-color: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }

.btn-danger   { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover  { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-warning  { background: #d97706; border-color: #d97706; color: #fff; }
.btn-warning:hover { background: #b45309; border-color: #b45309; color: #fff; }

.btn-sm  { padding: 5px 10px; font-size: 12px; gap: 4px; }
.btn-lg  { padding: 12px 24px; font-size: 15px; }

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
}

.btn-icon.btn-sm { width: 28px; height: 28px; }

/* ── Status & Priority Badges ─────────────────────────────────── */

.badge { border-radius: 20px; font-weight: 600; font-size: 11px; padding: 4px 10px; }

.status-open        { background: #dbeafe; color: #1d4ed8; }
.status-assigned    { background: #ffedd5; color: #c2410c; }
.status-in_progress { background: #fef9c3; color: #a16207; }
.status-resolved    { background: #ccfbf1; color: #0f766e; }
.status-closed      { background: #dcfce7; color: #15803d; }

.priority-urgent { background: #fee2e2; color: #b91c1c; }
.priority-high   { background: #ffedd5; color: #c2410c; }
.priority-medium { background: #fef9c3; color: #a16207; }
.priority-low    { background: #f1f5f9; color: #64748b; }

/* ── Forms ────────────────────────────────────────────────────── */

.form-control,
.form-select {
    border-radius: 8px;
    border-color: #e2e8f0;
    font-size: 14px;
    padding: 10px 14px;
    height: auto;
    color: #0f172a;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--crm-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
    color: #0f172a;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #374151;
    margin-bottom: 5px;
}

.form-text { color: #94a3b8; font-size: 12px; }

.form-floating .form-control,
.form-floating .form-select {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
}

.input-group .form-control:focus { z-index: 3; }

/* ── Page Header ──────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header-left .breadcrumb {
    font-size: 12px;
    margin-bottom: 6px;
}

.page-header-left h4 {
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
    margin: 0;
    letter-spacing: -0.3px;
}

.breadcrumb { margin-bottom: 0; }
.breadcrumb-item a { color: #64748b; text-decoration: none; }
.breadcrumb-item a:hover { color: var(--crm-primary, #2563eb); }
.breadcrumb-item + .breadcrumb-item::before { color: #cbd5e1; }
.breadcrumb-item.active { color: #94a3b8; }

/* ── Section Label ────────────────────────────────────────────── */

.section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    margin-bottom: 12px;
    display: block;
}

/* ── Empty States ─────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 24px;
}

.empty-state .empty-icon {
    font-size: 64px;
    color: #cbd5e1;
    margin-bottom: 16px;
    display: block;
}

.empty-state h5 {
    font-weight: 700;
    color: #374151;
    margin-bottom: 8px;
    font-size: 16px;
}

.empty-state p {
    color: #94a3b8;
    font-size: 14px;
    margin-bottom: 20px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Flash Alerts ─────────────────────────────────────────────── */

.flash-alerts { margin-bottom: 20px; }

.flash-alerts .alert {
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    padding: 12px 16px;
}

/* ── Modals ───────────────────────────────────────────────────── */

.modal-content {
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-header {
    border-bottom: 1px solid #f1f5f9;
    padding: 18px 24px;
}

.modal-title { font-weight: 700; font-size: 16px; }
.modal-body  { padding: 24px; }
.modal-footer {
    border-top: 1px solid #f1f5f9;
    padding: 14px 24px;
}

/* ── Pagination ───────────────────────────────────────────────── */

.pagination .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border-color: #e2e8f0;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
}

.pagination .page-link:hover { background: #f1f5f9; color: var(--crm-primary, #2563eb); }
.pagination .page-item.active .page-link {
    background: var(--crm-primary, #2563eb);
    border-color: var(--crm-primary, #2563eb);
}

/* ── Tabs ─────────────────────────────────────────────────────── */

.nav-tabs {
    border-bottom: 2px solid #e2e8f0;
    gap: 4px;
}

.nav-tabs .nav-link {
    border: none;
    border-radius: 8px 8px 0 0;
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    margin-bottom: -2px;
}

.nav-tabs .nav-link.active {
    color: var(--crm-primary, #2563eb);
    background: #fff;
    border-bottom: 2px solid var(--crm-primary, #2563eb);
}

.nav-tabs .nav-link:hover:not(.active) {
    color: #0f172a;
    background: #f8fafc;
}

/* ── Complaint Cards (mobile list view) ───────────────────────── */

.complaint-card {
    border-left: 4px solid var(--crm-primary, #2563eb) !important;
}

.complaint-card.priority-urgent { border-left-color: #dc2626 !important; }
.complaint-card.priority-high   { border-left-color: #d97706 !important; }
.complaint-card.priority-medium { border-left-color: #ca8a04 !important; }
.complaint-card.priority-low    { border-left-color: #94a3b8 !important; }

/* ── Form Switch ──────────────────────────────────────────────── */

.form-switch .form-check-input {
    width: 3em;
    height: 1.5em;
    cursor: pointer;
}

.form-switch .form-check-input:checked {
    background-color: var(--crm-primary, #2563eb);
    border-color: var(--crm-primary, #2563eb);
}

/* ── Color picker ─────────────────────────────────────────────── */

input[type="color"] {
    width: 48px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    padding: 3px;
    cursor: pointer;
}

/* ── Spinner overlay ──────────────────────────────────────────── */

#spinnerOverlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ── Mobile overrides (≤768px) ────────────────────────────────── */

@media (max-width: 991.98px) {
    .main-area { margin-left: 0; }
    .sidebar   { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.2); }
}

@media (max-width: 767.98px) {
    /* Bottom nav */
    .bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 60px;
        background: #fff;
        border-top: 1px solid #e2e8f0;
        z-index: 1000;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.07);
    }

    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        font-size: 10px;
        font-weight: 500;
        color: #94a3b8;
        text-decoration: none;
        padding: 6px 8px;
        min-width: 50px;
        border-radius: 8px;
        transition: color 0.15s;
    }

    .bottom-nav a.active { color: var(--crm-primary, #2563eb); }
    .bottom-nav a i { font-size: 20px; }

    /* Content padding for bottom nav */
    .main-content {
        padding: 16px;
        padding-bottom: 76px;
    }

    /* Touch targets */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .btn-icon { min-height: 36px; }

    /* Full-width action buttons */
    .btn-mobile-full { width: 100%; justify-content: center; }

    /* Topbar */
    .topbar { padding: 0 16px; }

    /* Tables scroll on mobile */
    .table-wrapper { overflow-x: auto; }

    /* Cards */
    .card { border-radius: 12px; margin-bottom: 12px; }
}

/* ── Desktop hides bottom nav ─────────────────────────────────── */

@media (min-width: 768px) {
    .bottom-nav { display: none !important; }
}

/* ── More Menu (mobile slide-up panel) ────────────────────────── */

#moreMenu {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1060;
}

#moreMenu.show-menu { display: block; }

#moreMenuOverlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
}

.more-menu-panel {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px 24px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}

.more-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    border-radius: 12px;
    background: #f8fafc;
    color: #374151;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    transition: background 0.15s;
}

.more-menu-item i {
    font-size: 22px;
    color: var(--crm-primary, #2563eb);
}

.more-menu-item.more-menu-logout i { color: #dc2626; }
.more-menu-item.more-menu-logout  { color: #dc2626; }
.more-menu-item:hover { background: #f1f5f9; text-decoration: none; color: #0f172a; }

/* ── Page Title (standalone h1 in views) ─────────────────────── */

h1.page-title {
    font-size: 22px;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 2px;
    letter-spacing: -0.4px;
    line-height: 1.2;
}

.page-subtitle {
    font-size: 13px;
    color: #94a3b8;
    margin: 0;
    font-weight: 400;
}

/* ── Custom badge colours ─────────────────────────────────────── */

.bg-orange { background-color: #ea580c !important; color: #fff !important; }
.bg-teal   { background-color: #0d9488 !important; color: #fff !important; }

/* ── List group ───────────────────────────────────────────────── */

.list-group-item {
    border-color: #f1f5f9;
    font-size: 14px;
}

/* ── Timeline (complaint view) ────────────────────────────────── */

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
    display: flex;
    gap: 12px;
    padding-bottom: 16px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}
.timeline-content { flex: 1; }
.timeline-content .timeline-title {
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
}
.timeline-content .timeline-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

/* ── Utility classes ──────────────────────────────────────────── */

.text-muted      { color: #94a3b8 !important; }
.fw-semibold     { font-weight: 600 !important; }
.border-radius-8 { border-radius: 8px !important; }
.fs-10           { font-size: 10px !important; }
.fs-11           { font-size: 11px !important; }
.fs-12           { font-size: 12px !important; }

/* ── Print ────────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .bottom-nav, #moreMenu { display: none !important; }
    .main-area { margin-left: 0; }
    .main-content { padding: 0; }
}
