:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --secondary: #ec4899;
    --bg-color: #0f172a;
    --surface-color: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --glass-blur: 12px;
    --sidebar-w: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Outfit', sans-serif;
}

/* Glassmorphism */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.text-gradient {
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* =====================
   LAYOUT
   ===================== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar overlay — hanya desktop, tidak dipakai mobile */
.sidebar-overlay {
    display: none !important;
}

/* =====================
   SIDEBAR
   ===================== */
.sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 100;
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.sidebar-close-btn {
    display: none !important;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    border-radius: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.25s ease;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item i {
    font-size: 1.2rem;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(to right, rgba(99, 102, 241, 0.15), transparent);
    border-left: 3px solid var(--primary);
    color: var(--primary-light);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
}

.user-profile img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info strong {
    font-size: 0.9rem;
}

.user-info span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* =====================
   MAIN CONTENT
   ===================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    min-width: 0;
}

/* =====================
   TOP HEADER
   ===================== */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* Hamburger — hidden everywhere, kept for JS compat */
.hamburger-btn {
    display: none !important;
}

.header-search {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    border-radius: 20px;
    flex: 1;
    max-width: 420px;
}

.header-search input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* =====================
   BUTTONS
   ===================== */
.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.25s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 0.7rem 1.25rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    font-size: 0.9rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

/* =====================
   STATS GRID
   ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.stat-card {
    padding: 1.25rem 1.5rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    flex-shrink: 0;
}

.stat-icon.income {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.stat-icon.expense {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.stat-icon.profit {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-light);
}

.stat-icon.neutral {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.stat-details {
    display: flex;
    flex-direction: column;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
}

.stat-value {
    font-size: 1.35rem;
    font-weight: 700;
}

/* =====================
   TABLE
   ===================== */
.table-container {
    border-radius: 20px;
    padding: 1.25rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    gap: 1rem;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.9rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background 0.2s ease;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.status-badge {
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-profit {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.status-loss {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

/* =====================
   MODAL
   ===================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    width: 100%;
    max-width: 580px;
    border-radius: 20px;
    padding: 1.75rem;
    transform: translateY(24px) scale(0.98);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-body {
    overflow-y: auto;
}

/* =====================
   FORMS
   ===================== */
.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

/* =====================
   SEARCHABLE PRODUCT PICKER
   ===================== */
.product-picker {
    position: relative;
}

.product-picker-input {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.25s ease;
    font-size: 0.95rem;
    min-height: 44px;
}

.product-picker-input:hover,
.product-picker-input:focus {
    border-color: var(--primary);
    outline: none;
}

.product-picker-input.selected span {
    color: var(--text-primary) !important;
}

.product-picker-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--primary);
    border-radius: 12px;
    z-index: 300;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    display: none;
    flex-direction: column;
    max-height: 280px;
}

.product-picker-dropdown.open {
    display: flex;
}

.product-picker-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

.product-picker-search i {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.product-picker-search input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 0;
    width: 100%;
}

.product-picker-search input:focus {
    outline: none;
    border: none;
}

#productPickerList {
    list-style: none;
    overflow-y: auto;
    max-height: 220px;
}

#productPickerList li {
    padding: 0.7rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

#productPickerList li:last-child {
    border-bottom: none;
}

#productPickerList li:hover,
#productPickerList li.active {
    background: rgba(99, 102, 241, 0.15);
}

#productPickerList li .prod-name {
    font-weight: 500;
}

#productPickerList li .prod-price {
    color: var(--success);
    font-size: 0.85rem;
    white-space: nowrap;
    margin-left: 0.5rem;
}

#productPickerList li .prod-unit {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-left: 0.3rem;
}

#productPickerList .picker-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.88rem;
    padding: 1.5rem;
    cursor: default;
}

#productPickerList .picker-empty:hover {
    background: transparent;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}


input,
select {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.7rem 1rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.25s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

.glass-select option {
    background: var(--bg-color);
    color: var(--text-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.7rem 1.25rem;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
}

.input-with-prefix {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0 1rem;
}

.input-with-prefix span {
    color: var(--text-secondary);
}

.input-with-prefix input {
    background: transparent;
    border: none;
    padding-left: 0.5rem;
}

.input-with-prefix input:focus {
    border: none;
}

.input-with-prefix:focus-within {
    border-color: var(--primary);
}

.calc-preview {
    margin-top: 1.25rem;
    padding: 1rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
}

.preview-item {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
}

.profit-text {
    color: var(--success);
}

.loss-text {
    color: var(--danger);
}

/* =====================
   TOAST
   ===================== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.9rem 1.4rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
    max-width: calc(100vw - 3rem);
    font-size: 0.9rem;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.text-success {
    color: var(--success);
    font-size: 1.2rem;
}

.text-danger {
    color: var(--danger);
    font-size: 1.2rem;
}

/* =====================
   PAGINATION
   ===================== */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.page-controls {
    display: flex;
    gap: 0.5rem;
}

.page-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.45rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =====================
   COLLAPSIBLE ROWS
   ===================== */
.toggle-btn {
    width: 30px;
    height: 30px;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.toggle-btn.expanded {
    transform: rotate(180deg);
}

.details-row td {
    padding: 0 1rem 1rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.row-details-content {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.detail-item small {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

/* hide by default, show on mobile */
.display-mobile-only {
    display: none;
}

/* =====================
   LOADING / EMPTY
   ===================== */
.loading-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 2.5rem;
    opacity: 0.4;
}

/* =====================
   CHART WRAPPER — fixed height container for Chart.js
   ===================== */
#laporanPage .stats-grid {
    align-items: start;
}

/* =====================
   BOTTOM NAV BAR (mobile only)
   ===================== */
.bottom-nav {
    display: none;
    isolation: isolate;
    will-change: transform;
}

/* =====================
   MOBILE — max 768px
   ===================== */
@media (max-width: 768px) {

    /* Sidebar completely hidden on mobile */
    .sidebar {
        display: none !important;
    }

    /* Main takes full width */
    .main-content {
        margin-left: 0;
        padding: 0.875rem;
        padding-bottom: calc(70px + 0.875rem);
        /* space for bottom nav */
        gap: 1rem;
    }

    /* Header */
    .top-header {
        flex-wrap: nowrap;
        gap: 0.6rem;
    }

    .header-search {
        max-width: none;
        flex: 1;
        min-width: 0;
        padding: 0.55rem 1rem;
    }

    .header-actions .primary-btn span {
        display: none;
        /* hide text on very small, keep icon */
    }

    /* Stats — 2 col */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 0.875rem;
        gap: 0.75rem;
        border-radius: 14px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
        border-radius: 10px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Table */
    .hide-mobile {
        display: none !important;
    }

    .display-mobile-only {
        display: flex;
    }

    .data-table th,
    .data-table td {
        padding: 0.7rem 0.4rem;
        font-size: 0.82rem;
    }

    .table-container {
        border-radius: 14px;
        padding: 0.875rem;
    }

    /* Modal */
    .modal {
        padding: 1.25rem;
        border-radius: 16px;
        max-height: 92vh;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .modal-footer {
        justify-content: stretch;
    }

    .modal-footer button {
        flex: 1;
        justify-content: center;
    }

    /* Pagination */
    .pagination-container {
        flex-direction: column;
        text-align: center;
    }

    /* Toast bottom center, above bottom nav */
    .toast {
        bottom: 80px;
        left: 1rem;
        right: 1rem;
        width: auto;
    }

    /* Laporan — stack vertikal di mobile */
    #laporanPage .stats-grid {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    /* Bottom Nav */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: rgba(15, 23, 42, 0.97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border-color);
        z-index: 9999;
        justify-content: space-around;
        align-items: stretch;
        padding: 0 0.5rem;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
        touch-action: manipulation;
        pointer-events: auto;
        /* Force own GPU compositing layer — prevents being occluded */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        flex: 1;
        padding: 0.4rem 0.5rem;
        border-radius: 10px;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.68rem;
        font-weight: 500;
        cursor: pointer;
        background: transparent;
        border: none;
        transition: color 0.2s ease, background 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        position: relative;
        z-index: 1;
        /* Prevent anything from blocking over these buttons */
        pointer-events: auto;
    }

    .bottom-nav-item i {
        font-size: 1.4rem;
        transition: transform 0.2s ease;
    }

    .bottom-nav-item.active {
        color: var(--primary-light);
    }

    .bottom-nav-item.active i {
        transform: scale(1.1);
    }

    .bottom-nav-item:active {
        background: rgba(255, 255, 255, 0.05);
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        flex-direction: row;
    }

    .primary-btn {
        padding: 0.6rem 0.9rem;
    }
}

/* Tablet — medium */
@media (min-width: 769px) and (max-width: 1100px) {
    :root {
        --sidebar-w: 220px;
    }

    .main-content {
        padding: 1.25rem 1.5rem;
    }

    .header-search {
        max-width: 300px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}