/**
 * ERP Suppliers Module - Premium CSS Styling
 */

:root {
    --sup-primary: #f97316; /* Elegant deep orange matching truck theme */
    --sup-primary-hover: #ea580c;
    --sup-bg-list: #f8fafc;
    --sup-border: #e2e8f0;
    --sup-text-main: #1e293b;
    --sup-text-muted: #64748b;
    --sup-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --sup-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* 1. Layout Module Root */
#module-suppliers {
    height: calc(100vh - 134px);
    flex-direction: column;
    background-color: #fff;
    overflow: hidden;
    font-family: 'Inter', -apple-system, sans-serif;
    min-height: 0;
}
#module-suppliers.active {
    display: flex !important;
}

/* 2. Top Header Strip */
.sup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--sup-border);
    background: #ffffff;
    flex-shrink: 0;
}

.sup-branding h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--sup-text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sup-branding p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--sup-text-muted);
}

.sup-badge {
    font-size: 0.65rem;
    background: #fef3c7;
    color: #d97706;
    padding: 2px 6px;
    border-radius: 999px;
    font-weight: 600;
}

.sup-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.sup-search-box {
    position: relative;
    width: 300px;
}

.sup-search-box i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sup-text-muted);
}

.sup-search-box input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    border-radius: 6px;
    border: 1px solid var(--sup-border);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.sup-search-box input:focus {
    outline: none;
    border-color: var(--sup-primary);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.1);
}

/* 3. Master Content Split Grid */
.sup-grid {
    display: flex;
    flex: 1;
    height: calc(100% - 70px); /* Adjust for header height */
    overflow: hidden;
}

/* Side Panel List */
.sup-sidebar {
    width: 340px;
    background: var(--sup-bg-list);
    border-right: 1px solid var(--sup-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
}

.sup-filters-panel {
    padding: 1rem;
    border-bottom: 1px solid var(--sup-border);
    background: #fff;
}

.sup-filter-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--sup-text-main);
    text-transform: uppercase;
}

.form-control-sup {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--sup-border);
    border-radius: 4px;
    font-size: 0.85rem;
}

.sup-list-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
}

/* Supplier Cards in List */
.sup-card-item {
    height: 38px;
    box-sizing: border-box;
    padding: 0 10px;
    border-radius: 6px;
    background: #fff;
    margin-bottom: 6px;
    border: 1px solid var(--sup-border);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    position: relative;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
}

.sup-card-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--sup-shadow-sm);
}

.sup-card-item.active {
    border-color: var(--sup-primary);
    background: #fff7ed;
    box-shadow: 0 1px 3px 0 rgba(249, 115, 22, 0.1);
}

.sup-card-item .card-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0 !important;
    min-height: 0 !important;
    border-bottom: none !important;
    background: transparent !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.sup-card-item h5 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #0f172a;
    max-width: 85%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.sup-card-item .fav-star {
    font-size: 0.85rem;
    color: #cbd5e1;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.15s ease;
    padding: 4px;
    margin: -4px;
}

.sup-card-item .fav-star:hover {
    transform: scale(1.2);
    color: #f59e0b;
}

.sup-card-item .fav-star.active {
    color: #f59e0b;
}

/* Main Workspace Viewport */
.sup-workspace {
    flex: 1;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.sup-centered-view {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--sup-text-muted);
    text-align: center;
}

.sup-watermark i {
    font-size: 4rem;
    color: #e2e8f0;
    margin-bottom: 1rem;
}

/* Profile / Details UI */
.sup-profile-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.sup-profile-header {
    padding: 2rem 2rem 1.5rem 2rem;
    background: linear-gradient(to right, #f8fafc, #ffffff);
    border-bottom: 1px solid var(--sup-border);
    flex-shrink: 0;
}

.sup-prof-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.sup-prof-titles h1 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 800;
    color: #0f172a;
}

.sup-prof-meta {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    color: var(--sup-text-muted);
    font-size: 0.9rem;
}

.sup-prof-meta a { color: var(--sup-primary); text-decoration: none; }
.sup-prof-meta a:hover { text-decoration: underline; }

/* Ratings Stars */
.sup-stars { color: #f59e0b; letter-spacing: 2px; }

/* Tabs Layout */
.sup-tabs {
    display: flex;
    padding: 0 2rem;
    border-bottom: 1px solid var(--sup-border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

.sup-tab-btn {
    padding: 1rem 1.5rem;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sup-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.sup-tab-btn:hover { color: var(--sup-primary); }
.sup-tab-btn.active {
    color: var(--sup-primary);
    border-bottom-color: var(--sup-primary);
}

.sup-doc-counter {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-left: 4px;
}

/* Pane Management */
.sup-tab-content {
    flex: 1;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 2rem;
    padding-top: 0 !important;
}

/* Premium Main Pane Scrollbar */
.sup-tab-content::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.sup-tab-content::-webkit-scrollbar-track {
    background: transparent;
}
.sup-tab-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.sup-tab-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
@media (prefers-color-scheme: dark) {
    .sup-tab-content::-webkit-scrollbar-thumb {
        background: #475569;
    }
    .sup-tab-content::-webkit-scrollbar-thumb:hover {
        background: #64748b;
    }
}

.sup-pane { display: none; animation: fadeIn 0.2s ease; }
.sup-pane.active { display: block; }

.sup-pane-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.sup-pane-card {
    background: #fff;
    border: 1px solid var(--sup-border);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--sup-shadow-sm);
}

.sup-pane-card h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--sup-text-main);
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 0.5rem;
}

/* Sub-Grids for Documents / Contacts */
.sup-pane-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.sup-pane-actions h4 { margin: 0; }

.sup-subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.sup-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

/* Individual Document Tile */
.sup-doc-card {
    border: 1px solid var(--sup-border);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
}

.sup-doc-card:hover {
    border-color: var(--sup-primary);
    background: #fff7ed;
}

.sup-doc-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
    color: #64748b;
}

.sup-doc-card h5 {
    font-size: 0.8rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sup-doc-card .doc-meta {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 4px;
}

/* Contacts Cards */
.sup-contact-card {
    border: 1px solid var(--sup-border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    gap: 1rem;
}

.sup-contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #64748b;
}

.sup-contact-card h5 { margin: 0; font-size: 0.95rem; }
.sup-contact-card p { margin: 2px 0; font-size: 0.8rem; color: var(--sup-text-muted); }

/* Responsive Controls */
@media (max-width: 1024px) {
    #module-suppliers {
        height: calc(100vh - 102px);
    }
    .sup-pane-split { grid-template-columns: 1fr; }
    .sup-sidebar { width: 280px; }
}

/* 📱 MOBILE & TABLET OPTIMIZATION (iPhone/iPad) */
@media (max-width: 768px) {
    .sup-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }

    .sup-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .sup-search-box {
        width: 100%;
    }

    .sup-actions button {
        width: 100%;
        justify-content: center;
        height: 44px;
    }

    .sup-grid {
        flex-direction: column;
        position: relative;
        height: calc(100% - 140px); /* Accounting for stacked header */
    }

    /* Mobile Stack System */
    .sup-sidebar {
        width: 100%;
        height: 100%;
        display: block;
        position: absolute;
        top: 0; left: 0;
        background: #ffffff;
        z-index: 1;
        transition: transform 0.3s ease;
    }

    .sup-workspace {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0; left: 0;
        background: #ffffff;
        z-index: 2;
        transform: translateX(100%); /* Hidden initially off-screen right */
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Activation Toggle Class injected by JS */
    .sup-grid.detail-active .sup-sidebar {
        transform: translateX(-100%);
    }
    .sup-grid.detail-active .sup-workspace {
        transform: translateX(0);
    }

    /* Profile Header inside details */
    .sup-profile-header {
        padding: 1rem;
    }

    .sup-prof-top {
        flex-direction: column;
        gap: 12px;
    }

    .sup-prof-titles h1 {
        font-size: 1.4rem;
    }

    .sup-prof-meta {
        flex-direction: column;
        gap: 8px;
    }

    /* Sticky Tabs row for mobile scrolling */
    .sup-tabs {
        padding: 0 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    .sup-tab-btn {
        padding: 1rem 0.75rem;
        flex-shrink: 0;
    }

    .sup-tab-content {
        padding: 1rem;
        flex: 1;
        overflow-y: auto;
    }

    /* Re-stack grids to 1 column */
    .sup-gallery-grid {
        grid-template-columns: 1fr;
    }

    .sup-subgrid {
        grid-template-columns: 1fr;
    }

    /* Modal enhancements */
    .modal-content {
        width: 95% !important;
        margin: 0 auto;
        max-height: 90vh;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Back button for mobile view only, visible only when detail loaded */
    .sup-mobile-back-btn {
        display: flex !important;
        align-items: center;
        gap: 6px;
        background: var(--sup-bg-list);
        border: 1px solid var(--sup-border);
        padding: 8px 12px;
        border-radius: 6px;
        font-weight: 600;
        color: var(--sup-text-main);
        margin-bottom: 1rem;
        font-size: 0.85rem;
        cursor: pointer;
    }
}

/* Hide mobile helper by default on desktop */
.sup-mobile-back-btn { display: none; }

/* ====================================================================
   🔤 INITIALS & GROUPED SIDEBAR LIST
   ==================================================================== */
.sup-list-divider {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    background: #f8fafc;
    padding: 6px 10px;
    margin-top: 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    border-left: 2px solid #cbd5e1;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sup-card-initial {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #f8fafc;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    flex-shrink: 0;
    transition: all 0.2s ease;
    border: 1px solid #e2e8f0;
}

.sup-card-item.active .sup-card-initial {
    background: #fff7ed;
    color: #f97316;
    border-color: #ffd8a8;
}

/* ====================================================================
   📁 SECTIONS & NOTES MANAGERS
   ==================================================================== */
.sup-sections-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.sup-pane-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 1.5rem;
    position: sticky !important;
    top: 0 !important;
    background: var(--white) !important;
    z-index: 100 !important;
    padding-top: 2rem !important;
    padding-bottom: 1.5rem !important;
    margin-top: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.sup-sec-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    padding: 1.25rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sup-sec-card.dragover {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.05);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
    transform: scale(1.005);
}

.sup-sec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sup-sec-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sup-folder-icon {
    color: #f59e0b;
    font-size: 1.2rem;
}

.sup-sec-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.sup-sec-count {
    font-size: 0.75rem;
    background: var(--bg-secondary);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 9999px;
    font-weight: 600;
}

.sup-sec-actions button {
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
}
.sup-sec-actions button:hover {
    opacity: 1;
    transform: scale(1.1);
}

.sup-sec-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    background: var(--bg-secondary);
    transition: all 0.2s ease;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sup-sec-dropzone:hover {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.05);
    color: #ea580c;
}

.sup-sec-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sup-item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
}
.sup-item-card:hover {
    border-color: var(--gray-400);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.sup-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    cursor: pointer;
    min-width: 0;
}

.sup-item-icon {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

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

.sup-item-info h5 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sup-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sup-item-move-select {
    font-size: 0.7rem !important;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--white);
    color: var(--text-muted);
    outline: none;
    cursor: pointer;
    padding: 0 4px;
}

/* Shield children from pointer events during drag to eliminate hover flickering */
.sup-sec-card.dragover * {
    pointer-events: none !important;
}

/* Drag reordering indicators within the same section */
.sup-item-card.drag-above {
    border-top: 2px solid #f97316 !important;
    position: relative;
}
.sup-item-card.drag-above::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f97316;
    z-index: 10;
}
.sup-item-card.drag-below {
    border-bottom: 2px solid #f97316 !important;
    position: relative;
}
.sup-item-card.drag-below::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f97316;
    z-index: 10;
}
