:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #475569;
    --accent-color: #f59e0b;
    --bg-color: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --surface: #334155;
    --surface-light: #475569;
    --surface-dark: #0f172a;
    --shadow-color: rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    display: flex;
    overflow-x: hidden;
    /* Prevent body scroll if sidebar is sticky */
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

* {
    box-sizing: border-box;
}

/* Sidebar - Modern Design */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    height: 100vh;
    border-right: 1px solid rgba(59, 130, 246, 0.2);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.3);
}

.logo-area {
    padding: 25px 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.15);
    display: flex;
    align-items: center;
    gap: 15px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.1) 0%, transparent 100%);
}

.logo-area h2 {
    margin: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.5rem;
    letter-spacing: 1px;
}

/* Replaced .nav-links with .nav-menu to match header.php */
.nav-menu {
    flex: 1;
    padding: 15px 10px;
    overflow-y: auto;
    list-style: none;
}

.nav-item {
    padding: 0;
    margin-bottom: 4px;
}

.nav-link {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    color: #94a3b8;
    transition: all 0.3s ease;
    font-weight: 500;
    text-decoration: none;
    border-radius: 12px;
    margin: 0 5px;
    position: relative;
    overflow: hidden;
}

.nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #3b82f6 0%, #60a5fa 100%);
    border-radius: 0 4px 4px 0;
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.nav-link:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    transform: translateX(5px);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.1) 100%);
    color: #60a5fa;
}

.nav-link.active::before {
    transform: scaleY(1);
}

.nav-link i {
    width: 24px;
    text-align: center;
    font-size: 1.1em;
    transition: transform 0.3s ease;
}

.nav-link:hover i {
    transform: scale(1.2);
}

.user-profile {
    padding: 20px 15px;
    border-top: 1px solid rgba(59, 130, 246, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.8) 0%, rgba(30, 41, 59, 0.5) 100%);
    margin: 10px;
    border-radius: 12px;
}

.sidebar-footer {
    /* Kept for compatibility if used elsewhere, but user-profile is current footer */
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 280px;
    /* Sidebar width */
    padding: 30px;
    width: calc(100% - 280px);
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px var(--shadow-color);
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn.secondary {
    background: var(--surface);
    color: white;
}

.btn.secondary:hover {
    background: var(--surface-light);
}

.btn.danger {
    background: var(--danger-color);
    color: white;
}

.btn.danger:hover {
    opacity: 0.9;
}

.btn.success {
    background: var(--success-color);
    color: white;
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface-dark);
    color: white;
    font-size: 1rem;
    transition: 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, var(--bg-card), var(--surface));
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin: 10px 0;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.stat-icon {
    float: right;
    font-size: 1.5rem;
    opacity: 0.5;
    color: var(--primary-color);
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid;
}

.alert.success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success-color);
    color: var(--success-color);
}

.alert.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.alert.warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: 0.3s;
        position: fixed;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
        z-index: 1001;
        /* Higher than overlay */
    }

    .mobile-close-btn {
        display: block !important;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 15px;
    }

    .mobile-header {
        display: flex !important;
    }
}

.mobile-header {
    display: none;
    padding: 15px;
    background: var(--bg-card);
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    border-radius: 12px;
}

/* Global Search (New) */
#globalSearch {
    transition: 0.3s;
    width: 250px;
}

#globalSearch:focus {
    width: 350px;
}

.search-container {
    position: relative;
}

.search-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 100%;
    min-width: 350px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: none;
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-result-item:hover {
    background: var(--surface);
}

.search-result-item:last-child {
    border-bottom: none;
}

/* ========================== */
/* MOBILE RESPONSIVE DESIGN   */
/* ========================== */

/* Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 70px;
    }

    .sidebar .nav-link span,
    .sidebar .logo-area h2,
    .sidebar .user-profile span,
    .sidebar .user-profile i.fa-sign-out-alt {
        display: none;
    }

    .sidebar .nav-link {
        justify-content: center;
        padding: 15px;
    }

    .sidebar .nav-link i {
        margin: 0;
        font-size: 1.3em;
    }

    .sidebar .logo-area {
        padding: 15px 10px;
    }

    .main-content {
        margin-left: 70px;
        width: calc(100% - 70px);
    }
}

/* Mobile */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100% !important;
        height: 65px !important;
        min-height: 65px !important;
        max-height: 65px !important;
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        flex-direction: row !important;
        border-right: none !important;
        border-top: 2px solid var(--border-color) !important;
        z-index: 99999 !important;
        padding: 5px 10px !important;
        background: var(--bg-card) !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .sidebar .logo-area,
    .sidebar .user-profile {
        display: none;
    }

    .sidebar .nav-menu {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        gap: 5px;
    }

    .sidebar .nav-item {
        flex: 1;
    }

    .sidebar .nav-link {
        flex-direction: column;
        padding: 10px 5px;
        font-size: 0.7em;
        text-align: center;
        gap: 3px;
    }

    .sidebar .nav-link i {
        font-size: 1.3em;
        margin: 0;
    }

    .sidebar .nav-link span {
        display: block;
        font-size: 0.85em;
    }

    .sidebar .nav-link::before {
        display: none;
    }

    .main-content {
        margin-left: 0;
        margin-bottom: 80px;
        width: 100%;
        padding: 10px;
        padding-top: 10px;
    }

    /* Hide mobile header toggle - sidebar is always visible at bottom */
    .mobile-header {
        display: none !important;
    }

    /* Hide sidebar overlay */
    #sidebarOverlay {
        display: none !important;
    }

    /* Optimize topbar for mobile */
    .topbar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        margin-bottom: 15px !important;
    }

    /* Hide desktop elements on mobile */
    .topbar .user-area,
    .topbar .desktop-only {
        display: none !important;
    }

    .topbar {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }

    .topbar .search-container {
        width: 100%;
    }

    .topbar .search-container input {
        width: 100%;
    }

    .search-dropdown {
        min-width: 100%;
        left: 0;
        right: 0;
    }

    /* Cards */
    .card {
        padding: 15px;
        border-radius: 12px;
    }

    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    th,
    td {
        padding: 10px 8px;
        font-size: 0.9em;
    }

    /* Forms */
    .form-group {
        margin-bottom: 12px;
    }

    input,
    select,
    textarea {
        padding: 12px;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    /* Buttons */
    .btn {
        padding: 12px 16px;
        font-size: 0.95em;
    }

    /* Stats grid */
    .stat-card,
    .kirim-stat,
    .chiqim-stat {
        padding: 15px;
    }

    /* Page titles */
    h1,
    h2 {
        font-size: 1.3em;
    }

    /* Modals */
    .modal-content,
    [id*="Modal"]>div {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
        padding: 15px !important;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .sidebar .nav-link span {
        display: none;
    }

    .sidebar .nav-link {
        padding: 12px 8px;
    }

    .sidebar .nav-link i {
        font-size: 1.4em;
    }

    .main-content {
        padding: 10px;
    }

    .card {
        padding: 12px;
    }

    .btn {
        padding: 10px 12px;
        font-size: 0.9em;
    }

    /* Hide some columns on very small screens */
    .hide-mobile {
        display: none !important;
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {

    .btn,
    button,
    a.btn,
    .nav-link {
        min-height: 44px;
        min-width: 44px;
    }

    input,
    select,
    textarea {
        min-height: 44px;
    }

    .product-item,
    .search-result-item {
        padding: 15px;
    }
}