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

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #8bc34a 0%, #4caf50 100%);
    color: #333;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    box-sizing: border-box;
}

/* Header */
header {
    background: linear-gradient(135deg, #3f8f3a 0%, #2e7d32 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main content */
main {
    padding: 40px;
}

.section {
    margin-bottom: 40px;
}

.section h2 {
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: #333;
    border-bottom: 3px solid #3f8f3a;
    padding-bottom: 15px;
}

/* Form styles */
.form-section form {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

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

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
    font-size: 0.95rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3f8f3a;
    box-shadow: 0 0 0 3px rgba(63, 143, 58, 0.12);
}

.btn-simulate {
    background: linear-gradient(135deg, #3f8f3a 0%, #2e7d32 100%);
    color: white;
    padding: 15px 40px;
    border: none;
    border-radius: 6px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    margin-top: 20px;
}

.btn-simulate:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(63, 143, 58, 0.30);
}

.btn-simulate:active {
    transform: translateY(0);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.kpi-card {
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: all 0.3s ease;
}

.kpi-card:hover {
    border-color: #3f8f3a;
    box-shadow: 0 5px 15px rgba(63, 143, 58, 0.20);
}

.kpi-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
    margin: 10px 0;
    word-wrap: break-word;
}

.kpi-value.highlight {
    color: #3f8f3a;
    font-size: 2.2rem;
}

.kpi-value.warning {
    color: #ff6b6b;
}

.kpi-unit {
    font-size: 0.8rem;
    color: #999;
    margin-top: 8px;
}

/* SoC Info */
.soc-info {
    background: #f0f4ff;
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #3f8f3a;
    margin: 30px 0;
}

.soc-info h3 {
    color: #3f8f3a;
    margin-bottom: 15px;
}

.soc-row {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.soc-item {
    display: flex;
    gap: 10px;
}

.soc-label {
    font-weight: 600;
    color: #555;
}

.soc-value {
    color: #3f8f3a;
    font-weight: 700;
}

/* Day stats */
.day-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.day-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #e9ecef;
}

.day-card h3 {
    color: #3f8f3a;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.day-card p {
    margin: 10px 0;
    color: #666;
}

/* Dataset Info */
.dataset-info-block {
    background: #e8f4f8;
    border-left: 4px solid #0066cc;
    padding: 20px;
    border-radius: 6px;
    margin-bottom: 30px;
    font-size: 0.95em;
}

.dataset-info-block strong {
    color: #0066cc;
}

/* Loading spinner */
.spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.spinner-inner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3f8f3a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.spinner p {
    margin-top: 20px;
    color: #3f8f3a;
    font-weight: 600;
}

/* Error message */
.error-message {
    background: #f8d7da;
    border-left: 4px solid #dc3545;
    color: #721c24;
    padding: 20px;
    border-radius: 6px;
    margin: 20px 0;
}

/* Quick Guide */
.quick-guide {
    background: #f0f7ff;
    border: 1px solid #b3d9ff;
    border-radius: 6px;
    padding: 0;
    margin: 20px 0;
}

.guide-summary {
    background: linear-gradient(135deg, #e8f4fd 0%, #d9ecfd 100%);
    padding: 15px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    color: #0066cc;
    border-radius: 6px;
    user-select: none;
    transition: background-color 0.2s ease;
}

.guide-summary:hover {
    background: linear-gradient(135deg, #d9ecfd 0%, #c9e0fd 100%);
}

.guide-content {
    padding: 15px 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #333;
}

.guide-content ol {
    margin: 10px 0 15px 20px;
}

.guide-content li {
    margin-bottom: 8px;
}

.guide-content a {
    color: #2196F3;
    text-decoration: none;
    font-weight: 500;
}

.guide-content a:hover {
    text-decoration: underline;
}

/* Analytics Dashboard */
#analyticsDashboard {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid #e9ecef;
}

#analyticsDashboard h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 30px;
}

.analytics-summary > div {
    background: white;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    text-align: center;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    margin-bottom: 30px;
    align-items: stretch;
}

.chart-card {
    background: white;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.chart-card h3 {
    font-size: 1rem;
    margin-bottom: 15px;
    color: #333;
    word-break: break-word;
}

.chart-card canvas {
    min-height: 300px;
    max-height: none;
    flex: 1;
    max-width: 100% !important;
    width: 100% !important;
}

.chart-wrapper {
    position: relative;
    height: 320px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.chart-info-message {
    padding: 12px;
    background: #fff3cd;
    border-left: 3px solid #ffc107;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #856404;
    display: none;
}

.chart-controls {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.chart-controls label {
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
    color: #333;
}

.chart-controls select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
    background: white;
    cursor: pointer;
}

.top-bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.top-bottom-grid > div {
    background: white;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.top-bottom-grid h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #333;
}

.top-bottom-grid table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.top-bottom-grid th {
    background: #f8f9fa;
    padding: 8px;
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid #ddd;
}

.top-bottom-grid td {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

/* Daily table styling */
.daily-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: white;
}

.daily-table-header th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8f9fa;
    border-bottom: 2px solid #ddd;
    padding: 10px;
    font-weight: 600;
}

.daily-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

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

.daily-table tbody tr {
    border-bottom: 1px solid #eee;
}

.daily-table tbody td {
    padding: 10px;
}

.sortable {
    user-select: none;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.sortable:hover {
    background: #e8ecf1 !important;
}

.sort-indicator {
    font-size: 0.8rem;
    margin-left: 4px;
    color: #999;
}

.sortable.active .sort-indicator {
    color: #3f8f3a;
    font-weight: 700;
}

.value-positive {
    color: #28a745;
    font-weight: 600;
}

.value-negative {
    color: #dc3545;
    font-weight: 600;
}

.value-neutral {
    color: #999;
    font-weight: 600;
}

.trade-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    min-width: 70px;
}

.trade-badge.yes {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.trade-badge.no {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Footer */
footer {
    background: #f8f9fa;
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
    border-top: 1px solid #e9ecef;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    main {
        padding: 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .kpi-value {
        font-size: 1.5rem;
    }

    .soc-row {
        flex-direction: column;
        gap: 15px;
    }

    .day-stats {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-card {
        width: 100%;
        padding: 1rem;
    }

    .chart-wrapper {
        height: 240px;
    }

    .chart-controls {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .chart-controls select {
        width: 100%;
    }

    .top-bottom-grid {
        grid-template-columns: 1fr;
    }

    .analytics-summary {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .chart-wrapper {
        height: 220px;
    }

    .chart-card h3 {
        font-size: 0.9rem;
        line-height: 1.25;
        margin-bottom: 10px;
    }

    .chart-controls {
        padding: 10px;
        gap: 8px;
    }

    .chart-controls label {
        font-size: 0.9rem;
    }

    .chart-controls select {
        font-size: 0.9rem;
        padding: 6px;
    }

    main {
        padding: 15px;
    }

    header h1 {
        font-size: 1.5rem;
    }
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content.modal-lg {
    max-width: 1000px;
    max-height: 95vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 30px;
}

.modal-body .form-group {
    margin-bottom: 20px;
}

.modal-body label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
}

.modal-body input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.modal-body input:focus {
    outline: none;
    border-color: #3f8f3a;
    box-shadow: 0 0 0 3px rgba(63, 143, 58, 0.12);
}

.form-hint {
    display: block;
    font-size: 0.85rem;
    color: #999;
    margin-top: 4px;
}

.error-inline {
    color: #d32f2f;
    font-size: 0.9rem;
    padding: 10px;
    background: #ffebee;
    border-left: 3px solid #d32f2f;
    border-radius: 4px;
}

.calculation-summary {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 6px;
    margin: 20px 0;
}

.calculation-summary h3 {
    margin-top: 0;
    color: #333;
    font-size: 1.1rem;
}

.formula-step {
    margin: 15px 0;
    font-size: 0.95rem;
}

.formula-step code {
    display: block;
    background: white;
    padding: 8px 12px;
    border-left: 3px solid #3f8f3a;
    margin-top: 6px;
    font-family: "Courier New", monospace;
    color: #666;
}

.result-box {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border: 2px solid #3f8f3a;
    border-radius: 6px;
    text-align: center;
}

.result-box strong {
    display: block;
    margin-bottom: 8px;
    color: #333;
}

.modal-note {
    background: #fffbf0;
    padding: 15px;
    border-left: 4px solid #ff9800;
    border-radius: 4px;
    margin-top: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
}

.modal-note p {
    margin: 10px 0;
}

.modal-note p:first-child {
    margin-top: 0;
}

.modal-note p:last-child {
    margin-bottom: 0;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    justify-content: flex-end;
}

.btn-primary {
    background: #3f8f3a;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #256b2a;
}

.btn-primary:active {
    background: #1b5e20;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* Day Detail modal */
.day-detail-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.day-detail-card {
    background: #f0f4ff;
    padding: 12px;
    border-radius: 6px;
    border-left: 3px solid #3f8f3a;
    font-size: 0.9rem;
}

.day-detail-card-label {
    display: block;
    color: #666;
    font-size: 0.85rem;
    margin-bottom: 4px;
    font-weight: 500;
}

.day-detail-card-value {
    display: block;
    color: #333;
    font-size: 1.1rem;
    font-weight: bold;
}

.day-detail-card-value.positive {
    color: #28a745;
}

.day-detail-card-value.negative {
    color: #dc3545;
}

/* Collapsible section */
.collapsible-section h3 {
    transition: color 0.2s;
}

.collapsible-section h3:hover {
    color: #ff9800;
}

/* Mobile responsiveness for modal */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
    }

    .modal-content {
        max-height: 95vh;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
    }
}


/* Customer registration and verification */

.customer-auth-section {
    max-width: 620px;
    margin: 30px auto;
}

.customer-auth-card {
    background: #ffffff;
    border: 1px solid #e1e5ea;
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.customer-auth-heading {
    margin-bottom: 24px;
}

.customer-auth-heading h2 {
    margin-bottom: 8px;
}

.customer-auth-heading p,
.customer-auth-help {
    color: #5f6670;
    line-height: 1.5;
}

.customer-auth-message {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 6px;
    line-height: 1.4;
}

.customer-auth-message.error {
    background: #fdeaea;
    border: 1px solid #efb6b6;
    color: #9f1d1d;
}

.customer-auth-message.success {
    background: #eaf7ee;
    border: 1px solid #add9ba;
    color: #1f6b35;
}

.customer-auth-card input {
    width: 100%;
    box-sizing: border-box;
}

.customer-otp-input {
    max-width: 220px;
    font-size: 1.5rem;
    letter-spacing: 0.35rem;
    text-align: center;
}

.customer-secondary-button {
    margin-top: 14px;
    padding: 9px 14px;
    border: 1px solid #b9c0c9;
    border-radius: 6px;
    background: #ffffff;
    cursor: pointer;
}

.customer-secondary-button:hover {
    background: #f4f5f7;
}

.customer-session-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 10px 14px;
    border: 1px solid #dce2e8;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 0.9rem;
}

.customer-logout-button {
    padding: 7px 12px;
    border: 1px solid #c5cbd2;
    border-radius: 6px;
    background: #ffffff;
    cursor: pointer;
}

.customer-logout-button:hover {
    background: #f0f2f4;
}

@media (max-width: 600px) {
    .customer-auth-card {
        padding: 20px;
    }

    .customer-session-bar {
        align-items: flex-start;
        flex-direction: column;
    }
}

.customer-simulation-usage {
    margin-top: 4px;
    color: #5f6670;
    font-size: 0.85rem;
}


/* Ferplant / D-BESS commercial branding */

header.brand-header {
    background:
        linear-gradient(
            135deg,
            #f8fbf7 0%,
            #f3f8fa 100%
        );
    color: #173a59;
    padding: 28px 36px 30px;
    text-align: left;
    border-bottom: 4px solid #78a942;
}

.brand-logo-row {
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand-logo-card {
    min-height: 68px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid #dfe7e9;
    border-radius: 10px;
    box-shadow: 0 3px 10px rgba(23, 58, 89, 0.06);
}

.brand-logo-card img {
    display: block;
    width: auto;
    object-fit: contain;
}

.ferplant-brand img {
    max-width: 145px;
    max-height: 52px;
}

.dbess-brand img {
    max-width: 175px;
    max-height: 52px;
}

.brand-divider {
    width: 1px;
    height: 46px;
    background: #d6e0e3;
}

.brand-copy {
    max-width: 900px;
    margin-top: 20px;
}

.brand-eyebrow {
    margin-bottom: 6px;
    color: #78a942;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

header.brand-header h1 {
    margin: 0 0 8px;
    color: #173a59;
    font-size: 2.35rem;
    line-height: 1.1;
}

header.brand-header .subtitle {
    margin: 0;
    color: #596d79;
    font-size: 1.05rem;
    opacity: 1;
}

@media (max-width: 700px) {
    header.brand-header {
        padding: 22px 20px 24px;
    }

    .brand-logo-row {
        gap: 10px;
    }

    .brand-logo-card {
        min-height: 56px;
        padding: 7px 10px;
    }

    .ferplant-brand img {
        max-width: 110px;
        max-height: 42px;
    }

    .dbess-brand img {
        max-width: 125px;
        max-height: 42px;
    }

    .brand-divider {
        height: 38px;
    }

    header.brand-header h1 {
        font-size: 1.75rem;
    }

    header.brand-header .subtitle {
        font-size: 0.95rem;
    }
}
