/* Basic CSS styles for the dashboard */

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f9;
    color: #333;
}

header {
    background-color: #2c3e50;
    color: white;
    padding: 0.6em 1em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left h1 {
    margin: 0;
    font-size: 1.3rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#deye-status-bar {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.1);
    padding: 4px 10px;
    border-radius: 12px;
}

.header-station-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.1);
    padding: 4px 10px;
    border-radius: 12px;
}

.hs-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    white-space: nowrap;
}

.hs-select {
    font-size: 0.75rem;
    padding: 2px 6px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    background: rgba(255,255,255,0.15);
    color: white;
    cursor: pointer;
    max-width: 180px;
}

.hs-select option {
    background: #2c3e50;
    color: white;
}

.icon-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 1.2rem;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    line-height: 1;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.3);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-unknown { background-color: #95a5a6; }
.status-online { background-color: #2ecc71; }
.status-offline { background-color: #e74c3c; }

#deye-last-update {
    color: #bdc3c7;
    margin-left: 4px;
}

#tab-home {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Energy Metrics Grid */
.card-grid {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.metric-card {
    background-color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex: 1;
    min-width: 160px;
    text-align: center;
}

.metric-card h3 {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-value {
    font-size: 2rem;
    font-weight: bold;
    margin: 5px 0;
}

.metric-value .unit {
    font-size: 1rem;
    font-weight: normal;
    color: #95a5a6;
}

.metric-label {
    font-size: 0.75rem;
    color: #95a5a6;
    margin: 4px 0 0 0;
}

/* Component Status Grid */
#component-status {
    margin-top: 30px;
}

.component-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

/* Component Card Styling */
.component-card {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-left: 5px solid #3498db; /* Default color */
}

/* Specific status colors (Example) */
.status-online { border-color: #2ecc71 !important; }
.status-offline { border-color: #e74c3c !important; }

/* Chart Area */
.chart-area {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 30px;
}

/* Deye Debug Section */
#deye-debug-section {
    margin-top: 30px;
    background: #2c3e50;
    color: #ecf0f1;
    padding: 15px;
    border-radius: 8px;
}

#deye-debug-section h3 {
    margin: 0 0 10px 0;
    color: #3498db;
}

#deye-debug-info {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

/* Inverter Group Selector */
#inverter-selector-section {
    margin-top: 20px;
}

#inverter-selector-section h2 {
    margin-bottom: 10px;
}

.selector-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.selector-bar label {
    font-weight: 600;
    font-size: 0.85rem;
    color: #555;
    white-space: nowrap;
}

.selector-bar select {
    flex: 1;
    min-width: 250px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #f9f9f9;
    cursor: pointer;
    transition: border-color 0.2s;
}

.selector-bar select:focus {
    outline: none;
    border-color: #3498db;
    background: #fff;
}

.selector-bar .badge {
    background: #3498db;
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Device List */
.device-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.device-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    overflow: hidden;
    border-left: 5px solid #95a5a6;
    transition: box-shadow 0.2s;
}

.device-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.device-card.device-online {
    border-left-color: #2ecc71;
}

.device-card.device-offline {
    border-left-color: #e74c3c;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px 8px;
    background: #fafafa;
    border-bottom: 1px solid #eee;
}

.device-card-header h4 {
    margin: 0;
    font-size: 0.8rem;
    font-family: 'Courier New', monospace;
    color: #2c3e50;
    word-break: break-all;
}

.device-status-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-online {
    background: #d5f5e3;
    color: #27ae60;
}

.badge-offline {
    background: #fadbd8;
    color: #c0392b;
}

.device-card-body {
    padding: 12px 16px;
}

.device-spec {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.8rem;
    border-bottom: 1px solid #f5f5f5;
}

.device-spec:last-of-type {
    border-bottom: none;
}

.spec-label {
    color: #7f8c8d;
    font-weight: 500;
}

.spec-value {
    color: #2c3e50;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.device-card-footer {
    padding: 8px 16px;
    background: #fafafa;
    border-top: 1px solid #eee;
    text-align: right;
}

.device-card-footer .update-time {
    font-size: 0.7rem;
    color: #95a5a6;
}

/* Deye Station Section */
#deye-station-section {
    margin-top: 20px;
}

#deye-station-section h2 {
    margin-bottom: 10px;
}

/* Deye Config Section */
#deye-config-section {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

#deye-config-section h2 {
    margin-top: 0;
    font-size: 1.2rem;
}

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.config-field {
    display: flex;
    flex-direction: column;
}

.config-field label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: #555;
}

.config-field input {
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.9rem;
}

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

.config-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#deye-connect-btn {
    background: #2ecc71;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#deye-connect-btn:hover {
    background: #27ae60;
}

#deye-connect-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

#deye-config-status {
    font-size: 0.85rem;
    font-weight: 500;
}

/* ============================================
   Tab Navigation
   ============================================ */
.tab-bar {
    display: flex;
    background: #34495e;
    padding: 0 16px;
    gap: 0;
    border-bottom: 2px solid #2c3e50;
}

.tab-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    padding: 12px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.05);
}

.tab-btn.active {
    color: #fff;
    border-bottom-color: #2ecc71;
}

.tab-panel {
    display: none;
}

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

/* ============================================
   Admin Tab
   ============================================ */
#tab-admin {
    padding: 20px;
    max-width: 700px;
    margin: 0 auto;
}

#tab-admin h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.4rem;
    color: #2c3e50;
}

.settings-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.settings-card h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    color: #2c3e50;
}

/* ============================================
   Feedback Box
   ============================================ */
.feedback-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid;
    animation: feedbackSlideIn 0.3s ease-out;
}

@keyframes feedbackSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.feedback-box.feedback-success {
    background: #eafaf1;
    border-color: #a3d9b1;
}

.feedback-box.feedback-warning {
    background: #fef9e7;
    border-color: #f9e79f;
}

.feedback-box.feedback-error {
    background: #fdedec;
    border-color: #f5b7b1;
}

.feedback-box.feedback-info {
    background: #ebf5fb;
    border-color: #aed6f1;
}

.feedback-icon {
    font-size: 1.5rem;
    line-height: 1;
    flex-shrink: 0;
    min-width: 28px;
    text-align: center;
}

.feedback-success .feedback-icon::before { content: "✅"; }
.feedback-warning .feedback-icon::before { content: "⚠️"; }
.feedback-error .feedback-icon::before { content: "❌"; }
.feedback-info .feedback-icon::before { content: "ℹ️"; }

.feedback-content {
    flex: 1;
    min-width: 0;
}

.feedback-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 3px;
    color: #2c3e50;
}

.feedback-message {
    font-size: 0.85rem;
    color: #555;
    line-height: 1.4;
}

.feedback-details {
    margin-top: 6px;
    font-size: 0.75rem;
    color: #7f8c8d;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 100px;
    overflow-y: auto;
}

.feedback-close {
    background: none;
    border: none;
    color: #95a5a6;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.feedback-close:hover {
    background: rgba(0,0,0,0.08);
    color: #555;
}

.config-ok { color: #2ecc71; }
.config-error { color: #e74c3c; }
.config-warn { color: #f39c12; }

/* ============================================
   Swagger UI Button
   ============================================ */
.swagger-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    background: #3498db;
    color: white;
    border: none;
}

.swagger-btn:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.swagger-btn.json-btn {
    background: #2c3e50;
}

.swagger-btn.json-btn:hover {
    background: #1a252f;
}

/* ============================================
   Station Power Highlight Card
   ============================================ */
.highlight-card {
    background: linear-gradient(135deg, #eafaf1 0%, #d5f5e3 100%);
    border: 2px solid #2ecc71 !important;
    text-align: center;
}

.highlight-card h3 {
    color: #27ae60 !important;
    font-size: 1rem !important;
}

#station-power-detail .metric-value {
    font-weight: 700;
}

.selector-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.selector-bar label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #2c3e50;
    white-space: nowrap;
}

.selector-bar select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
    max-width: 400px;
}

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

/* ============================================
   Mobile Responsive Design
   ============================================ */

/* Unter 768px (Tablets & Phones) */
@media (max-width: 768px) {
    /* Header */
    header {
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
    }
    .header-left h1 {
        font-size: 1rem;
    }
    .header-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 6px;
    }
    .station-picker {
        max-width: 100% !important;
        flex: 1;
        font-size: 0.7rem !important;
    }
    .header-station-picker {
        flex: 1;
        min-width: 0;
    }
    .hs-select {
        max-width: 100% !important;
        font-size: 0.75rem !important;
        padding: 6px 8px !important;
        min-height: 36px;
    }
    #deye-status-bar {
        font-size: 0.65rem;
        padding: 3px 8px;
    }

    /* Tab Bar – horizontal scrollbar */
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding: 6px 4px;
        gap: 4px;
    }
    .tab-btn {
        font-size: 0.75rem;
        padding: 8px 12px;
        white-space: nowrap;
    }

    /* Tab Panels */
    #tab-home, #tab-live, #tab-history, #tab-devices, #tab-admin {
        padding: 12px;
    }

    /* Überschriften */
    h2 {
        font-size: 1.1rem;
    }
    h3 {
        font-size: 0.95rem;
    }

    /* Card Grids – 1 Spalte */
    .card-grid {
        gap: 10px;
        margin-bottom: 16px;
    }
    .metric-card {
        min-width: 100%;
        padding: 12px 16px;
    }
    .metric-value {
        font-size: 1.5rem;
    }
    .metric-value .unit {
        font-size: 0.85rem;
    }

    /* Selector Bar */
    .selector-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 12px;
    }
    .selector-bar label {
        font-size: 0.8rem;
    }
    .selector-bar select {
        min-width: 100%;
        font-size: 0.8rem;
    }

    /* Config Grid – 1 Spalte */
    .config-grid {
        grid-template-columns: 1fr;
    }
    .config-actions {
        flex-direction: column;
        gap: 8px;
    }
    .config-actions a, .config-actions button {
        width: 100%;
        text-align: center;
    }

    /* Tabellen horizontal scrollbar */
    .db-table {
        font-size: 0.7rem;
    }
    .db-table th, .db-table td {
        padding: 4px 6px;
    }

    /* Charts */
    .chart-area, #history-chart-area {
        min-height: 200px !important;
        padding: 12px;
    }

    /* Device Cards – 1 Spalte */
    .device-list {
        grid-template-columns: 1fr;
    }
    .device-card-header h4 {
        font-size: 0.7rem;
    }

    /* Messpunkte Grid – 2 Spalten */
    #devices-measurements-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    }

    /* Feedback Box */
    .feedback-box {
        flex-direction: column;
    }
    .feedback-content {
        width: 100%;
    }

    /* Settings Cards */
    .settings-card {
        padding: 12px;
    }

    /* Swagger Button */
    .swagger-btn {
        width: 100%;
        text-align: center;
    }

    /* Highlight Card */
    .highlight-card .metric-value {
        font-size: 1.8rem;
    }

    /* Touch-freundliche Buttons + Selects */
    .swagger-btn, .page-btn, .agg-btn, .lang-btn, .sub-tab-btn, .tab-btn {
        min-height: 40px;
        padding: 10px 14px !important;
        font-size: 0.85rem !important;
    }
    .selector-bar select, .selector-bar input, .hs-select {
        min-height: 40px;
        font-size: 0.85rem !important;
    }
    .pagination-bar {
        flex-wrap: wrap;
        gap: 6px;
    }
    .page-info {
        font-size: 0.8rem;
        min-width: auto;
    }
    .points-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
    }
    .point-card {
        padding: 10px 12px !important;
    }
    .point-key {
        font-size: 0.8rem !important;
    }
    .point-val {
        font-size: 1.1rem !important;
    }
    .language-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    }
    .agg-btn {
        padding: 8px 16px !important;
    }
}

/* Unter 480px (kleine Smartphones) */
@media (max-width: 480px) {
    header {
        padding: 6px 10px;
    }
    .header-left h1 {
        font-size: 0.85rem;
    }
    .tab-btn {
        font-size: 0.7rem;
        padding: 6px 10px;
    }
    .metric-value {
        font-size: 1.2rem;
    }
    .metric-card {
        padding: 10px 12px;
    }
    #devices-measurements-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
    }
    .db-table {
        font-size: 0.6rem;
    }
    .db-table th, .db-table td {
        padding: 3px 4px;
    }
    pre {
        font-size: 0.65rem !important;
    }
    .points-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    }
    .language-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
    }
    .swagger-btn, .page-btn, .agg-btn {
        min-height: 36px;
        padding: 8px 10px !important;
    }
    }
}

/* Dark Mode Unterstützung für Pre/Code-Blöcke */
pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.75rem;
}
