/**
 * Sushil ERP - FMCG Packaging Manufacturing Management Theme
 * Clean, Enterprise-Grade UI Design with Full Mobile Responsiveness
 */

:root {
    --erp-primary: #1e3a8a;       /* Deep Navy */
    --erp-primary-hover: #172554;
    --erp-secondary: #0f766e;     /* Deep Teal */
    --erp-sidebar-bg: #0f172a;     /* Dark Slate */
    --erp-sidebar-hover: #1e293b;
    --erp-sidebar-active: #2563eb;
    --erp-sidebar-text: #94a3b8;
    --erp-sidebar-heading: #64748b;
    --erp-body-bg: #f8fafc;
    --erp-card-bg: #ffffff;
    --erp-border: #e2e8f0;
    --erp-text: #1e293b;
    --erp-text-muted: #64748b;
    --erp-success: #16a34a;
    --erp-warning: #d97706;
    --erp-danger: #dc2626;
    --erp-info: #0284c7;
    --sidebar-width: 260px;
    --topbar-height: 62px;
}

html {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--erp-body-bg);
    color: var(--erp-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
}

body.sidebar-open {
    overflow: hidden;
}

/* ====================================================
   Layout & Wrapper
   ==================================================== */
#app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

/* Sidebar Navigation */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--erp-sidebar-bg);
    color: var(--erp-sidebar-text);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-brand-wrapper {
    height: var(--topbar-height);
    background: #090e1a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 0.5rem;
    flex-shrink: 0;
}

#sidebar .sidebar-brand {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #ffffff;
    text-decoration: none;
    background: transparent;
    min-width: 0;
}

#sidebar .sidebar-brand i {
    font-size: 1.4rem;
    color: #38bdf8;
    margin-right: 0.6rem;
    flex-shrink: 0;
}

#sidebar .sidebar-brand span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 38px;
    height: 38px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.15rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-close-btn:hover,
.sidebar-close-btn:focus {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
    outline: none;
}

.sidebar-heading {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--erp-sidebar-heading);
    padding: 1rem 1.25rem 0.4rem;
}

.sidebar-nav {
    list-style: none;
    padding: 0.5rem 0 1.5rem;
    margin: 0;
}

.sidebar-nav .nav-item {
    margin: 2px 0.5rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.85rem;
    color: var(--erp-sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-nav .nav-link i {
    font-size: 1.15rem;
    margin-right: 0.75rem;
    width: 22px;
    text-align: center;
    color: #94a3b8;
    transition: color 0.2s;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    background-color: var(--erp-sidebar-hover);
    color: #ffffff;
}

.sidebar-nav .nav-link:hover i {
    color: #38bdf8;
}

.sidebar-nav .nav-link.active {
    background-color: var(--erp-sidebar-active);
    color: #ffffff;
    font-weight: 600;
}

.sidebar-nav .nav-link.active i {
    color: #ffffff;
}

.sidebar-badge {
    margin-left: auto;
    font-size: 0.72rem;
}

/* Main Content Area */
#main-content {
    flex: 1 1 auto;
    min-width: 0;
    width: calc(100% - var(--sidebar-width));
    max-width: 100%;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--erp-body-bg);
    overflow-x: hidden;
}

/* Topbar Navigation */
#topbar {
    height: var(--topbar-height);
    background-color: #ffffff;
    border-bottom: 1px solid var(--erp-border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1020;
    max-width: 100vw;
    width: 100%;
}

.topbar-toggler {
    background: #f8fafc;
    border: 1px solid var(--erp-border);
    font-size: 1.35rem;
    color: var(--erp-text);
    padding: 0.25rem 0.5rem;
    min-width: 42px;
    min-height: 42px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.topbar-toggler:hover,
.topbar-toggler:focus {
    background-color: #f1f5f9;
    color: var(--erp-primary);
    outline: none;
}

.topbar-title {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 600;
    color: var(--erp-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background-color: #e0e7ff;
    color: #3730a3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Page Content Body */
.content-body {
    padding: 1.5rem;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
}

/* ERP Application Footer */
.app-footer {
    background-color: #ffffff;
    border-top: 1px solid var(--erp-border);
    padding: 0.85rem 1.5rem;
    margin-top: auto;
    width: 100%;
    flex-shrink: 0;
}

.app-footer .footer-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--erp-text-muted);
}

/* ====================================================
   Card & UI Components
   ==================================================== */
.erp-card {
    background: #ffffff;
    border: 1px solid var(--erp-border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
    overflow: hidden;
    max-width: 100%;
}

.erp-card-header {
    padding: 1rem 1.25rem;
    background: #ffffff;
    border-bottom: 1px solid var(--erp-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.erp-card-header h5 {
    margin: 0;
    font-size: clamp(0.95rem, 2.5vw, 1.05rem);
    font-weight: 600;
    color: var(--erp-text);
}

.erp-card-body {
    padding: 1.25rem;
}

/* Stat & KPI Cards */
.stat-card {
    border-radius: 10px;
    border: 1px solid var(--erp-border);
    background: #ffffff;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-width: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-info {
    min-width: 0;
    flex: 1;
}

.stat-info .stat-label {
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--erp-text-muted);
    margin-bottom: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-info .stat-value {
    font-size: clamp(1.2rem, 3.5vw, 1.65rem);
    font-weight: 700;
    color: var(--erp-text);
    line-height: 1.2;
    word-break: break-word;
}

.stat-info .stat-desc {
    font-size: 0.76rem;
    color: var(--erp-text-muted);
    margin-top: 0.25rem;
}

.stat-icon {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.icon-blue   { background: #eff6ff; color: #2563eb; }
.icon-green  { background: #f0fdf4; color: #16a34a; }
.icon-orange { background: #fffbeb; color: #d97706; }
.icon-purple { background: #faf5ff; color: #7c3aed; }
.icon-cyan   { background: #ecfeff; color: #0891b2; }
.icon-red    { background: #fef2f2; color: #dc2626; }

/* ====================================================
   Tables & Data Grid
   ==================================================== */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
    position: relative;
}

/* Clean WebKit scrollbar for mobile swipe */
.table-responsive::-webkit-scrollbar {
    height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.erp-table {
    width: 100%;
    margin-bottom: 0;
}

.erp-table thead th {
    background-color: #f8fafc;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--erp-border);
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.erp-table tbody td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--erp-border);
    font-size: 0.88rem;
}

.erp-table tbody tr:hover {
    background-color: #f8fafc;
}

.erp-table .badge,
.erp-table .btn {
    white-space: nowrap;
}

.erp-table td:last-child {
    white-space: nowrap;
}

/* ====================================================
   Forms & Controls
   ==================================================== */
.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: #334155;
}

.form-control, .form-select {
    border-radius: 6px;
    border-color: #cbd5e1;
}

.form-control:focus, .form-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-group {
    min-width: 0;
}

.input-group > .form-control,
.input-group > .form-select {
    min-width: 0;
}

.invalid-feedback {
    font-size: 0.8rem;
    word-break: break-word;
}

/* ====================================================
   Modals & Popups
   ==================================================== */
.modal {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.modal-dialog {
    max-width: min(500px, calc(100vw - 1rem)) !important;
    margin: 0.5rem auto !important;
}

@media (min-width: 576px) {
    .modal-dialog {
        margin: 1.75rem auto !important;
    }
    .modal-dialog.modal-sm { max-width: min(380px, calc(100vw - 2rem)) !important; }
    .modal-dialog.modal-lg { max-width: min(800px, calc(100vw - 2rem)) !important; }
    .modal-dialog.modal-xl { max-width: min(1140px, calc(100vw - 2rem)) !important; }
}

.modal-content {
    border-radius: 12px;
    border: 1px solid var(--erp-border);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 160px);
    padding: 1.25rem;
}

.modal-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ====================================================
   Alerts, Images, Workflow & Utilities
   ==================================================== */
img {
    max-width: 100%;
    height: auto;
}

.alert {
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    border-radius: 8px;
}

.alert.d-flex {
    align-items: flex-start;
}

.alert .bi {
    flex-shrink: 0;
}

.workflow-step {
    position: relative;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    background: #f1f5f9;
    border-left: 4px solid #94a3b8;
}

.workflow-step.active {
    background: #eff6ff;
    border-left-color: #2563eb;
    color: #1e3a8a;
}

/* ====================================================
   Responsive Breakpoints
   ==================================================== */

/* Tablet & Below (<= 991.98px) */
@media (max-width: 991.98px) {
    :root {
        --topbar-height: 56px;
    }

    #sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 280px;
        max-width: 82vw;
        transform: translateX(-100%);
        margin-left: 0 !important;
        z-index: 1055;
        box-shadow: none;
    }

    #sidebar.show {
        transform: translateX(0);
        box-shadow: 6px 0 28px rgba(0, 0, 0, 0.35);
    }

    #main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw;
        padding-top: 56px !important;
        padding-bottom: 52px !important;
        min-height: 100vh;
    }

    /* Fixed Header and Fixed Top-Left Hamburger Menu Button */
    #topbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100% !important;
        height: 56px !important;
        z-index: 1040 !important;
        padding: 0 0.85rem !important;
        background-color: #ffffff !important;
        border-bottom: 1px solid var(--erp-border) !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    }

    .topbar-toggler {
        position: fixed !important;
        top: 7px !important;
        left: 8px !important;
        z-index: 1045 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 42px !important;
        height: 42px !important;
        min-width: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        background: #f8fafc !important;
        border: 1px solid var(--erp-border) !important;
        border-radius: 8px !important;
        color: var(--erp-text) !important;
        font-size: 1.35rem !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
    }

    .topbar-toggler:active,
    .topbar-toggler:hover {
        background-color: #e2e8f0 !important;
        color: #0f172a !important;
    }

    #topbar > .d-flex:first-child {
        padding-left: 48px;
    }

    /* Fixed Viewport Footer */
    .app-footer {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100% !important;
        height: 44px !important;
        z-index: 1030 !important;
        background-color: #ffffff !important;
        border-top: 1px solid var(--erp-border) !important;
        box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.05) !important;
        padding: 0 1rem !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
    }

    .app-footer .footer-container {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 0.74rem;
        line-height: 1;
        color: var(--erp-text-muted);
    }

    .app-footer .footer-brand {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 85vw;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.6);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        z-index: 1050;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.28s ease, visibility 0.28s ease;
        pointer-events: none;
    }

    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .content-body {
        padding: 1.15rem 1.15rem 2rem 1.15rem;
    }
}

/* Mobile Devices (<= 767.98px) */
@media (max-width: 767.98px) {
    .content-body {
        padding: 0.85rem 0.85rem 2rem 0.85rem;
    }

    .erp-card {
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    .erp-card-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.6rem;
    }

    .erp-card-header .btn-group,
    .erp-card-header .btn {
        width: auto;
    }

    .erp-card-body {
        padding: 0.85rem;
    }

    .stat-card {
        padding: 0.85rem;
        border-radius: 8px;
    }

    .stat-info .stat-value {
        font-size: clamp(1.2rem, 3.8vw, 1.5rem);
    }

    .form-control, .form-select {
        min-height: 42px;
        font-size: 0.92rem;
    }

    .btn {
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }

    .btn-sm {
        min-height: 34px;
        padding: 0.35rem 0.65rem;
    }

    .erp-table th, .erp-table td {
        padding: 0.65rem 0.75rem;
        font-size: 0.82rem;
    }

    .erp-table .btn-sm {
        min-height: 30px;
        min-width: 30px;
        padding: 0.2rem 0.45rem;
    }

    .nav-pills, .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 4px;
    }

    .nav-pills .nav-item, .nav-tabs .nav-item {
        flex-shrink: 0;
    }

    .dropdown-menu {
        max-width: calc(100vw - 1.5rem);
    }
}

/* Small Smartphone Viewports (<= 414px, e.g. 360x800, 390x844, 412x915) */
@media (max-width: 414px) {
    .content-body {
        padding: 0.65rem;
    }

    .erp-card-body {
        padding: 0.75rem;
    }

    .topbar-title {
        max-width: 170px;
        font-size: 0.92rem;
    }

    .stat-card {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
        min-width: 38px;
        font-size: 1.15rem;
    }

    .btn-group.w-100 {
        flex-wrap: wrap;
    }

    .btn-group.w-100 .btn {
        flex: 1 1 auto;
        min-width: calc(33.333% - 4px);
    }
}

/* ====================================================
   Print Styles
   ==================================================== */
@media print {
    #sidebar, #topbar, .app-footer, .sidebar-overlay, .btn-print, .no-print, .topbar-toggler, .sidebar-close-btn {
        display: none !important;
    }
    #main-content {
        margin-left: 0 !important;
        width: 100% !important;
        background: #ffffff !important;
    }
    .content-body {
        padding: 0 !important;
    }
    .erp-card {
        border: none !important;
        box-shadow: none !important;
    }
}
