:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #7209b7;
    --success: #4cc9f0;
    --light: #f8f9fa;
    --dark: #212529;
    --gray: #6c757d;
    --light-gray: #e9ecef;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --card-shadow-hover: 0 10px 15px rgba(0, 0, 0, 0.1);
    font-size: 14px; /* Base font size decreased from default 16px */
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f5f7fb;
    color: #333;
    line-height: 1.5;
    font-size: 0.875rem; /* Decreased body font size */
}

/* Headings with decreased sizes */
h1 { font-size: 1.5rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.2rem; }
h5 { font-size: 1.1rem; }
h6 { font-size: 1rem; }

/* Navbar */
.navbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 0.6rem 1rem;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem; /* Decreased from 1.5rem */
    display: flex;
    align-items: center;
    color: white !important;
}

.navbar-brand i {
    margin-right: 8px;
    font-size: 1.5rem; /* Decreased from 1.8rem */
}

.nav-link {
    font-weight: 500;
    padding: 0.4rem 0.8rem; /* Slightly decreased padding */
    border-radius: 6px;
    margin: 0 2px;
    transition: all 0.3s ease;
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 0.875rem; /* Decreased font size */
}

.nav-link:hover, .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    color: white !important;
}

/* Cards */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-bottom: none;
    padding: 0.8rem 1.2rem; /* Decreased padding */
    font-weight: 600;
    font-size: 0.9rem; /* Decreased font size */
}

.card-header i {
    margin-right: 8px;
}

.card-body {
    padding: 1.2rem; /* Decreased padding */
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.4rem 1rem; /* Decreased padding */
    transition: all 0.3s ease;
    font-size: 0.875rem; /* Decreased font size */
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(67, 97, 238, 0.3);
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.btn-success {
    background: linear-gradient(135deg, #4cc9f0 0%, #3a86ff 100%);
    border: none;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(76, 201, 240, 0.3);
}

.btn-info {
    background: linear-gradient(135deg, #7209b7 0%, #560bad 100%);
    border: none;
}

.btn-info:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(114, 9, 183, 0.3);
}

.btn-outline-secondary {
    border: 1px solid var(--gray);
    color: var(--gray);
}

.btn-outline-secondary:hover {
    background-color: var(--gray);
    border-color: var(--gray);
    color: white;
    transform: translateY(-2px);
}

/* Sidebar */
.service-sidebar {
    background-color: white;
    border-right: 1px solid var(--light-gray);
    min-height: calc(100vh - 76px);
    padding: 0;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

.service-sidebar .nav-link {
    border-radius: 0;
    border-bottom: 1px solid var(--light-gray);
    padding: 10px 12px; /* Decreased padding */
    color: var(--dark) !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    font-size: 0.875rem; /* Decreased font size */
}

.service-sidebar .nav-link:hover {
    background-color: rgba(67, 97, 238, 0.05);
}

.service-sidebar .nav-link.active {
    background: linear-gradient(135deg, rgba(67, 97, 238, 0.1) 0%, rgba(114, 9, 183, 0.1) 100%);
    color: var(--primary) !important;
    border-right: 3px solid var(--primary);
}

.service-sidebar .nav-link .service-badge {
    background-color: var(--primary);
    color: white;
    border-radius: 15px;
    padding: 2px 6px; /* Decreased padding */
    font-size: 0.7rem; /* Decreased font size */
    min-width: 20px;
    text-align: center;
}

/* Form Elements */
.form-control, .form-select {
    width: 100%;
    border-radius: 8px;
    padding: 0.5rem 0.6rem; /* Decreased padding */
    border: 1px solid #dee2e6;
    transition: all 0.3s ease;
    font-size: 0.875rem; /* Decreased font size */
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
}

.input-group .btn {
    border-radius: 0 8px 8px 0;
}

.form-label.fw-semibold {
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.875rem; /* Decreased font size */
}

.form-text {
    color: var(--gray);
    font-size: 0.8rem; /* Decreased font size */
    margin-top: 0.2rem;
}

/* Tables */
.table {
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0;
}

.table th {
    background-color: rgba(67, 97, 238, 0.05);
    font-weight: 600;
    border-top: none;
    padding: 0.6rem; /* Decreased padding */
    font-size: 0.85rem; /* Decreased font size */
}

.table td {
    padding: 0.6rem; /* Decreased padding */
    vertical-align: middle;
    font-size: 0.85rem; /* Decreased font size */
}

.table-hover tbody tr:hover {
    background-color: rgba(67, 97, 238, 0.03);
}

/* Status Badges */
.status-processing { 
    color: #ffc107; 
    font-weight: 600;
    background-color: rgba(255, 193, 7, 0.1);
    padding: 3px 6px; /* Decreased padding */
    border-radius: 4px;
    display: inline-block;
    font-size: 0.8rem; /* Decreased font size */
}

.status-success { 
    color: #198754; 
    font-weight: 600;
    background-color: rgba(25, 135, 84, 0.1);
    padding: 3px 6px; /* Decreased padding */
    border-radius: 4px;
    display: inline-block;
    font-size: 0.8rem; /* Decreased font size */
}

.status-error { 
    color: #dc3545; 
    font-weight: 600;
    background-color: rgba(220, 53, 69, 0.1);
    padding: 3px 6px; /* Decreased padding */
    border-radius: 4px;
    display: inline-block;
    font-size: 0.8rem; /* Decreased font size */
}

/* ============ YOUR ORIGINAL STATS CARDS ============ */
/* Keep this exactly as you had it before */
.stat-card {
    text-align: center;
    padding: 1rem; /* Decreased padding */
}

.stat-card h4 {
    font-size: 1.5rem; /* Decreased from 2rem */
    font-weight: 700;
    margin-bottom: 0.3rem;
    color: var(--primary);
}

.stat-card p {
    color: var(--gray);
    margin-bottom: 0;
    font-size: 0.8rem; /* Decreased font size */
}

/* Service Cards */
.service-card {
    cursor: pointer;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    padding: 0.8rem; /* Decreased padding */
    margin-bottom: 0.6rem;
    background: white;
    font-size: 0.875rem; /* Decreased font size */
}

.service-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--card-shadow-hover);
}

.service-card.selected {
    border-left: 4px solid var(--primary);
    background-color: rgba(67, 97, 238, 0.05);
}

/* Loading Spinner */
.spinner-border {
    color: var(--primary);
}

/* Footer */
footer {
    background: linear-gradient(135deg, var(--dark) 0%, #343a40 100%);
    color: white;
    margin-top: 2rem;
    padding: 1.5rem 0;
    font-size: 0.8rem; /* Decreased font size */
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Service Results */
.service-results-container {
    display: none;
}

.service-results-container.active {
    display: block;
}

/* Sortable Table Headers */
.sortable th {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background-color 0.2s ease;
}

.sortable th:hover {
    background-color: rgba(67, 97, 238, 0.08);
}

.sortable th.sort-asc::after {
    content: ' ▲';
    font-size: 12px;
    color: var(--primary);
}

.sortable th.sort-desc::after {
    content: ' ▼';
    font-size: 12px;
    color: var(--primary);
}

.sortable th.sort-none::after {
    content: ' ↕';
    font-size: 12px;
    color: #ccc;
}

/* IMEI Input */
.imei-input {
    font-family: monospace;
    resize: vertical;
}

/* Main Content */
.main-content {
    padding: 0 15px;
}

/* History filter improvements */
#historyFilters .border-start {
    border-left: 2px solid var(--light-gray) !important;
}

#historyImeiSearch {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 120px;
}

/* ============ RESPONSIVE ADJUSTMENTS ============ */
@media (max-width: 768px) {
    .service-sidebar {
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid var(--light-gray);
    }
    
    .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .input-group .form-control {
        border-radius: 8px;
        margin-bottom: 10px;
    }
    
    .input-group .btn {
        border-radius: 8px;
        width: 100%;
    }
    
    .main-content {
        padding: 0 10px;
    }
    
    .card-body {
        padding: 1rem;
    }

    #historyFilters .border-start {
        border-left: none !important;
        border-top: 2px solid var(--light-gray) !important;
        padding-left: 0 !important;
        padding-top: 1rem;
        margin-top: 1rem;
    }
    
    #historyFilters .row.g-3 > .col-md-8,
    #historyFilters .row.g-3 > .col-md-4 {
        width: 100%;
    }
    
    /* ============ ENHANCED ALL TABLES FOR MOBILE ============ */
    /* History tables */
    #historyContent .table-responsive,
    #serviceResultsContainer .table-responsive {
        margin: 0 -10px;
        width: calc(100% + 20px);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #historyContent .table,
    #serviceResultsContainer .table {
        min-width: 768px; /* Force horizontal scrolling for complex tables */
        font-size: 0.8rem;
    }
    
    #historyContent .table th,
    #historyContent .table td,
    #serviceResultsContainer .table th,
    #serviceResultsContainer .table td {
        white-space: nowrap;
        padding: 0.5rem;
    }
    
    /* Column width adjustments for history table */
    #historyContent .table th:nth-child(1),
    #historyContent .table td:nth-child(1) {
        min-width: 150px;
    }
    
    #historyContent .table th:nth-child(2),
    #historyContent .table td:nth-child(2) {
        min-width: 120px;
        font-family: monospace;
    }
    
    #historyContent .table th:nth-child(3),
    #historyContent .table td:nth-child(3) {
        min-width: 100px;
    }
    
    #historyContent .table th:nth-child(4),
    #historyContent .table td:nth-child(4) {
        min-width: 200px;
        white-space: normal;
    }
    
    #historyContent .table th:nth-child(5),
    #historyContent .table td:nth-child(5) {
        min-width: 200px;
        white-space: normal;
        word-break: break-word;
    }
    
    /* Column width adjustments for service results tables */
    #serviceResultsContainer .table th:nth-child(1),
    #serviceResultsContainer .table td:nth-child(1) {
        min-width: 140px;
    }
    
    #serviceResultsContainer .table th:nth-child(2),
    #serviceResultsContainer .table td:nth-child(2) {
        min-width: 110px;
    }
    
    #serviceResultsContainer .table th:nth-child(3),
    #serviceResultsContainer .table td:nth-child(3) {
        min-width: 120px;
        font-family: monospace;
        font-weight: bold;
    }
    
    #serviceResultsContainer .table th:nth-child(4),
    #serviceResultsContainer .table td:nth-child(4) {
        min-width: 250px;
        white-space: normal;
        word-break: break-word;
    }
    
    /* Status badges in mobile */
    #historyContent .badge,
    #serviceResultsContainer .badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    /* Card header adjustments for mobile */
    #historyContent .card-header,
    #serviceResultsContainer .card-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.75rem;
    }
    
    #historyContent .card-header > span,
    #serviceResultsContainer .card-header > span {
        margin-bottom: 0.5rem;
        width: 100%;
    }
    
    /* History filter card adjustments */
    #historyFilters .card-body {
        padding: 1rem;
    }
    
    /* IMEI search textarea in mobile */
    #historyImeiSearch {
        font-size: 0.85rem;
        min-height: 100px;
    }
    
    /* Filter buttons in mobile */
    #historyFilters .d-grid .btn {
        font-size: 0.85rem;
        padding: 0.5rem;
    }
    
    /* Alert messages in history */
    #historyContent .alert,
    #serviceResultsContainer .alert {
        font-size: 0.85rem;
        margin: 0.5rem;
        padding: 0.75rem;
    }
    
    /* Pagination in mobile */
    #historyContent .pagination {
        flex-wrap: wrap;
        margin-bottom: 1rem;
    }
    
    #historyContent .pagination .page-item {
        margin: 0.1rem;
    }
    
    #historyContent .pagination .page-link {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }
    
    /* Add horizontal scroll indicator for mobile tables */
    .table-responsive {
        position: relative;
    }
    
    .table-responsive::after {
        content: '← Scroll →';
        position: absolute;
        right: 10px;
        top: 10px;
        background: rgba(67, 97, 238, 0.9);
        color: white;
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
        border-radius: 12px;
        font-weight: bold;
        z-index: 10;
        pointer-events: none;
        animation: pulse 2s infinite;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
    
    @keyframes pulse {
        0%, 100% { opacity: 0.9; }
        50% { opacity: 1; }
    }
    
    /* Improve text visibility in tables on mobile */
    #historyContent .table td,
    #serviceResultsContainer .table td {
        background-color: rgba(255, 255, 255, 0.95);
    }
    
    #historyContent .table-striped tbody tr:nth-of-type(odd) td,
    #serviceResultsContainer .table-striped tbody tr:nth-of-type(odd) td {
        background-color: rgba(248, 249, 250, 0.95);
    }
    
    #historyContent .table-hover tbody tr:hover td,
    #serviceResultsContainer .table-hover tbody tr:hover td {
        background-color: rgba(67, 97, 238, 0.1) !important;
    }
    
    /* Make sure the table header stays visible when scrolling horizontally */
    #historyContent .table thead,
    #serviceResultsContainer .table thead {
        position: sticky;
        top: 0;
        background: white !important;
        z-index: 20;
        box-shadow: 0 3px 6px rgba(0,0,0,0.1);
    }
    
    /* Adjust service ID display in mobile */
    #historyContent .table td:first-child strong {
        font-size: 0.8rem;
        display: block;
        line-height: 1.3;
    }
    
    #historyContent .table td:first-child strong::before {
        content: "[";
    }
    
    #historyContent .table td:first-child strong::after {
        content: "]";
    }
    
    /* Batch separator styling in mobile */
    #serviceResultsContainer .batch-separator td {
        padding: 0.8rem 0.5rem !important;
        background: linear-gradient(135deg, rgba(67, 97, 238, 0.1) 0%, rgba(114, 9, 183, 0.1) 100%) !important;
        font-size: 0.85rem;
    }
    
    /* Service results action buttons in mobile */
    #serviceResultsContainer .card-header .btn-sm {
        margin-top: 0.5rem;
        margin-right: 0.3rem;
        width: auto;
        min-width: 80px;
    }
    
    #serviceResultsContainer .card-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    #serviceResultsContainer .card-header > span {
        margin-bottom: 0.8rem;
    }
    
    #serviceResultsContainer .card-header .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    
    /* ============ QUICK STATS IN MOBILE - NO CHANGES ============ */
    /* Your quick stats remain exactly the same as desktop */
    /* No special mobile styling needed */
}

/* Mobile-responsive API key input */
@media (max-width: 576px) {
    .col-8, .col-4 {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }
    
    /* ============ EXTRA SMALL DEVICES ENHANCEMENTS ============ */
    /* More aggressive table styling for very small screens */
    #historyContent .table,
    #serviceResultsContainer .table {
        font-size: 0.75rem;
    }
    
    #historyContent .table th,
    #historyContent .table td,
    #serviceResultsContainer .table th,
    #serviceResultsContainer .table td {
        padding: 0.4rem;
    }
    
    #historyContent .table th:nth-child(1),
    #historyContent .table td:nth-child(1) {
        min-width: 130px;
    }
    
    #historyContent .table th:nth-child(4),
    #historyContent .table td:nth-child(4),
    #historyContent .table th:nth-child(5),
    #historyContent .table td:nth-child(5) {
        min-width: 180px;
        font-size: 0.7rem;
    }
    
    #serviceResultsContainer .table th:nth-child(1),
    #serviceResultsContainer .table td:nth-child(1) {
        min-width: 120px;
    }
    
    #serviceResultsContainer .table th:nth-child(4),
    #serviceResultsContainer .table td:nth-child(4) {
        min-width: 220px;
        font-size: 0.7rem;
    }
    
    /* Better text wrapping for small screens */
    #historyContent small.text-break,
    #serviceResultsContainer .table td:nth-child(4) {
        font-size: 0.7rem;
        line-height: 1.3;
    }
    
    /* Export button adjustments */
    #exportHistory {
        width: 100%;
        margin-top: 0.5rem;
    }
    
    /* Filter section adjustments */
    #historyFilters .border-start {
        padding-left: 0 !important;
        padding-top: 1rem;
        margin-top: 1rem;
        border-left: none !important;
        border-top: 1px solid var(--light-gray) !important;
    }
    
    /* Date inputs in filters */
    #historyStartDate,
    #historyEndDate {
        font-size: 0.85rem;
    }
}

/* Ensure proper spacing */
.row.g-2 {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
}

.row.g-2 > [class*="col-"] {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Animation for alerts */
.alert {
    border: none;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    font-size: 0.875rem; /* Decreased font size */
}

/* Table responsive wrapper */
.table-responsive {
    border-radius: 8px;
    overflow: hidden;
}

/* Badge styles */
.badge {
    font-weight: 500;
    font-size: 0.75em; /* Decreased font size */
}

/* Text colors */
.text-primary {
    color: var(--primary) !important;
}

.text-muted {
    color: var(--gray) !important;
    font-size: 0.8rem; /* Decreased font size */
}

/* Margin utilities */
.mt-3 {
    margin-top: 1rem !important;
}

.mt-4 {
    margin-top: 1.5rem !important;
}

.mt-5 {
    margin-top: 3rem !important;
}

.mb-3 {
    margin-bottom: 1rem !important;
}

/* Input group focus */
.input-group:focus-within .form-control {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
}

/* Loading states */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.font-monospace {
    font-family: 'Courier New', monospace;
}

/* Service list styling */
#servicesList {
    max-height: 300px;
    overflow-y: auto;
}

/* Sidebar sticky positioning */
.sidebar-sticky {
    position: sticky;
    top: 0;
    height: calc(100vh - 76px);
    overflow-y: auto;
}

/* Additional small text adjustments */
.small {
    font-size: 0.75rem;
}

code, pre {
    font-size: 0.8rem; /* Decreased font size for code */
}

/* Additional responsive font adjustments */
@media (max-width: 768px) {
    :root {
        font-size: 13px;
    }
    
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
}

.service-nav-btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
}

.service-nav-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.service-nav-btn.active {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

/* ============ BATCH SEPARATOR STYLING ============ */
.batch-separator td {
    background: linear-gradient(135deg, rgba(67, 97, 238, 0.08) 0%, rgba(114, 9, 183, 0.08) 100%) !important;
    color: #4361ee !important;
    font-weight: 700;
    text-align: center;
    padding: 0.8rem !important;
    border-top: 2px solid rgba(67, 97, 238, 0.2) !important;
    border-bottom: 2px solid rgba(67, 97, 238, 0.2) !important;
}

.batch-separator .fas {
    color: #7209b7;
}