/* ==========================================================================
   VYPNEX B2B CommerceOS - Comprehensive Mobile-Responsive Stylesheet
   ========================================================================== */

:root {
    --vypnex-primary: #0070f3;
    --vypnex-primary-dark: #07387d;
    --vypnex-primary-light: #38bdf8;
    --vypnex-orange: #ff5722;
    --vypnex-orange-light: #f97316;
    --vypnex-gold: #f59e0b;
    --vypnex-accent: #ff5722;
    --vypnex-sidebar-bg: #070d1d;
    --vypnex-sidebar-hover: #0f1c3f;
    --vypnex-bg-gray: #f8fafc;
    --vypnex-border: #e2e8f0;
    --vypnex-card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --vypnex-header-height: 68px;
    --vypnex-sidebar-width: 260px;
}

/* Brand Gradient & Typography Utilities */
.brand-text-vyp {
    background: linear-gradient(135deg, #38bdf8 0%, #0070f3 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.brand-text-nex {
    background: linear-gradient(135deg, #f97316 0%, #ff5722 50%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.brand-tagline {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #94a3b8;
}

.btn-vypnex {
    background: linear-gradient(135deg, #ff5722 0%, #f97316 100%);
    border: none;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 4px 14px 0 rgba(249, 115, 22, 0.39);
    transition: all 0.25s ease;
}

.btn-vypnex:hover {
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(249, 115, 22, 0.5);
    transform: translateY(-1px);
}

.btn-vypnex-blue {
    background: linear-gradient(135deg, #0070f3 0%, #0284c7 100%);
    border: none;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 4px 14px 0 rgba(0, 112, 243, 0.39);
    transition: all 0.25s ease;
}

.btn-vypnex-blue:hover {
    background: linear-gradient(135deg, #07387d 0%, #0369a1 100%);
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(0, 112, 243, 0.5);
    transform: translateY(-1px);
}

.brand-gradient-bar {
    height: 3px;
    background: linear-gradient(90deg, #0070f3 0%, #38bdf8 45%, #ff5722 55%, #f59e0b 100%);
    width: 100%;
}

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

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--vypnex-bg-gray);
    color: #1e293b;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================
   PORTAL LAYOUT FRAMEWORK
   ========================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

.app-sidebar {
    width: var(--vypnex-sidebar-width);
    background-color: var(--vypnex-sidebar-bg);
    color: #94a3b8;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    overflow-y: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
}

.app-sidebar .sidebar-brand {
    height: var(--vypnex-header-height);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    font-size: 1.2rem;
    font-weight: 800;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    letter-spacing: 0.5px;
}

.app-sidebar .nav-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    padding: 1.1rem 1.25rem 0.4rem;
    letter-spacing: 0.06em;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    color: #94a3b8;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
}

.app-sidebar .nav-link i {
    font-size: 1.1rem;
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

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

.app-sidebar .nav-link.active {
    color: #ffffff;
    background-color: var(--vypnex-primary);
    font-weight: 600;
    border-left: 4px solid #38bdf8;
}

/* Sidebar Backdrop on Mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(2px);
    z-index: 1045;
    transition: opacity 0.3s ease;
}

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

.app-main {
    margin-left: var(--vypnex-sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.3s ease;
}

.app-header {
    height: var(--vypnex-header-height);
    background-color: #ffffff;
    border-bottom: 1px solid var(--vypnex-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.app-content {
    padding: 1.5rem;
    flex: 1;
    min-width: 0;
}

.app-footer {
    padding: 1rem 1.5rem;
    background-color: #ffffff;
    border-top: 1px solid var(--vypnex-border);
    color: #64748b;
    font-size: 0.85rem;
}

/* ==========================================
   CARDS, METRICS & COMPONENTS
   ========================================== */
.card {
    border: 1px solid var(--vypnex-border);
    border-radius: 12px;
    box-shadow: var(--vypnex-card-shadow);
    background-color: #ffffff;
    margin-bottom: 1.25rem;
}

.card-header {
    background-color: #ffffff;
    border-bottom: 1px solid var(--vypnex-border);
    padding: 0.9rem 1.25rem;
    font-weight: 600;
    color: #0f172a;
}

.metric-card {
    padding: 1.25rem;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid var(--vypnex-border);
    box-shadow: var(--vypnex-card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
    box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.08);
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.metric-card .metric-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.metric-card .metric-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ==========================================
   TABLES & HORIZONTAL SCROLL ENHANCEMENT
   ========================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    position: relative;
    max-width: 100%;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.table {
    width: 100%;
    margin-bottom: 0;
    vertical-align: middle;
}

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

.table td {
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--vypnex-border);
    font-size: 0.88rem;
}

/* ==========================================
   BADGES, BUTTONS & FORM INPUTS
   ========================================== */
.badge {
    font-weight: 600;
    padding: 0.35em 0.65em;
    border-radius: 6px;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
}

.btn {
    font-weight: 500;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.btn-primary {
    background-color: var(--vypnex-primary);
    border-color: var(--vypnex-primary);
}

.btn-primary:hover {
    background-color: var(--vypnex-primary-dark);
    border-color: var(--vypnex-primary-dark);
}

/* Form Controls */
.form-control {
    border: 1px solid var(--vypnex-border);
    border-radius: 8px;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    min-height: 42px;
    color: #0f172a;
    background-color: #ffffff;
}

.form-control-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.84rem;
    min-height: 34px;
    border-radius: 6px;
}

/* Form Select Dropdown: Explicit Right Padding to prevent Arrow Collisions */
.form-select, select.form-select {
    display: block;
    width: 100%;
    border: 1px solid var(--vypnex-border);
    border-radius: 8px;
    padding: 0.55rem 2.5rem 0.55rem 0.85rem !important;
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1.5;
    color: #0f172a;
    background-color: #ffffff !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23334155' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.85rem center !important;
    background-size: 14px 10px !important;
    min-height: 44px;
    cursor: pointer !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-user-select: auto !important;
    user-select: auto !important;
    position: relative;
    z-index: 2;
}

.form-select-sm {
    padding: 0.35rem 2rem 0.35rem 0.65rem !important;
    background-position: right 0.65rem center !important;
    background-size: 12px 8px !important;
    font-size: 0.84rem !important;
    min-height: 36px !important;
    border-radius: 6px;
}

.form-select-lg {
    padding: 0.75rem 3rem 0.75rem 1rem !important;
    background-position: right 1rem center !important;
    background-size: 16px 12px !important;
    min-height: 48px !important;
}

.form-control:focus, .form-select:focus {
    border-color: var(--vypnex-primary-light);
    box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.15);
    outline: 0;
}

/* Input Group with Select dropdowns */
.input-group > .form-select {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
    padding-right: 2.25rem !important;
}

.input-group > .input-group-text {
    background-color: #f8fafc;
    border-color: var(--vypnex-border);
    color: #64748b;
    font-size: 0.88rem;
}

/* Dropdown toggles & carets */
.dropdown-toggle::after {
    margin-left: 0.5em;
    vertical-align: 0.15em;
}

.dropdown-menu {
    border: 1px solid var(--vypnex-border);
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
    padding: 0.5rem 0;
    font-size: 0.88rem;
    max-width: calc(100vw - 20px) !important;
    z-index: 1060;
}

.dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
    transform: none !important;
}

.dropdown-item {
    padding: 0.5rem 1rem;
    font-weight: 500;
    white-space: normal;
    word-break: break-word;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
    color: var(--vypnex-primary);
}

/* ==========================================
   PUBLIC NAVBAR STYLING
   ========================================== */
.navbar-toggler {
    padding: 0.4rem 0.6rem;
    font-size: 1.25rem;
    line-height: 1;
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 8px;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

/* ==========================================
   MOVEABLE FLOATING SMART CALCULATOR WIDGET
   ========================================== */
.floating-calc-widget {
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    z-index: 99999 !important;
}

#toggleFloatingCalc {
    z-index: 99998 !important;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#toggleFloatingCalc:active {
    cursor: grabbing !important;
}

#vypnexCalcHeader {
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#vypnexCalcHeader:active {
    cursor: grabbing !important;
}

.floating-calc-widget:hover {
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.45) !important;
}

/* =========================================================================
   UNIVERSAL RESPONSIVE MODAL TOUCH SCROLL ENGINE
   ========================================================================= */
.modal {
    -webkit-overflow-scrolling: touch !important;
}

.modal-dialog-scrollable {
    height: calc(100% - 1rem) !important;
    max-height: calc(100dvh - 1rem) !important;
    display: flex !important;
}

.modal-dialog-scrollable .modal-content,
.modal-dialog-scrollable form.modal-content {
    max-height: 100% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    border-radius: 14px !important;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    flex: 1 1 auto !important;
    overscroll-behavior-y: contain !important;
}

.modal-dialog-scrollable .modal-header,
.modal-dialog-scrollable .modal-footer {
    flex-shrink: 0 !important;
}

/* Fallback if form is nested inside modal-content */
.modal-dialog-scrollable .modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
    flex: 1 1 auto !important;
}

.modal-dialog-scrollable .modal-content > form > .modal-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    flex: 1 1 auto !important;
    overscroll-behavior-y: contain !important;
}

.modal-dialog-scrollable .modal-content > form > .modal-header,
.modal-dialog-scrollable .modal-content > form > .modal-footer {
    flex-shrink: 0 !important;
}

/* Hide Floating Calculator trigger button when any modal or offcanvas is open to avoid blocking form inputs */
body.modal-open #toggleFloatingCalc,
body.modal-open #vypnexCalculatorModal,
body.offcanvas-open #toggleFloatingCalc,
body.offcanvas-open #vypnexCalculatorModal,
.modal.show ~ #toggleFloatingCalc,
.modal.show ~ #vypnexCalculatorModal,
.modal-backdrop.show ~ #toggleFloatingCalc,
.modal-backdrop ~ #toggleFloatingCalc {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
}

/* ==========================================
   RESPONSIVE MEDIA QUERIES (FULL MOBILE SUITE)
   ========================================== */

/* Tablets & Small Laptops (<= 991.98px) */
@media (max-width: 991.98px) {
    .app-sidebar {
        left: auto !important;
        right: 0 !important;
        transform: translateX(100%) !important;
        box-shadow: -6px 0 25px rgba(0, 0, 0, 0.45);
        width: 280px;
    }

    .app-sidebar.show {
        transform: translateX(0) !important;
    }

    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .app-header {
        height: 60px;
        padding: 0 1rem;
    }

    .app-content {
        padding: 1rem 0.85rem;
    }

    /* Public Navbar collapse menu */
    .navbar-collapse {
        background-color: #0f172a;
        padding: 1.25rem;
        border-radius: 12px;
        margin-top: 0.75rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    }

    .navbar-collapse .nav-link {
        padding: 0.65rem 0.5rem !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .navbar-collapse .d-flex {
        flex-direction: column;
        width: 100%;
        margin-top: 1rem;
    }

    .navbar-collapse .btn {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }
}

/* Mobile Phones (<= 767.98px) */
@media (max-width: 767.98px) {
    /* Prevent iOS input auto-zoom by ensuring minimum 16px text */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="tel"],
    input[type="search"],
    select.form-select,
    textarea.form-control {
        font-size: 16px !important;
    }

    .form-select {
        padding-right: 2.5rem !important;
        background-position: right 0.75rem center !important;
    }

    .form-select-sm {
        padding-right: 2rem !important;
        background-position: right 0.55rem center !important;
    }

    /* Headings */
    h1, .display-4 {
        font-size: 1.7rem !important;
        line-height: 1.25 !important;
    }

    h2, .display-5, .display-6 {
        font-size: 1.4rem !important;
        line-height: 1.3 !important;
    }

    h3 {
        font-size: 1.2rem !important;
    }

    h4 {
        font-size: 1.1rem !important;
    }

    .lead {
        font-size: 0.95rem !important;
    }

    /* Container & Content Spacing */
    .container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    .app-main {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        width: 100% !important;
    }

    .app-content {
        padding: 0.75rem 0.5rem 85px !important; /* Bottom padding prevents floating buttons from covering numbers */
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    .card {
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .card-body {
        padding: 0.75rem 0.65rem !important;
        max-width: 100% !important;
    }

    /* Page Header Action Stacking */
    .d-flex.justify-content-between.align-items-center {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.65rem;
    }

    .d-flex.justify-content-between.align-items-center > .d-flex {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .d-flex.justify-content-between.align-items-center > .d-flex .btn,
    .d-flex.justify-content-between.align-items-center > a.btn {
        flex: 1 1 auto;
    }

    /* Filter rows & form bars stack gracefully */
    form.row.g-2.align-items-center > div[class*="col-"],
    form.row.g-3 > div[class*="col-"] {
        width: 100% !important;
        margin-bottom: 0.35rem;
    }

    /* Select option text display improvement */
    select.form-select {
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        max-width: 100%;
    }

    /* Modal Full-Width on Mobile */
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: 96%;
    }

    /* Metric Cards on Mobile */
    .metric-card {
        padding: 0.9rem;
    }

    .metric-icon {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        margin-right: 0.65rem !important;
    }

    .metric-card .metric-value {
        font-size: 1.35rem;
    }

    .metric-card .metric-label {
        font-size: 0.75rem;
    }

    /* Tables on Mobile */
    .table th, .table td {
        padding: 0.55rem 0.6rem;
        font-size: 0.82rem;
    }

    .table-responsive {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 8px;
    }

    /* Calculator Widget on Mobile */
    .floating-calc-widget {
        width: calc(100vw - 20px) !important;
        max-width: 320px;
    }

    #toggleFloatingCalc {
        bottom: 12px !important;
        right: 12px !important;
        width: 44px !important;
        height: 44px !important;
        font-size: 1rem !important;
        opacity: 0.92;
        z-index: 1035 !important;
    }

    /* Word Break for Long Monospace Identifiers */
    .font-monospace, .text-truncate-mobile {
        word-break: break-all;
        overflow-wrap: anywhere;
    }
}

/* Small Phones (<= 575.98px) */
@media (max-width: 575.98px) {
    .btn {
        padding: 0.45rem 0.75rem;
        font-size: 0.82rem;
    }

    .metric-card {
        padding: 0.75rem;
    }

    .metric-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .metric-card .metric-value {
        font-size: 1.2rem;
    }

    .card {
        margin-bottom: 0.85rem;
        border-radius: 10px;
    }

    .card-header {
        padding: 0.75rem 0.9rem;
        font-size: 0.9rem;
    }

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

/* ==========================================================================
   Universal Modal & Mobile Touch Scroll Engine
   ========================================================================== */
.modal {
    -webkit-overflow-scrolling: touch !important;
}

.modal-dialog-scrollable {
    height: calc(100% - 1rem) !important;
    max-height: calc(100dvh - 1rem) !important;
    display: flex !important;
}

.modal-dialog-scrollable .modal-content,
.modal-dialog-scrollable form.modal-content {
    max-height: 100% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    flex: 1 1 auto !important;
    overscroll-behavior-y: contain !important;
}

/* Fallback for form nested inside modal-content if any */
.modal-dialog-scrollable .modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
}

.modal-dialog-scrollable .modal-content > form > .modal-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    flex: 1 1 auto !important;
    overscroll-behavior-y: contain !important;
}

/* Hide floating calculator button & widget when any modal is open */
body.modal-open #toggleFloatingCalc,
body.modal-open #vypnexCalculatorModal,
.modal.show ~ #toggleFloatingCalc,
.modal.show ~ #vypnexCalculatorModal {
    display: none !important;
    pointer-events: none !important;
}
