/* ==========================================================================
   custom.css - Sistem Ritel Sayur & Buah PT. PNL
   Theme System: Pure CSS Variables with zero PHP conditionals
   Supports: [data-bs-theme="light"] and [data-bs-theme="dark"]
   ========================================================================== */

:root,
[data-bs-theme="light"] {
    /* Backgrounds */
    --bg-body-custom: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
    --bg-sidebar-active: #059669;
    --bg-table-stripe: rgba(0, 0, 0, 0.02);

    /* Text Colors (WCAG AA Compliant >= 4.5:1) */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-sidebar: #94a3b8;
    --text-sidebar-bright: #ffffff;

    /* Borders */
    --border-subtle: #e2e8f0;
    --border-medium: #cbd5e1;

    /* Brand Colors - Fresh Organic Commodity */
    --brand-primary: #059669;
    --brand-primary-hover: #047857;
    --brand-primary-subtle: #ecfdf5;
    --brand-primary-text: #065f46;

    --brand-accent: #d97706; /* Warm Harvest Gold */
    --brand-danger: #dc2626;
    --brand-info: #0284c7;

    /* Shadows */
    --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.08);

    /* Status Badges */
    --badge-ok-bg: #ecfdf5;
    --badge-ok-text: #065f46;
    --badge-ng-bg: #fef2f2;
    --badge-ng-text: #991b1b;
    --badge-booking-bg: #eff6ff;
    --badge-booking-text: #1e40af;
}

[data-bs-theme="dark"] {
    /* Backgrounds */
    --bg-body-custom: #0b1120;
    --bg-surface: #1e293b;
    --bg-surface-elevated: #334155;
    --bg-sidebar: #070d19;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
    --bg-sidebar-active: #059669;
    --bg-table-stripe: rgba(255, 255, 255, 0.02);

    /* Text Colors */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-sidebar: #94a3b8;
    --text-sidebar-bright: #ffffff;

    /* Borders */
    --border-subtle: #334155;
    --border-medium: #475569;

    /* Brand Colors */
    --brand-primary: #10b981;
    --brand-primary-hover: #34d399;
    --brand-primary-subtle: rgba(16, 185, 129, 0.15);
    --brand-primary-text: #a7f3d0;

    --brand-accent: #f59e0b;
    --brand-danger: #ef4444;
    --brand-info: #38bdf8;

    /* Shadows */
    --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
    --card-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.5);

    /* Status Badges */
    --badge-ok-bg: rgba(16, 185, 129, 0.15);
    --badge-ok-text: #34d399;
    --badge-ng-bg: rgba(239, 68, 68, 0.15);
    --badge-ng-text: #f87171;
    --badge-booking-bg: rgba(56, 189, 248, 0.15);
    --badge-booking-text: #7dd3fc;
}

/* ==========================================================================
   Base Elements & Reset
   ========================================================================== */

body {
    background-color: var(--bg-body-custom);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Accessible Focus States (R-32) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--brand-primary) !important;
    outline-offset: 2px !important;
}

/* ==========================================================================
   Button Consistency & Universal Vertical Centering Alignment
   ========================================================================== */

/* Min Tap Target Size (R-03) untuk tombol standar dan kontrol form */
.btn:not(.btn-sm):not(.btn-xs):not(.btn-close),
.nav-link,
.form-control,
.form-select {
    min-height: 42px;
}

/* Pastikan SEMUA button selalu flex terpusat simetris antara atas dan bawah */
.btn:not(.btn-close) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    line-height: 1.25;
    text-align: center;
}

/* Penyelarasan ikon di dalam button: tengah sempurna vertikal & horizontal */
.btn:not(.btn-close) > i,
.btn:not(.btn-close) > .bi,
.btn:not(.btn-close) > svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: 0;
}

/* Hilangkan offset vertikal -0.125em bawaan Bootstrap Icons di dalam tombol */
.btn:not(.btn-close) > i::before,
.btn:not(.btn-close) > .bi::before {
    vertical-align: 0 !important;
}

/* Penyelarasan teks atau span pembungkus di dalam button */
.btn:not(.btn-close) > span {
    display: inline-flex;
    align-items: center;
    line-height: 1.25;
}

/* Button Small (.btn-sm) proporsional & presisi di tengah */
.btn-sm:not(.btn-close) {
    min-height: 36px;
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.25;
}

/* Button Large (.btn-lg) */
.btn-lg:not(.btn-close) {
    min-height: 48px;
    padding: 0.65rem 1.25rem;
    font-size: 1.05rem;
    line-height: 1.25;
}

/* ==========================================================================
   Admin Layout Structure
   ========================================================================== */

.app-wrapper {
    display: flex;
    flex: 1;
    width: 100%;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: all 0.25s ease-in-out;
    z-index: 1040;
}

.sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
    color: var(--text-sidebar-bright);
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar-brand i {
    color: var(--brand-primary);
    font-size: 1.35rem;
}

.sidebar-menu {
    flex: 1;
    padding: 0.75rem 0.4rem;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar halus untuk sidebar */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}
.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.menu-heading {
    padding: 0.65rem 0.85rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #475569;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 0.45rem;
    transition: all 0.15s ease;
    margin-bottom: 0.15rem;
}

.sidebar-link i:first-child,
.sidebar-link .menu-icon {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link:hover {
    color: var(--text-sidebar-bright);
    background-color: var(--bg-sidebar-hover);
}

.sidebar-link.active {
    color: var(--text-sidebar-bright);
    background-color: var(--bg-sidebar-active);
    font-weight: 600;
}

/* Collapsible Sub-menu Styling */
.sidebar-collapse-toggle {
    cursor: pointer;
    user-select: none;
}

.sidebar-collapse-toggle .arrow-icon {
    font-size: 0.75rem;
    margin-left: auto;
    transition: transform 0.25s ease-in-out;
    opacity: 0.7;
}

.sidebar-collapse-toggle[aria-expanded="true"] {
    color: var(--text-sidebar-bright);
    background-color: var(--bg-sidebar-hover);
}

.sidebar-collapse-toggle[aria-expanded="true"] .arrow-icon {
    transform: rotate(180deg);
    opacity: 1;
}

.sidebar-link.parent-active {
    color: var(--text-sidebar-bright);
    font-weight: 600;
}

.sidebar-submenu {
    background-color: rgba(0, 0, 0, 0.2);
    margin: 0.15rem 0.35rem 0.4rem 0.35rem;
    padding: 0.3rem 0;
    border-radius: 0.45rem;
    border-left: 2px solid rgba(255, 255, 255, 0.08);
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.48rem 0.85rem 0.48rem 1rem;
    margin: 0.1rem 0.35rem;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
}

.sidebar-sublink i {
    font-size: 0.95rem;
    width: 18px;
    text-align: center;
    opacity: 0.75;
    flex-shrink: 0;
}

.sidebar-sublink:hover {
    color: var(--text-sidebar-bright);
    background-color: var(--bg-sidebar-hover);
}

.sidebar-sublink:hover i {
    opacity: 1;
}

.sidebar-sublink.active {
    color: #ffffff;
    background-color: var(--bg-sidebar-active);
    font-weight: 600;
}

.sidebar-sublink.active i {
    opacity: 1;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.8rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
}

.top-navbar {
    height: 64px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.content-body {
    flex: 1;
    padding: 1.5rem;
}

/* ==========================================================================
   Cards & Surfaces
   ========================================================================== */

.card-custom {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
    transition: all 0.2s ease;
}

.card-custom:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header-custom {
    padding: 1.1rem 1.25rem;
    background-color: transparent;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ==========================================================================
   Tables & Data
   ========================================================================== */

.table-custom {
    color: var(--text-primary);
    width: 100% !important;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table-custom th {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-size: 0.76rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
    white-space: nowrap;
}

.table-custom td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.table-custom tbody tr {
    transition: background-color 0.15s ease;
}

.table-custom tbody tr:hover {
    background-color: var(--bg-table-stripe);
}

/* ==========================================================================
   DataTables Custom Wrapper Styling (Light & Dark Mode)
   ========================================================================== */

.dataTables_wrapper {
    padding: 0.75rem 0;
    color: var(--text-secondary);
}

.dataTables_wrapper .row:first-child {
    padding: 0.5rem 1.25rem 0.85rem;
    align-items: center;
    margin: 0;
}

.dataTables_wrapper .row:last-child {
    padding: 1rem 1.25rem 0.5rem;
    align-items: center;
    margin: 0;
    border-top: 1px solid var(--border-subtle);
}

.dataTables_wrapper .dataTables_length label {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0;
}

.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.35rem 2rem 0.35rem 0.75rem;
    font-size: 0.84rem;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    cursor: pointer;
}

.dataTables_wrapper .dataTables_filter label {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 0;
    width: 100%;
}

.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.4rem 0.85rem;
    font-size: 0.84rem;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    transition: all 0.2s ease;
    min-width: 200px;
    max-width: 100%;
}

.dataTables_wrapper .dataTables_filter input:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
    outline: none;
}

.dataTables_wrapper .dataTables_info {
    font-size: 0.84rem;
    color: var(--text-secondary);
    padding-top: 0.3rem;
}

.dataTables_wrapper .dataTables_paginate {
    display: flex;
    justify-content: flex-end;
}

.dataTables_wrapper .dataTables_paginate .pagination {
    margin-bottom: 0;
    gap: 0.3rem;
}

.dataTables_wrapper .dataTables_paginate .page-link {
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dataTables_wrapper .dataTables_paginate .page-item.active .page-link {
    background-color: #16a34a !important;
    border-color: #16a34a !important;
    color: #ffffff !important;
    font-weight: 600;
}

.dataTables_wrapper .dataTables_paginate .page-item.disabled .page-link {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    opacity: 0.45;
    border-color: var(--border-subtle);
}

.dataTables_wrapper .dataTables_paginate .page-link:hover:not(.active) {
    background-color: var(--bg-surface-elevated);
    border-color: #16a34a;
    color: #16a34a;
}

/* ==========================================================================
   Stock & Business Status Badges
   ========================================================================== */

.badge-stok-ok {
    background-color: var(--badge-ok-bg);
    color: var(--badge-ok-text);
    padding: 0.35rem 0.65rem;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.82rem;
}

.badge-stok-ng {
    background-color: var(--badge-ng-bg);
    color: var(--badge-ng-text);
    padding: 0.35rem 0.65rem;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.82rem;
}

.badge-stok-booking {
    background-color: var(--badge-booking-bg);
    color: var(--badge-booking-text);
    padding: 0.35rem 0.65rem;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.82rem;
}

/* ==========================================================================
   UI States (Empty, Loading, Error - R-27)
   ========================================================================== */

.state-empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.state-empty i {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.state-loading {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--brand-primary);
}

.state-error {
    padding: 2rem 1.5rem;
    background-color: var(--badge-ng-bg);
    border: 1px solid var(--brand-danger);
    border-radius: 0.5rem;
    color: var(--badge-ng-text);
}

/* ==========================================================================
   Theme Switcher Button
   ========================================================================== */

.btn-theme-toggle {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: 0.5rem;
    padding: 0.4rem 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-theme-toggle:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-medium);
}

/* CSS Icons for Pure CSS Theme Detection */
[data-bs-theme="light"] .theme-icon-dark {
    display: none;
}
[data-bs-theme="light"] .theme-icon-light {
    display: inline-block;
}

[data-bs-theme="dark"] .theme-icon-light {
    display: none;
}
[data-bs-theme="dark"] .theme-icon-dark {
    display: inline-block;
}

/* Mobile Responsiveness (R-03) */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -260px;
    }

    .sidebar.show {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1030;
    }

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

/* ==========================================================================
   Select2 Bootstrap 5 Integration & Dark/Light Mode Theming
   ========================================================================== */

.select2-container {
    width: 100% !important;
}

.select2-container--bootstrap-5 .select2-selection {
    min-height: 42px;
    border-color: var(--border-subtle) !important;
    background-color: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.select2-container--bootstrap-5 .select2-selection--single {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary) !important;
    line-height: 1.5;
    padding-left: 0.75rem;
    padding-right: 2rem;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
    color: var(--text-secondary) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
    right: 0.75rem;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(22, 163, 74, 0.2) !important;
}

.select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-subtle) !important;
    box-shadow: var(--card-shadow) !important;
    border-radius: 0.5rem !important;
    overflow: hidden;
    z-index: 1060;
}

.select2-container--bootstrap-5 .select2-search {
    padding: 0.5rem;
}

.select2-container--bootstrap-5 .select2-search .select2-search__field {
    background-color: var(--bg-body-custom) !important;
    border: 1px solid var(--border-subtle) !important;
    color: var(--text-primary) !important;
    border-radius: 0.375rem;
    padding: 0.4rem 0.75rem;
}

.select2-container--bootstrap-5 .select2-search .select2-search__field:focus {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 0.2rem rgba(22, 163, 74, 0.15) !important;
    outline: none !important;
}

.select2-container--bootstrap-5 .select2-results__option {
    color: var(--text-primary) !important;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--brand-primary) !important;
    color: #ffffff !important;
}

.select2-container--bootstrap-5 .select2-results__option[aria-selected="true"]:not(.select2-results__option--highlighted) {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-text) !important;
    font-weight: 600;
}

.select2-container--bootstrap-5 .select2-results__option--disabled {
    color: var(--text-secondary) !important;
    opacity: 0.6;
}

/* Ukuran Small (.form-select-sm) */
.form-select-sm + .select2-container--bootstrap-5 .select2-selection {
    min-height: 34px !important;
    font-size: 0.8125rem;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
}
