:root {
    --sidebar-width: 230px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #0ea5e9;
    --topbar-height: 56px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: #f1f5f9;
    font-size: 14px;
}

/* Sidebar */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar .nav-link {
    color: rgba(255,255,255,0.7);
    padding: 10px 20px;
    border-radius: 0;
    transition: all 0.2s;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
}

.sidebar .nav-link.active {
    color: #fff;
    background: var(--sidebar-active);
}

.sidebar .nav-link i {
    margin-right: 8px;
    width: 20px;
    text-align: center;
}

.nav-section {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    letter-spacing: 1px;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 16px;
    min-height: var(--topbar-height);
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-radius: 8px;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    padding: 12px 16px;
}

.stat-card {
    border-radius: 10px;
    padding: 20px;
    color: #fff;
}

.stat-card .stat-number {
    font-size: 32px;
    font-weight: 700;
}

.stat-card .stat-label {
    font-size: 15px;
    opacity: 0.9;
}

.stat-card.revenue { background: linear-gradient(135deg, #0ea5e9, #3b82f6); }
.stat-card.cost { background: linear-gradient(135deg, #f59e0b, #f97316); }
.stat-card.profit { background: linear-gradient(135deg, #10b981, #059669); }
.stat-card.margin { background: linear-gradient(135deg, #8b5cf6, #6366f1); }
.stat-card.orders { background: linear-gradient(135deg, #ec4899, #f43f5e); }

/* Tables */
.table th {
    font-weight: 600;
    background: #f8fafc;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background: #f0f9ff;
}

/* Form */
.form-control, .form-select {
    border-radius: 6px;
    font-size: 14px;
}

/* Pagination */
.pagination {
    margin-bottom: 0;
}

/* Print */
@media print {
    @page { margin: 15mm; size: A4 portrait; }
    body { background: #fff !important; }
    .sidebar, .topbar, .no-print { display: none !important; }
    .wrapper { display: block !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
    .card-header { background: #f8fafc !important; }
    .table { font-size: 12px !important; }
    .table th { background: #f1f5f9 !important; }
    .container-fluid { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
    #sidebar, .topbar, .navbar, .alert { display: none !important; }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }

    /* Make tables horizontally scrollable */
    .table-responsive-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -4px;
    }
    .table-responsive-wrap table {
        min-width: 600px;
    }

    /* Stat cards - compact on mobile */
    .stat-card {
        padding: 12px !important;
    }
    .stat-card .stat-number {
        font-size: 20px !important;
    }
    .stat-card .stat-label {
        font-size: 13px !important;
    }

    /* Card body padding reduction */
    .card-body {
        padding: 10px;
    }

    /* Form controls full width */
    .form-control, .form-select {
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    /* Topbar - username text truncation */
    .topbar .text-muted {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Sidebar overlay */
    .sidebar.show::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: -1;
    }

    /* Hide summary card row on very small screens if needed */
    .container-fluid {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Month input full width on mobile */
    input[type="month"] {
        max-width: 160px;
    }

    /* Button groups wrap gracefully */
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .stat-card .stat-number {
        font-size: 17px !important;
    }
    .card-header {
        font-size: 13px;
        padding: 10px 12px;
    }
    .table {
        font-size: 12px !important;
    }
    .table td, .table th {
        padding: 6px 8px !important;
    }
    .sidebar {
        width: 240px;
    }
}

/* Profit structure */
.profit-bar {
    display: flex;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    margin: 10px 0;
}

.profit-bar-item {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
}

/* Loading */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
