* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-light: #f8fafc;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
.header {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

.header h1 {
    color: var(--text-dark);
    font-size: 2rem;
    margin-bottom: 6px;
    font-weight: 700;
}

.header .subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Configuration */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
    background: var(--bg-light);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-helper {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: block;
}

.form-helper a {
    color: var(--primary);
    text-decoration: none;
}

.form-helper a:hover {
    text-decoration: underline;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-group label {
    margin: 0;
    font-weight: 400;
    font-size: 0.875rem;
    cursor: pointer;
}

/* File Upload */
.file-upload {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--bg-light);
}

.file-upload:hover,
.file-upload.drag-over {
    border-color: var(--primary);
    background: #eff6ff;
}

.file-upload-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.file-upload-title {
    color: var(--text-dark);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.file-upload-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

#fileInfo {
    margin-top: 12px;
    padding: 12px;
    background: #d1fae5;
    border-radius: 8px;
    color: #065f46;
    font-size: 0.875rem;
    display: none;
}

#fileInfo.active {
    display: block;
}

/* Buttons */
.btn {
    padding: 11px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #059669;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
}

/* Estimation Panel */
.estimation-panel {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    padding: 20px;
    border-radius: 12px;
    margin-top: 24px;
    border: 1px solid #bae6fd;
}

.estimation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(56, 189, 248, 0.2);
}

.estimation-row:last-child {
    border-bottom: none;
}

.estimation-label {
    font-size: 0.875rem;
    color: var(--text-light);
    font-weight: 500;
}

.estimation-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

.progress-bar-wrapper {
    margin-top: 12px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
    border-radius: 4px;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
}

/* API Consumption Tracker */
.api-tracker {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: white;
    padding: 24px;
    border-radius: 12px;
    margin-top: 24px;
}

.api-tracker-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.api-tracker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.api-tracker-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 16px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

.api-tracker-item .label {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-bottom: 8px;
}

.api-tracker-item .value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

.stat-label {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

/* Alerts */
.alert {
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border-left: 4px solid var(--primary);
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success);
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger);
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning);
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 48px 32px;
    background: rgba(15, 23, 42, 0.95);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 24px;
    backdrop-filter: blur(10px);
}

.loading.active {
    display: block !important;
}

.spinner {
    width: 64px;
    height: 64px;
    border: 5px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--success);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 24px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-title {
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.loading-status {
    color: rgba(255, 255, 255, 0.8);
    margin-top: 8px;
    line-height: 1.6;
    font-size: 0.9rem;
}

/* Filter Section */
.filter-section {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05) 0%, rgba(37, 99, 235, 0.02) 100%);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 24px;
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.filter-section-title {
    margin-bottom: 20px;
    color: var(--text-dark);
    font-size: 1rem;
    font-weight: 600;
}

.filter-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.filter-category {
    padding: 20px;
    border-radius: 12px;
    color: white;
}

.filter-category-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.filter-category-icon {
    font-size: 1.8rem;
}

.filter-category-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.filter-category-subtitle {
    margin: 0;
    font-size: 0.8rem;
    opacity: 0.9;
}

.filter-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid white;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.filter-custom {
    background: rgba(100, 116, 139, 0.1);
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
}

.filter-custom summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.filter-custom-content {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
    margin-top: 12px;
}

.filter-info {
    margin-top: 16px;
    padding: 14px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 8px;
    border-left: 3px solid var(--success);
    display: none;
    font-size: 0.9rem;
    color: var(--text-dark);
}

.filter-info.active {
    display: block;
}

/* Results Table */
.table-wrapper {
    overflow-x: auto;
    margin-top: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.results-table th,
.results-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.results-table th {
    background: var(--bg-light);
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
}

.results-table tbody tr:hover {
    background: var(--bg-light);
}

.trend-up { 
    color: var(--success); 
    font-weight: 600; 
}

.trend-down { 
    color: var(--danger); 
    font-weight: 600; 
}

/* Export Options */
.export-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Section Divider */
.section-divider {
    height: 1px;
    background: var(--border);
    margin: 24px 0;
}

/* API Usage Display */
.api-usage-display {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.api-usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.api-usage-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.api-usage-item .label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 5px;
}

.api-usage-item .value {
    font-size: 1.5rem;
    font-weight: 700;
}

.api-progress {
    background: rgba(255, 255, 255, 0.2);
    height: 30px;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 15px;
    position: relative;
}

.api-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .config-grid,
    .stats-grid,
    .api-tracker-grid,
    .filter-categories,
    .api-usage-grid {
        grid-template-columns: 1fr;
    }

    .actions,
    .filter-custom-content {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}

#resultsSection {
    display: none;
}

#apiUsageResult {
    margin-top: 20px;
}

/* API Usage Compact Display */
.api-usage-compact {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.api-service-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.api-service-card.error {
    border-color: var(--danger);
    background: #fee2e2;
}

.api-service-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.api-service-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
}

.api-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.api-status.error {
    background: #fee2e2;
    color: var(--danger);
}

.api-metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.api-metric {
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
}

.metric-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
}

.metric-unit {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 2px;
}

.api-progress-compact {
    height: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-bar-fill {
    height: 100%;
    transition: width 0.5s ease;
    border-radius: 4px;
}

.api-progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

.api-timestamp {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.api-timestamp small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
    .api-usage-compact {
        grid-template-columns: 1fr;
    }
    
    .api-metrics-grid {
        grid-template-columns: 1fr;
    }
}