:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #f3f4f6;
    --surface-color: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --border-color: #e5e7eb;
    --sidebar-width: 250px;
    --header-height: 60px;
    --radius: 8px;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

img, svg, video, canvas {
    max-width: 100%;
}

button, input, select, textarea {
    max-width: 100%;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 1000;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: var(--primary-color);
    font-weight: 700;
    font-size: clamp(1rem, 4vw, 1.125rem);
}

.brand-icon {
    font-size: 1.5rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md) 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 0.75rem var(--spacing-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
    border-radius: var(--radius);
    margin-bottom: 0.25rem;
}

.nav-item:hover, .nav-item.active {
    background-color: #eff6ff;
    color: var(--primary-color);
}

.nav-item i {
    font-size: 1.25rem;
}

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

.top-header {
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-md);
    gap: 10px;
    z-index: 100;
}

.header-title {
    font-size: clamp(1rem, 4vw, 1.25rem);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
}

#menu-toggle {
    flex-shrink: 0;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    padding-bottom: 100px; /* Safe padding for sticky bars */
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    max-width: 100%;
    word-break: break-word;
    gap: 0.25rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Placeholder card */
.card {
    background: var(--surface-color);
    border-radius: var(--radius);
    padding: var(--spacing-md);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: var(--spacing-md);
    width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.card h2, .card h3 {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

/* Forms */
.form-group { margin-bottom: var(--spacing-sm); width: 100%; min-width: 0; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; color: var(--text-secondary); }
.form-control { width: 100%; padding: 0.75rem; border: 1px solid var(--border-color); border-radius: var(--radius); font-family: inherit; font-size: 1rem; }
.form-control:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }
.input-group { display: flex; gap: var(--spacing-sm); width: 100%; flex-wrap: wrap; }
.input-group .form-control { flex: 1; min-width: 0; }

/* Grid Utilities */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--spacing-sm);
}

.grid-2-col {
    display: grid; 
    grid-template-columns: repeat(2, minmax(0, 1fr)); 
    gap: var(--spacing-sm); 
}

.w-100 { width: 100%; }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mb-0 { margin-bottom: 0 !important; }
.d-none { display: none !important; }
.d-block { display: block; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.text-danger { color: #ef4444; }
.text-success { color: #16a34a; }
.text-lg { font-size: clamp(1.1rem, 4vw, 1.25rem); }
.text-sm { font-size: 0.875rem; }
.font-bold { font-weight: 700; }
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.align-items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }

/* Cart Table Desktop */
.cart-table { width: 100%; border-collapse: collapse; margin-top: var(--spacing-sm); font-size: 0.875rem; table-layout: fixed; }
.cart-table th, .cart-table td { padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border-color); word-break: break-word; overflow-wrap: anywhere; }
.cart-table th { background: #f9fafb; font-weight: 600; color: var(--text-secondary); }
.mobile-label { display: none; }
.mobile-value { display: block; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.875rem; }
.btn-danger { color: #ef4444; background: none; border: 1px solid #ef4444; }
.btn-danger:hover { background: #fef2f2; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1.125rem; }

/* Summary Box */
.summary-box { background: #f9fafb; padding: var(--spacing-md); border-radius: var(--radius); border: 1px solid var(--border-color); width: 100%; }
.summary-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.125rem; flex-wrap: wrap; gap: 8px; }

/* Sticky Bottom Bar */
.sticky-bottom-bar { 
    position: sticky; 
    bottom: 0; 
    left: 0;
    right: 0;
    background: var(--surface-color); 
    padding: var(--spacing-sm) var(--spacing-md); 
    border-top: 1px solid var(--border-color); 
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05); 
    z-index: 90; 
    margin: 0 calc(var(--spacing-md) * -1) calc(var(--spacing-md) * -1) calc(var(--spacing-md) * -1); 
    width: auto;
}

/* Badges */
.badge { display: inline-block; padding: 0.25rem 0.5rem; font-size: 0.75rem; font-weight: 600; border-radius: 9999px; text-align: center; white-space: nowrap; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-primary { background: #dbeafe; color: #1e40af; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 2000; display: none; align-items: center; justify-content: center; padding: var(--spacing-md); overflow-y: auto; }
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease-out; }
.modal { background: var(--surface-color); width: calc(100% - 24px); max-width: 600px; border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.2); display: flex; flex-direction: column; max-height: 90vh; }
.modal-header { padding: var(--spacing-md); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1.125rem; font-weight: 600; margin: 0; }
.modal-body { padding: var(--spacing-md); overflow-y: auto; overflow-x: hidden; }
.modal-footer { padding: var(--spacing-md); border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: var(--spacing-sm); flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Toast Notifications */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; max-width: calc(100% - 40px); }
.toast { background: var(--surface-color); color: var(--text-primary); padding: var(--spacing-md); border-radius: var(--radius); box-shadow: 0 4px 15px rgba(0,0,0,0.15); display: flex; align-items: center; gap: 10px; min-width: 250px; border-left: 4px solid var(--primary-color); animation: slideIn 0.3s ease-out forwards; overflow-wrap: anywhere; }
.toast.toast-success { border-left-color: #22c55e; }
.toast.toast-error { border-left-color: #ef4444; }
.toast.toast-warning { border-left-color: #eab308; }
.toast-icon { font-size: 1.5rem; flex-shrink: 0; }
.toast.toast-success .toast-icon { color: #22c55e; }
.toast.toast-error .toast-icon { color: #ef4444; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* Empty States */
.empty-state { padding: var(--spacing-lg) var(--spacing-md); text-align: center; color: var(--text-secondary); display: flex; flex-direction: column; align-items: center; gap: var(--spacing-sm); }
.empty-state i { font-size: 3rem; color: #cbd5e1; }
.empty-state p { margin-bottom: var(--spacing-sm); }


/* ==============================================================
 * RESPONSIVE BREAKPOINTS
 * ============================================================== */

@media (min-width: 769px) {
    #menu-toggle, #sidebar-close { display: none; }
    .header-title { text-align: left; }
}

@media (max-width: 1024px) {
    .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
    /* Layout */
    .sidebar { position: fixed; height: 100%; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 999; display: none; }
    .sidebar-overlay.open { display: block; }
    .header-title { text-align: center; }
    .d-desktop-none { display: block; }
    
    /* Grids */
    .grid-2-col { grid-template-columns: 1fr; }
    
    /* Buttons */
    .btn { padding: 0.6rem 1rem; }
    
    /* Responsive Table to Vertical Cards */
    .responsive-table, .responsive-table thead, .responsive-table tbody, .responsive-table th, .responsive-table td, .responsive-table tr { 
        display: block; 
        width: 100%;
    }
    .responsive-table thead tr { 
        position: absolute; 
        top: -9999px; 
        left: -9999px; 
    } 
    .responsive-table tr { 
        border: 1px solid var(--border-color); 
        border-radius: var(--radius); 
        margin-bottom: var(--spacing-md); 
        background: var(--surface-color); 
        padding: var(--spacing-sm) 0;
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .responsive-table td { 
        border: none; 
        position: relative; 
        display: grid;
        grid-template-columns: minmax(110px, 40%) minmax(0, 1fr);
        align-items: start;
        gap: 12px;
        text-align: right; 
        padding: 0.5rem var(--spacing-md);
        min-height: unset; 
        min-width: 0;
        width: 100%;
    }
    .responsive-table td:not(:last-child) {
        border-bottom: 1px solid #f1f5f9;
    }
    
    .mobile-label {
        display: block;
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
    }
    
    .mobile-value {
        display: block;
        text-align: right;
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Force buttons to wrap normally inside cards */
    .mobile-value .btn { margin-left: auto; }
    
    /* Title Row for Mobile Card */
    .responsive-table td.mobile-card-title {
        display: block;
        font-weight: 700;
        color: var(--text-primary);
        text-align: left;
        font-size: 1.1rem;
        padding-bottom: 0.25rem;
        background-color: #f8fafc;
        border-bottom: none;
    }
    .responsive-table td.mobile-card-title .mobile-value {
        text-align: left;
    }
    
    /* Subtitle Row for Mobile Card */
    .responsive-table td.mobile-card-subtitle {
        display: block;
        text-align: left;
        color: var(--text-secondary);
        font-size: 0.875rem;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
        background-color: #f8fafc;
    }
    .responsive-table td.mobile-card-subtitle .mobile-value {
        text-align: left;
    }
}

@media (max-width: 480px) {
    /* Adjust input groups on very small screens */
    .input-group { flex-direction: column; }
    .input-group .btn { width: 100%; }
}

@media (max-width: 360px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    /* Very small screens: Make headers shrink well */
    .top-header { padding: 0 var(--spacing-sm); }
    .btn { font-size: 0.875rem; padding: 0.5rem; }
    .header-title { font-size: 1rem; }
}
