/* style.css - Mobile Responsive - Optimized */
:root {
    --primary-color: #58A5A4;
    --primary-hover: #5B5E5E;
    --secondary-color: #5469d4;
    --secondary-hover: #4254b0;
    --success-color: #28a745;
    --success-hover: #218838;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-radius: 4px;
    --box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    --transition: all 0.3s ease;
}

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

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 15px;
    line-height: 1.6;
    background-color: #f5f5f5;
    font-size: 14px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    display: block;
    align-self: center;
}

a, a:visited {
    color: black;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--box-shadow);
}

/* Header and Navigation */
header {
    background: var(--primary-color);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 15px;
    color: var(--dark-color);
}

/* Forms */
form { 
    margin-bottom: 20px; 
    background: #ffffff; 
    padding: 15px; 
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

label { 
    display: block; 
    margin-bottom: 5px; 
    font-weight: bold;
    color: var(--dark-color);
}

input, select, button, textarea { 
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 16px; /* Better for mobile touch */
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(88, 165, 164, 0.1);
}

.datalist-input { 
    width: 100%; 
}

.form-row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 15px;
    margin-bottom: 15px;
}

.form-group { 
    flex: 1;
    min-width: 200px;
    margin-bottom: 15px;
}

/* Tables - Desktop (full width) */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 20px;
    font-size: 14px;
    min-width: 600px; /* Minimum width to prevent too much squeezing */
}

th, td { 
    border: 1px solid #ddd; 
    padding: 12px; 
    text-align: left;
    word-wrap: break-word;
}

th { 
    background-color: #f2f2f2; 
    font-weight: bold;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    font-weight: bold;
    transition: var(--transition);
}

button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.search-button {
    background: var(--primary-color);
    color: white;
    border-radius: var(--border-radius);
    padding: 15px;
    font-size: 16px;
    margin-top: 10px;
}

.search-button:hover {
    background: var(--primary-hover);
}

.stripe-button {
    background: var(--secondary-color);
    color: white;
    border-radius: var(--border-radius);
    padding: 12px;
    font-size: 14px;
    margin-top: 5px;
    width: 100%;
    max-width: content;
}

.stripe-button:hover {
    background: var(--secondary-hover);
}

.stripe-button-full {
    background: var(--secondary-color);
    color: white;
    border-radius: var(--border-radius);
    padding: 15px;
    font-size: 16px;
    margin-top: 10px;
}

.stripe-button-full:hover {
    background: var(--secondary-hover);
}

.details-button {
    background: var(--primary-color);
    color: white;
    border-radius: var(--border-radius);
    padding: 12px;
    font-size: 14px;
    margin-top: 5px;
    width: 100%;
    max-width: content;
}

.details-button:hover {
    background: var(--primary-hover);
}

.invoice-button {
    background: var(--success-color);
    color: white;
    border-radius: var(--border-radius);
    padding: 12px;
    font-size: 14px;
    margin-top: 5px;
    width: 100%;
    max-width: 190px;
}

.invoice-button:hover {
    background: var(--success-hover);
}

.invoice-wait {
    color: #2e2e2e;
    border: 1px solid #5B5E5E;
    border-radius: var(--border-radius);
    padding: 8px 12px 8px 12px;
    font-size: 14px;
    font-weight: 800;
    margin-top: 5px;
    width: 100%;
    max-width: content;
    margin-bottom: 10px !important;
    display: block;
    background: #eee;
    align-content: center;
}

.invoice-wait:hover {
    background: #ddd;
}

/* Pagination */
.pagination { 
    display: flex; 
    justify-content: center; 
    margin-top: 20px;
    flex-wrap: wrap;
    gap: 5px;
}

.pagination a, .pagination span { 
    padding: 10px 15px; 
    margin: 2px; 
    text-decoration: none; 
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 14px;
}

.pagination a:hover { 
    background-color: #f2f2f2; 
}

.pagination .active { 
    background-color: var(--primary-color); 
    color: white; 
    border-color: var(--primary-color); 
}

.pagination .disabled { 
    color: #ddd; 
    cursor: not-allowed; 
}

/* Info Boxes */
.copyright {
    text-align: center;
    margin-top: 200px;
    margin-bottom: 20px;
    color: #666;
    font-size: 0.9em;
    line-height: 1.5;
    padding: 20px;
}

.cost-info, .pricing-info, .production-notice,
.payment-success, .payment-cancelled, .error {
    margin: 15px 0;
    padding: 15px;
    border-radius: var(--border-radius);
    border-left: 5px solid;
}

.cost-info {
    background-color: #e7f3ff;
    border-left-color: var(--info-color);
    padding-left:30px;
}

.pricing-info {
    background-color: #fff8e1;
    border-left-color: var(--warning-color);
    padding-left:30px;
}

.production-notice {
    background-color: var(--success-color);
    color: white;
    text-align: center;
    font-weight: bold;
}

.payment-success {
    background-color: #d4edda;
    color: #155724;
    border-left-color: #c3e6cb;
}

.payment-cancelled {
    background-color: #f8d7da;
    color: #721c24;
    border-left-color: #f5c6cb;
}

.error {
    color: var(--danger-color);
    font-weight: bold;
    background-color: #ffe6e6;
    border: 1px solid var(--danger-color);
}

/* Monthly Comparison */
.monthly-comparison {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 20px 0;
}

.monthly-table {
    width: 100%;
    overflow-x: auto;
    margin: 20px 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.monthly-table table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.monthly-table th, 
.monthly-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.monthly-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.monthly-table tr:hover {
    background-color: #f5f7ff;
}

.chart-container {
    width: 100%;
    height: 300px;
    min-height: 250px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    margin: 30px 0;
    position: relative;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2d3748;
}

.chart-legend {
    display: flex;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    margin-right: 8px;
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 250px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1000;
    bottom: 125%;
    left: 50%;
    margin-left: -125px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 12px;
    font-weight: normal;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

.tooltip-icon {
    font-size: 14px;
    margin-left: 5px;
    color: #666;
}

/* Payment Status */
.payment-status-icon {
    font-size: 18px;
    margin-right: 5px;
}

.paid-icon {
    color: var(--success-color);
}

.unpaid-icon {
    color: var(--danger-color);
}

.payment-status-paid { color: var(--success-color); font-weight: bold; }
.payment-status-pending { color: var(--warning-color); font-weight: bold; }
.payment-status-unpaid { color: var(--danger-color); font-weight: bold; }

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

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 95%;
    max-width: 900px;
    border-radius: 8px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 10px;
    z-index: 1001;
}

.close:hover {
    color: black;
}

.modal-header {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 15px;
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.modal-table th, .modal-table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
    word-break: break-word;
}

.modal-table th {
    background-color: #f2f2f2;
}

.loading {
    text-align: center;
    padding: 40px;
    font-size: 16px;
}

/* Modal Pagination */
.modal-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
    margin-bottom: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-pagination button {
    margin: 0;
    padding: 8px 15px;
    border: 1px solid #ddd;
    background: #f8f8f8;
    cursor: pointer;
    width: auto;
    font-size: 14px;
}

.modal-pagination button:disabled {
    background: #e9e9e9;
    cursor: not-allowed;
    opacity: 0.6;
}

.modal-pagination span {
    margin: 0 10px;
    padding: 5px 10px;
    font-size: 14px;
}

/* Logo Styles */
.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 40px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.logo {
    height: 35px;
    width: auto;
    max-width: 120px;
}

/* Results Info */
.results-info {
    margin: 15px 0;
    padding: 15px;
    background: #e9e9e9;
    border-radius: var(--border-radius);
    font-size: 14px;
}

/* Subscription Plans */
.subscription-plans {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin: 20px 0;
}

.subscription-plan {
    flex: 1;
    min-width: 250px;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background: #f9f9f9;
}

.subscription-plan h4 {
    margin: 0 0 10px 0;
    color: #333;
}

.plan-price {
    font-size: 24px;
    font-weight: bold;
    color: #4CAF50;
    margin: 10px 0;
}

.plan-description {
    color: #666;
    font-size: 14px;
    margin: 10px 0;
}

/* Subscription Info */
.subscription-info {
    background-color: #e8f5e9;
    border-left: 4px solid #4CAF50;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
}

.subscription-info h3 {
    margin-top: 0;
    color: #2e7d32;
}

/* Error Message */
.error-message {
    background-color: #ffebee;
    border-left: 4px solid #f44336;
    color: #c62828;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
}

/* Mobile Table Alternatives */
.mobile-table-cards {
    display: none; /* Hidden by default, shown on mobile */
}

.mobile-card {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.mobile-card-row:last-child {
    border-bottom: none;
}

.mobile-card-label {
    font-weight: bold;
    color: #666;
    min-width: 120px;
}

.mobile-card-value {
    text-align: right;
    word-break: break-word;
    flex: 1;
    margin-left: 10px;
}

/* Touch-friendly tooltips */
.chartjs-tooltip {
    pointer-events: none;
    position: absolute;
    z-index: 100;
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    body {
        padding: 10px;
        font-size: 14px;
    }
    
    .container {
        padding: 15px;
        margin: 0;
        border-radius: 0;
    }
    
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    
    .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .form-group {
        min-width: 100%;
        margin-bottom: 10px;
    }
    
    input, select, button {
        padding: 14px; /* Larger touch targets */
        margin-bottom: 12px;
    }
    
    .monthly-comparison {
        flex-direction: column;
    }
    
    .monthly-table {
        min-width: 100%;
    }
    
    .chart-container {
        overflow-x: auto;
        padding: 5px;
    }
    
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-legend {
        flex-wrap: wrap;
        margin-top: 10px;
    }
    
    .legend-item {
        margin-right: 15px;
        margin-bottom: 8px;
    }
    
    .monthly-table {
        overflow-x: auto;
    }
    
    .monthly-table table {
        min-width: 600px;
    }
    
    /* Stack buttons on mobile */
    .stripe-button, .details-button, .invoice-button {
        max-width: 100%;
        margin-bottom: 8px;
        margin-right: 0;
        padding: 6px 10px;
        font-size: 12px;
    }
    
    /* Adjust table for mobile - SIMPLIFIED APPROACH */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: var(--border-radius);
    }
    
    table {
        font-size: 12px;
        min-width: 600px; /* Force horizontal scrolling on small screens */
        width: 100%;
    }
    
    th, td {
        padding: 8px;
        font-size: 12px;
        white-space: nowrap;
    }
    
    th {
        background-color: #f0f0f0;
    }
    
    /* Modal adjustments for mobile */
    .modal-content {
        margin: 10% auto;
        padding: 15px;
        width: 95%;
    }
    
    .modal-table {
        font-size: 11px;
        min-width: 500px;
    }
    
    .modal-table th, .modal-table td {
        padding: 6px;
    }
    
    /* Pagination adjustments */
    .pagination a, .pagination span {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Hide some less important elements on mobile */
    .production-notice {
        font-size: 14px;
        padding: 8px;
    }
    
    .monthly-table table th,
    .monthly-table table td {
        padding: 8px 6px;
        font-size: 13px;
    }
    
    .invoice-wait {
        padding: 8px 30px 8px 30px;
    }
    
    .desktop-table {
        display: none;
    }
    
    .mobile-table-cards {
        display: block;
    }
    
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .chart-legend {
        flex-wrap: wrap;
        margin-top: 10px;
    }
    
    .legend-item {
        margin-right: 15px;
        margin-bottom: 8px;
    }
}

@media screen and (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 10px;
    }
    
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }
    
    input, select, button {
        padding: 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .search-button {
        padding: 16px;
        font-size: 16px;
    }
    
    .modal-content {
        padding: 10px;
        margin: 5% auto;
    }
    
    .logo {
        height: 30px;
    }
    
    .tooltip .tooltiptext {
        width: 200px;
        margin-left: -100px;
        font-size: 11px;
    }
    
    /* Even smaller tables on very small screens */
    table {
        min-width: 500px;
    }
    
    th, td {
        padding: 6px;
        font-size: 11px;
    }
    
    .invoice-wait {
        padding: 8px 30px 8px 30px;
    }
}

/* Desktop-specific styles */
@media screen and (min-width: 769px) {
    table {
        width: 100%;
        table-layout: auto;
    }
    
    th, td {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }
    
    /* Ensure tables take full width on desktop */
    .table-container {
        width: 100%;
        overflow-x: visible;
    }
    
    .mobile-table-cards {
        display: none;
    }
    
    .desktop-table {
        display: table;
    }
}

/* High-resolution devices */
@media screen and (min-width: 1200px) {
    .container {
        padding: 30px;
    }
    
    body {
        font-size: 16px;
    }
}

/* Print styles */
@media print {
    .search-button, .stripe-button, .details-button,
    .invoice-button, .invoice-wait, .pagination,
    .production-notice, .logo-container {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
        font-size: 12px;
    }
    
    .container {
        box-shadow: none;
        padding: 0;
    }
    
    table {
        page-break-inside: avoid;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000000;
        --primary-hover: #333333;
        --secondary-color: #000000;
        --secondary-hover: #333333;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .modal-content {
        border: 2px solid black;
    }
    
    th {
        background: #000000;
        color: white;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #58A5A4;
        --primary-hover: #6BB7B6;
        --secondary-color: #5469d4;
        --secondary-hover: #6578e0;
        --dark-color: #f8f9fa;
        --light-color: #343a40;
    }
    
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }
    
    .container {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    th, td {
        border-color: #555;
    }
    
    th {
        background-color: #3d3d3d;
        color: #e0e0e0;
    }
    
    input, select, textarea {
        background: #3d3d3d;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .cost-info {
        background-color: #2d3d4d;
        border-left-color: #2196F3;
    }
    
    .pricing-info {
        background-color: #3d3d2d;
        border-left-color: #ffc107;
    }
}