/* assets/css/style.css */
:root {
    --bg-color: #0f172a; /* Slate 900 */
    --sidebar-bg: #1e293b; /* Slate 800 */
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6; /* Blue 500 */
    --accent-hover: #2563eb;
    
    --grad-1: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    --grad-2: linear-gradient(135deg, #f43f5e 0%, #fb923c 100%);
    --grad-3: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
    --grad-4: linear-gradient(135deg, #10b981 0%, #3b82f6 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.amis-image-wrap {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
}

.amis-image-empty {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-style: italic;
    white-space: nowrap;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    padding: 0 0 20px 0;
    box-shadow: 4px 0 10px rgba(0,0,0,0.3);
    z-index: 10;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar .logo {
    height: 110px;
    padding: 0 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 20px;
    box-sizing: border-box;
    text-align: center;
}

.sidebar .nav {
    list-style: none;
    padding: 0 8px;
}

.sidebar .nav li.nav-section-title {
    padding: 14px 10px 6px 12px;
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #94a3b8;
    background: transparent !important;
    cursor: default;
    border-left: none !important;
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .nav li.nav-section-title:first-child {
    margin-top: 0;
    padding-top: 2px;
    border-top: none;
}

.sidebar .nav li:not(.nav-section-title) {
    padding: 10px 14px 10px 24px;
    margin: 2px 0;
    cursor: pointer;
    color: #94a3b8;
    font-size: 0.92rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 6px;
    border-left: 3px solid transparent;
}

.sidebar .nav li:not(.nav-section-title):hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    padding-left: 26px;
}

.sidebar .nav li:not(.nav-section-title).active {
    background-color: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    font-weight: 600;
    border-left: 3px solid #3b82f6;
    padding-left: 24px;
}

/* Sub Navigation */
.sub-nav-container {
}
.sub-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 20px;
}
.sub-nav li {
    padding: 10px 20px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
    font-weight: 500;
}
.sub-nav li:hover {
    color: var(--text-primary);
}
.sub-nav li.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* --- REMOVED: sticky-sub-nav no longer used (sub-nav is in fixed-top-bar) --- */


.sticky-anchors {
    background-color: var(--bg-color);
    padding: 14px 30px 16px 30px;
    border-top: 1px solid rgba(255,255,255,0.05);
    border-bottom: 2px solid rgba(255,255,255,0.07);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.sticky-anchors a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.85rem;
}
.sticky-anchors a:hover {
    text-decoration: underline;
}

/* Main Content */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* important: children handle their own scroll */
}

/* Fixed top bar: header + sub-nav, never scrolls */
.fixed-top-bar {
    min-height: 110px;
    height: auto;
    box-sizing: border-box;
    flex-shrink: 0;
    background-color: var(--bg-color);
    position: relative;
    z-index: 100;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.scroll-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto !important;
    display: flex;
    flex-direction: column;
}

#tab-overview {
    overflow-y: auto !important;
    height: 100%;
}

#tab-crm-orders {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    padding-bottom: 60px !important;
}

.tab-content {
    padding: 20px 30px 30px 30px;
}

.tab-content.active-flex {
    display: flex !important;
    flex: 1;
    flex-direction: column;
    min-height: 0; /* prevent flex blowout */
    overflow: hidden;
}

.sub-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#sub-inventory-report, #sub-inventory-guide {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: block;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px 15px 30px;
}

.user-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    border-radius: 12px;
    padding: 20px;
    color: #fff;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px rgba(0,0,0,0.2);
}

.card h3 {
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.9;
    margin-bottom: 10px;
}

.card h2 {
    font-size: 1.8rem;
    font-weight: 700;
}

.card-gradient-1 { background: var(--grad-1); }
.card-gradient-2 { background: var(--grad-2); }
.card-gradient-3 { background: var(--grad-3); }
.card-gradient-4 { background: var(--grad-4); }

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.crm-widgets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

@media (max-width: 1024px) {
    .crm-widgets-grid {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.chart-container h3 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* Tables */
.table-container {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    
    /* Flexbox layout to pass height to wrapper */
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.table-container h2 {
    margin-bottom: 20px;
    font-size: 1.2rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

/* DataTables Overrides for Dark Mode */
.dataTables_wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* pass height down */
}

.dataTables_wrapper .top {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}
.dataTables_wrapper .bottom {
    flex-shrink: 0;
}

.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate {
    color: var(--text-secondary) !important;
    margin-bottom: 0px !important;
}

.dt-buttons {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-export-excel {
    background: #10b981;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.btn-export-excel:hover {
    background: #059669;
}
/* Custom scrollbar for DataTables scrollBody */
.dataTables_scrollBody::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}
.dataTables_scrollBody::-webkit-scrollbar-track {
    background: transparent;
}
.dataTables_scrollBody::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}
.dataTables_scrollBody::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}

/* Custom wrapper for table scrolling to enable pure CSS sticky headers */
.table-scroll-wrapper {
    flex: 1; /* take up remaining height from dataTables_wrapper */
    min-height: 0; /* prevent flex blowout */
    overflow: auto; /* Handles its own scrolling and traps the table */
    width: 100%;
}

table.dataTable {
    border-bottom: 1px solid #334155 !important;
    border-collapse: collapse !important;
    width: 100% !important;
}

table.dataTable thead th, table.dataTable thead td {
    padding: 10px 18px;
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background-color: var(--card-bg) !important;
    color: var(--text-secondary);
    border-bottom: 2px solid rgba(255,255,255,0.1);
}

/* Alternate row color for readability */
table.dataTable tbody tr:nth-child(even) {
    background-color: rgba(255,255,255,0.02) !important;
}

/* Right align numerical columns in report tables */
#sub-inventory-report table.dataTable thead th:not(:first-child),
#sub-inventory-report table.dataTable tbody td:not(:first-child),
#sub-inventory-report table.dataTable tfoot th:not(:first-child) {
    text-align: right !important;
}

table.dataTable tbody tr {
    background-color: var(--card-bg) !important;
}

table.dataTable tbody tr:hover {
    background-color: rgba(255,255,255,0.05) !important;
}

/* Highlight Total Row (Footer) */
#sub-inventory-report table.dataTable tfoot th,
#sub-inventory-report table.dataTable tfoot td {
    background-color: rgba(56, 189, 248, 0.1) !important;
    color: var(--accent) !important;
    border-top: 2px solid var(--accent) !important;
    font-size: 1.05rem;
}

table.dataTable tbody td {
    border-top: 1px solid #334155 !important;
    color: var(--text-primary);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-secondary) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--accent) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 5px;
}

input[type="search"], select {
    background-color: #0f172a;
    border: 1px solid #334155;
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    outline: none;
}

/* Custom styles for DataTables Layout */
.dataTables_wrapper .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.dataTables_wrapper .dataTables_filter {
    float: none !important;
    text-align: left !important;
    margin: 0 !important;
}

.dataTables_wrapper .bottom {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 15px;
    gap: 20px;
}

.dataTables_wrapper .dataTables_info {
    order: 1;
    margin-right: auto !important;
    float: none !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.dataTables_wrapper .dataTables_length {
    order: 2;
    float: none !important;
    margin: 0 !important;
}

.dataTables_wrapper .dataTables_paginate {
    order: 3;
    float: none !important;
    margin: 0 !important;
}

/* Truncate Text for Name Column */
.truncate-text {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Right-align numeric columns (DataTables dt-right class) */
table.dataTable td.dt-right,
table.dataTable th.dt-right {
    text-align: right !important;
}

.nowrap {
    white-space: nowrap;
    width: 1%;
}

/* colResizable Grips */
.JCLRgrip {
    cursor: col-resize !important;
    background-color: transparent;
}
.JCLRgrip .grip {
    width: 2px;
    height: 100%;
    background-color: var(--accent);
    opacity: 0;
    transition: opacity 0.2s;
}
.JCLRgrip:hover .grip, .JCLRgrip.dragging .grip {
    opacity: 1;
}

/* Custom Scrollbars for Dark Theme */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: #0f172a;
}
::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* Shopee Filter Buttons & Expandable Row Styles */
.shopee-filter-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid #475569;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}
.shopee-filter-btn:hover, .shopee-filter-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-weight: 600;
}

.shopee-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge-match { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid #10b981; }
.badge-discrepancy-under { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid #ef4444; }
.badge-discrepancy-over { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid #f59e0b; }
.badge-pending { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; border: 1px solid #64748b; }

.shopee-item-subtable {
    width: 100%;
    margin: 10px 0;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
}
.shopee-item-subtable th {
    background: rgba(255,255,255,0.05) !important;
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
}
.shopee-item-subtable td {
    font-size: 0.85rem !important;
    padding: 8px 12px !important;
}
::-webkit-scrollbar-corner {
    background: transparent;
}
