/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
    color: #2c3e50;
    font-size: 28px;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-success {
    background-color: #2ecc71;
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-top: 6px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 18px;
    font-weight: 500;
    color: #ffffff;
}

/* Company Overview */
.company-overview {
    background: #f8f9fa;
    padding: 20px;
    margin: 20px 0 30px 0;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.company-overview h2 {
    margin: 0 0 20px 0;
    color: #2c3e50;
    font-size: 1.5em;
}

.overview-container {
    display: flex;
    gap: 30px;
    align-items: center;
}

.overview-chart {
    flex: 2;
    max-width: 600px;
    height: 250px;
}

.overview-stats {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stat-item {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    text-align: center;
}

.stat-item h3 {
    margin: 0 0 10px 0;
    color: #6c757d;
    font-size: 0.9em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cost-value {
    font-size: 2em;
    font-weight: bold;
    color: #2c3e50;
    font-family: monospace;
}

.cost-change {
    font-size: 1.5em;
    font-weight: bold;
    font-family: monospace;
}

.cost-change.positive {
    color: #e74c3c;
}

.cost-change.negative {
    color: #27ae60;
}

.cost-change.neutral {
    color: #6c757d;
}

@media (max-width: 768px) {
    .overview-container {
        flex-direction: column;
        gap: 20px;
    }
    
    .overview-stats {
        flex-direction: row;
        width: 100%;
    }
    
    .overview-chart {
        height: 200px;
    }
}

/* Main content */
.main-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.main-content h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    min-width: 800px; /* Ensure table doesn't get too cramped */
}

.table th,
.table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
    white-space: nowrap; /* Prevent text wrapping */
}

/* Pagination controls */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
    padding: 15px 0;
}

.pagination-info {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

/* Payment status dropdown */
.payment-status-dropdown {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    background-color: white;
    min-width: 130px;
}

.payment-status-dropdown:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

/* Subscription indicator */
.subscription-active {
    color: #27ae60;
    font-weight: bold;
    font-size: 18px;
    text-align: center;
}

.subscription-inactive {
    color: #e74c3c;
    font-weight: bold;
    font-size: 18px;
    text-align: center;
}

/* Payment status badges */
.payment-status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.payment-status-not-paying {
    background-color: #f8d7da;
    color: #721c24;
}

.payment-status-paying {
    background-color: #d4edda;
    color: #155724;
}

.payment-status-paused {
    background-color: #fff3cd;
    color: #856404;
}

.payment-status-payment-failed {
    background-color: #f5c6cb;
    color: #721c24;
}

.table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
    position: sticky;
    top: 0;
    z-index: 10;
}

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

/* Cost display */
.cost-positive {
    color: #27ae60;
    font-weight: bold;
}

.cost-negative {
    color: #e74c3c;
    font-weight: bold;
}

.cost-neutral {
    color: #7f8c8d;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    max-height: 95vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 900px;
    max-height: 95vh;
    overflow-y: auto;
}

.modal-extra-wide {
    max-width: 90vw;
    width: 90%;
    max-height: 95vh;
    overflow-y: auto;
}

.modal-content.wide {
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-actions {
    margin-bottom: 20px;
    text-align: right;
    flex-shrink: 0;
    padding-right: 40px; /* Account for close button */
}

.modal-content.wide .table {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
}

.modal-content.wide h2 {
    margin-top: 0;
    margin-bottom: 20px;
    padding-right: 50px; /* Account for close button */
}

.modal-content.wide .table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(90vh - 150px); /* Account for header and actions */
    border: 1px solid #ddd;
    border-radius: 4px;
}

.modal-content.wide .table {
    margin-bottom: 0;
    min-width: 900px; /* Increased for additional provider column */
}

.modal-content.wide .table th,
.modal-content.wide .table td {
    white-space: nowrap;
    padding: 12px 8px;
}

.modal-content.wide .table th:first-child,
.modal-content.wide .table td:first-child {
    min-width: 140px; /* Model name column */
}

.modal-content.wide .table th:nth-child(2),
.modal-content.wide .table td:nth-child(2) {
    min-width: 100px; /* Provider column */
}

.modal-content.wide .table th:last-child,
.modal-content.wide .table td:last-child {
    min-width: 120px; /* Actions column */
    text-align: center;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
    z-index: 1000;
    background: white;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close:hover {
    color: #000;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

/* Field change indicators */
.form-group.changed {
    position: relative;
}

.form-group.changed input,
.form-group.changed select {
    border-color: #f39c12;
    background-color: #fef9e7;
}

.form-group.changed::after {
    content: "CHANGED";
    position: absolute;
    top: 0;
    right: 0;
    background-color: #f39c12;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 3px;
    transform: translateY(-50%);
}

/* Checkbox group styles */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    background-color: #fafafa;
    max-width: 100%;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-item input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.checkbox-item label {
    margin: 0;
    font-weight: normal;
    cursor: pointer;
    flex-grow: 1;
}

.checkbox-item:hover {
    background-color: #f0f0f0;
    border-radius: 3px;
    padding: 2px 4px;
}

/* Responsive checkbox layout for wider screens */
@media (min-width: 768px) {
    .checkbox-group {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .checkbox-item {
        min-width: 120px;
        flex: 0 0 auto;
    }
}

.form-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
}

/* Chart sections */
.chart-section {
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.chart-section:last-child {
    border-bottom: none;
}

.chart-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.chart-section canvas {
    max-width: 100%;
    height: auto !important;
}

.chart-controls {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.chart-btn,
.chart-btn-func,
.chart-btn-events {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background-color: white;
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
}

.chart-btn.active,
.chart-btn-func.active,
.chart-btn-events.active {
    background-color: #3498db;
    color: white;
    border-color: #3498db;
}

.chart-btn:hover,
.chart-btn-func:hover,
.chart-btn-events:hover {
    background-color: #f8f9fa;
}

.chart-btn.active:hover,
.chart-btn-func.active:hover,
.chart-btn-events.active:hover {
    background-color: #2980b9;
}

/* Action buttons in tables */
.action-buttons {
    display: flex;
    gap: 5px;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
    }
    
    .main-content {
        padding: 20px;
        overflow-x: auto;
        max-height: 85vh;
    }
    
    .modal-content {
        margin: 2% auto;
        width: 95%;
        padding: 20px;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    .modal-large {
        width: 98%;
        margin: 1% auto;
    }
    
    .table {
        font-size: 14px;
        min-width: 600px;
    }
    
    .table th,
    .table td {
        padding: 8px;
    }
    
    .form-buttons {
        flex-direction: column;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .chart-controls {
        flex-wrap: wrap;
    }
    
    .chart-section {
        margin-bottom: 30px;
    }
}

/* Login Page Styles */
.login-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.login-header {
    background: #2c3e50;
    color: white;
    padding: 30px 20px;
    text-align: center;
}

.login-header h1 {
    margin: 0 0 10px 0;
    font-size: 1.8em;
    font-weight: 600;
}

.login-header p {
    margin: 0;
    opacity: 0.9;
    font-size: 0.95em;
}

.login-content {
    padding: 40px 30px;
    text-align: center;
}

.btn-large {
    padding: 15px 30px;
    font-size: 1.1em;
    width: 100%;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-primary.btn-large {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.btn-primary.btn-large:hover {
    background: linear-gradient(135deg, #2980b9, #21618c);
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.btn-success.btn-large {
    background: linear-gradient(135deg, #27ae60, #229954);
    color: white;
}

.btn-success.btn-large:hover {
    background: linear-gradient(135deg, #229954, #1e8449);
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3);
}

.user-info {
    margin-bottom: 30px;
}

.user-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 15px;
    border: 3px solid #ecf0f1;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.user-info h3 {
    margin: 0 0 5px 0;
    color: #2c3e50;
    font-size: 1.3em;
}

.user-info p {
    margin: 0;
    color: #7f8c8d;
    font-size: 0.95em;
}

.auth-loading {
    padding: 20px 0;
}

.hidden {
    display: none !important;
}

/* Loading spinner for login */
.auth-loading .loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.auth-loading .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(52, 152, 219, 0.3);
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.auth-loading .loading-text {
    color: #7f8c8d;
    font-size: 0.95em;
}
