/* static/style.css */
:root {
    --sat: env(safe-area-inset-top);
    --sar: env(safe-area-inset-right);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
    --card-bg-light: rgba(255, 255, 255, 0.15);
    --card-bg-dark: rgba(0, 0, 0, 0.4);
    --text-color-light: #212529;
    --text-color-dark: #f0f0f0;
    --text-color: #212529;
    --card-border-light: rgba(255, 255, 255, 0.3);
    --card-border-dark: rgba(255, 255, 255, 0.2);
    --flow-border-light: #000000;
    --flow-border-dark: #ffffff;
    --good-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --animation-duration: 0.5s;
    --line-color: #000000;
    --box-fill: transparent;
    --border-color: var(--flow-border-light);
}

/* Растягиваем оболочку */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
    padding-right: var(--sar);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    background-attachment: fixed;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover !important;
}

/* СВЕТЛАЯ ТЕМА (Логин и Обои) */
body.unauth-bg, .login-container {
    background-image: url('/static/auth.jpg') !important;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover !important;
}

body.auth-bg {
    background-image: url('/static/wallpaper.jpg') !important;
}

h1 {
    font-size: 2rem;
    margin-top: 0;
    line-height: 1.2;
    font-weight: 600;
}

.container {
    width: 100%;
    max-width: 100%;
    padding-left: max(env(safe-area-inset-left), 15px);
    padding-right: max(env(safe-area-inset-right), 15px);
}

.d-flex.mb-3 {
    margin-top: max(env(safe-area-inset-top), 10px);
}

.modal-dialog {
    margin-top: max(env(safe-area-inset-top), 1.75rem);
    margin-bottom: max(env(safe-area-inset-bottom), 1.75rem);
}

.status-card, .flow-card, .graph-container, #week-stats, .log-container, .settings-table,
.chart-container, .glass-panel {
    background: var(--card-bg-light);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: none;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    color: inherit;
    transition: all 0.3s ease;
}

.status-card {
    padding: 15px;
    margin-bottom: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    word-break: break-word;
}

.status-card p {
    margin: 5px 0;
    line-height: 1.5;
    font-size: 1rem;
    white-space: nowrap;
}

#inverter-params p:last-child {
    white-space: normal;
    word-break: break-all;
}

.status-card h5 {
    margin-bottom: 12px;
    font-size: 1.1rem;
    white-space: nowrap;
    font-weight: 600;
}

.flow-card {
    padding: 15px 15px 5px 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.flow-card h5 {
    margin-top: 0;
    margin-bottom: 10px;
    line-height: 1.2;
    font-weight: 600;
}

.flow-card canvas {
    display: block;
    width: 100%;
    aspect-ratio: 800 / 600;
    border-radius: 10px;
}

.right-column {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 20px;
}

.row-flex {
    flex: 1 1 0;
    display: flex;
    gap: 20px;
    min-height: 0;
}

.col-flex {
    flex: 1;
    display: flex;
    min-width: 0;
}

.col-flex .status-card {
    width: 100%;
    height: 100%;
    margin: 0;
}

.row-flex:last-child {
    margin-bottom: 0;
}

.graph-container, #week-stats {
    padding: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
}

/* ФИКСИРОВАННАЯ ВЫСОТА ДЛЯ ВСЕХ ГРАФИКОВ */
.chart-container {
    position: relative;
    height: 500px;        /* фиксированная высота */
    width: 100%;
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 15px;
    box-sizing: border-box;
}

.chart-container canvas {
    height: 100% !important;
    width: 100% !important;
}

.glass-panel {
    padding: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.nav-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    border-bottom: none !important;
    list-style: none !important;
}

.nav-tabs .nav-item {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    max-width: none !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
}

.nav-tabs .nav-link {
    display: block !important;
    width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    margin: 0 !important;
    padding: 0.5rem 0.75rem !important;
    border: none !important;
    border-radius: 15px !important;
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(5px) !important;
    color: var(--text-color) !important;
    box-sizing: border-box !important;
    font-weight: 500;
}

.nav-tabs .nav-link.active {
    background: rgba(255, 255, 255, 0.3) !important;
    color: var(--text-color) !important;
}

.btn-primary {
    background: rgba(46, 204, 113, 0.3);
    border: none;
    backdrop-filter: blur(5px);
    color: var(--text-color);
    font-weight: 500;
}

.btn-primary:hover {
    background: rgba(46, 204, 113, 0.5);
}

.btn-danger {
    background: rgba(231, 76, 60, 0.3);
    border: none;
    backdrop-filter: blur(5px);
    color: var(--text-color);
}

.btn-outline-secondary {
    background: rgba(255,255,255,0.1);
    border: none;
    backdrop-filter: blur(5px);
    color: var(--text-color);
}

.btn-glass-blue {
    background: rgba(13, 110, 253, 0.25);
    border: none;
    backdrop-filter: blur(5px);
    color: var(--text-color);
    transition: background 0.3s ease;
}

.form-control {
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(5px);
    border: none;
    color: var(--text-color);
}

.form-label {
    color: var(--text-color);
    font-weight: 500;
}

.glass-select {
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: none !important;
    color: var(--text-color) !important;
    border-radius: 15px !important;
    padding: 0.375rem 2.25rem 0.375rem 0.75rem !important;
    cursor: pointer;
}

.inverter-select-wrapper {
    position: relative;
    display: inline-block;
}
.inverter-select-wrapper .glass-select {
    padding-right: 40px !important;
}
.inverter-select-wrapper .inverter-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 1.2rem;
    color: var(--text-color);
    opacity: 0.8;
}

.date-field {
    max-width: 250px;
    min-width: 180px;
    width: auto;
}

.date-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.date-input-wrapper .calendar-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 1.2rem;
    color: var(--text-color);
    opacity: 0.8;
}

table {
    background: transparent;
    color: inherit;
    width: 100%;
}

th, td {
    border: 1px solid var(--card-border-light);
    padding: 8px;
    color: var(--text-color);
}

th {
    background: rgba(255,255,255,0.1);
    font-weight: 600;
}

.settings-table input {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--card-border-light);
    color: var(--text-color);
}

.log-container {
    background: var(--card-bg-light);
    backdrop-filter: blur(10px);
    color: var(--text-color);
}

.log-line {
    border-bottom: 1px solid var(--card-border-light);
}

.bg-light {
    background-color: var(--card-bg-light) !important;
    backdrop-filter: blur(10px);
}

#events-list {
    max-height: 300px;
    overflow-y: auto;
    color: inherit;
}

#events-list.border {
    border: 1px solid var(--card-border-light) !important;
}

.updated {
    animation: flash var(--animation-duration) ease;
}

@keyframes flash {
    0% { background-color: rgba(255, 255, 255, 0.3); }
    100% { background-color: transparent; }
}

.value-good { color: var(--good-color); font-weight: 600; }
.value-warning { color: var(--warning-color); font-weight: 600; }
.value-danger { color: var(--danger-color); font-weight: 600; }

#canvas-wrapper {
    position: relative;
    background: var(--card-bg-light);
    backdrop-filter: blur(5px);
    border: none;
    border-radius: 15px;
    padding: 5px;
}

#weekCanvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1800 / 750;
    background: transparent;
}

#week-stats {
    display: flex;
    flex-direction: row;
    gap: 20px;
    width: 100%;
}

.header-icon {
    height: 0.9em;
    width: auto;
    vertical-align: baseline;
    margin-right: 0.3em;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

.title-icon {
    height: 1.2em;
    width: auto;
    margin-right: 0.2em;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
    vertical-align: text-top;
    margin-top: -5px;
}

.total-item {
    margin-bottom: 15px;
}
.total-item span {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #fff;
}

.progress-bar-container {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    height: 20px;
    width: 100%;
    overflow: hidden;
}

.progress-bar-fill {
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
}

.tou-container {
    background: var(--card-bg-light);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    margin-top: 20px;
}

.tou-table {
    width: 100%;
    border-collapse: collapse;
}

.tou-table th, .tou-table td {
    border: 1px solid var(--card-border-light);
    padding: 8px;
    text-align: center;
}

.tou-table th {
    background: rgba(255,255,255,0.2);
}

.yasno-card-mini .update-info {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
}

.yasno-tab-container {
    padding: 20px;
    background: var(--card-bg-light);
    backdrop-filter: blur(10px);
    border-radius: 15px;
}

.yasno-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.yasno-table th, .yasno-table td {
    border: 1px solid var(--card-border-light);
    padding: 8px;
    text-align: left;
}

.yasno-table th {
    background: rgba(255,255,255,0.2);
}

.pull-indicator {
    position: fixed;
    top: 0; left: 0; right: 0; height: 60px;
    background: rgba(13, 110, 253, 0.9);
    backdrop-filter: blur(10px);
    color: white;
    display: flex; align-items: center; justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.2s;
    z-index: 9999;
    font-weight: bold;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
}

@media (max-width: 768px) {
    .container { padding-left: 10px; padding-right: 10px; }
    h1 { font-size: 1.5rem; }
    .row-flex { flex-direction: column; gap: 10px; flex: none; }
    .nav-tabs { overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; padding-bottom: 5px !important; }
    .nav-tabs .nav-item { flex: 0 0 auto !important; }
}

/* ===== ТЁМНАЯ ТЕМА ===== */
@media (prefers-color-scheme: dark) {
    /* Переключаем обои и фон логина на DARK */
    body.auth-bg {
        background-image: url('/static/wallpaper_dark.jpg') !important;
    }
    
    body.unauth-bg, .login-container {
        background-image: url('/static/auth_dark.jpg') !important;
    }

    .tou-container, .tou-table th, .tou-table td, .tou-info {
        color: #fff !important;
    }

    :root {
        --text-color: var(--text-color-dark);
        --line-color: #ffffff;
        --card-border-light: var(--card-border-dark);
        --border-color: var(--flow-border-dark);
    }
    body { color: var(--text-color-dark); }

    .status-card, .flow-card, .graph-container, #week-stats, .log-container, .settings-table,
    .chart-container, .glass-panel {
        background: var(--card-bg-dark) !important;
        backdrop-filter: blur(12px);
    }

    th { background: rgba(0,0,0,0.3) !important; }

    .nav-tabs .nav-link {
        background: rgba(0, 0, 0, 0.4) !important;
        color: #fff !important;
    }
    .nav-tabs .nav-link.active {
        background: rgba(0, 0, 0, 0.6) !important;
    }

    .glass-select, .form-control {
        background: rgba(0, 0, 0, 0.4) !important;
        border: 1px solid rgba(255,255,255,0.2) !important;
        color: #fff !important;
    }

    .yasno-tab-container {
        background: var(--card-bg-dark);
        color: var(--text-color-dark);
    }
}

/* СТИЛИ ЛОГИНА */
.login-container {
    position: fixed; 
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
}

.login-card {
    width: 100%; max-width: 380px; padding: 2rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 15px;
}

.login-card .form-control {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
