html, body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #081525;
}
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}
canvas {
    height: 600px !important;
    min-height: 600px;
}
/* --- Power Flow Diagram (vertical layout) --- */
.power-flow-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px 12px;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}
.pf-row {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
}
.pf-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2;
}
.pf-node .pf-icon {
    font-size: 1.6em;
    margin-bottom: 2px;
}
.pf-node .pf-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.pf-node .pf-value {
    font-size: 1.15rem;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 6px;
    border: 2px solid;
    background: rgba(255,255,255,0.9);
    white-space: nowrap;
    margin: 3px 0;
}
.pf-node .pf-sub {
    font-size: 0.78rem;
    font-weight: 500;
}
.pf-connector {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pf-connector .pf-line {
    background: rgba(0,0,0,0.1);
    position: relative;
}
.pf-connector .pf-line.active {
    position: relative;
    overflow: hidden;
}
.pf-connector .pf-line.active::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    animation: pf-dot-move 1.8s linear infinite;
}
.pf-connector.vertical {
    flex-direction: column;
}
.pf-connector.vertical .pf-line {
    width: 3px;
    height: 28px;
}
.pf-connector.vertical .pf-line.active::after {
    width: 8px;
    height: 8px;
    left: -2.5px;
}
.pf-connector.vertical.down .pf-line.active::after {
    animation-name: pf-dot-down;
}
.pf-connector.vertical.up .pf-line.active::after {
    animation-name: pf-dot-up;
}
.pf-connector.horizontal .pf-line {
    height: 3px;
    width: 36px;
}
.pf-connector.horizontal .pf-line.active::after {
    width: 8px;
    height: 8px;
    top: -2.5px;
}
.pf-connector.horizontal.right .pf-line.active::after {
    animation-name: pf-dot-right;
}
.pf-connector.horizontal.left .pf-line.active::after {
    animation-name: pf-dot-left;
}
.pf-arrow {
    font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "Arial Unicode MS", sans-serif;
    font-size: 1.5rem;
    font-weight: 500;
    display: none;
    line-height: 1;
    letter-spacing: 1px;
}
.pf-arrow.active {
    display: inline-block;
}
.pf-solar-row {
    position: relative;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: flex-start;
    column-gap: 18px;
    min-height: 88px;
}

.pf-solar-row > .pf-priority-box {
    grid-column: 1;
    justify-self: start;
    margin-left: 4px;
}

.pf-solar-row > .pf-node {
    grid-column: 2;
    justify-self: center;
}

.pf-priority-box {
    position: static;
    transform: none;
    margin-top: 10px;
    padding: 6px 8px 5px;
    min-width: 100px;
    border: 1px dashed rgba(76, 96, 126, 0.55);
    border-radius: 8px;
    background: rgba(245, 248, 255, 0.9);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5);
    box-sizing: border-box;
}

.pf-priority-title {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #58657a;
    line-height: 1.1;
    margin-bottom: 2px;
}

.pf-refresh-ticker {
    position: absolute;
    right: 10px;
    top: 10px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    cursor: pointer;
    outline: none;
    user-select: none;
}
.pf-refresh-ticker svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    overflow: visible;
}
.pf-refresh-ticker .base-ring {
    fill: none;
    stroke: rgba(0,0,0,0.12);
    stroke-width: 3;
}
.pf-refresh-ticker .progress-ring {
    fill: none;
    stroke: #2e7d32;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.2s linear;
}
.pf-refresh-ticker .inner-text {
    position: absolute;
    font-size: 0.7rem;
    font-weight: 700;
    color: #2e7d32;
}
@keyframes pf-dot-down { 0%{top:-8px;} 100%{top:100%;} }
@keyframes pf-dot-up { 0%{top:100%;} 100%{top:-8px;} }
@keyframes pf-dot-right { 0%{left:-8px;} 100%{left:100%;} }
@keyframes pf-dot-left { 0%{left:100%;} 100%{left:-8px;} }
.pf-inverter-circle {
    width: 44px;
    height: 44px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.2);
    color: #555555;
    flex-shrink: 0;
}
.pf-grid-node {
    position: relative;
}

.pf-grid-inverter-stack {
    position: absolute;
    top: 100%;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
}

.pf-grid-inverter-badge {
    position: static;
    transform: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    min-width: 0;
    padding: 3px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(107, 114, 128, 0.35);
    box-shadow: 0 2px 6px rgba(55, 65, 81, 0.08);
    color: #6b7280;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    z-index: 1;
    margin-top: 2px;
}

.pf-grid-inverter-badge-icon {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.2);
    color: #555555;
    flex-shrink: 0;
}

.pf-grid-inverter-stream {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    margin-top: 4px;
}

.pf-grid-inverter-line {
    width: 3px;
    height: 18px;
    background: rgba(107, 114, 128, 0.7);
    border-radius: 999px;
}

.pf-grid-inverter-arrow {
    display: none;
    margin-top: -2px;
    font-size: 1.2rem;
    line-height: 1;
    color: rgba(107, 114, 128, 0.85);
    font-weight: 700;
}

.pf-grid-inverter-stream.active .pf-grid-inverter-arrow {
    display: inline-block;
}
.topbar-pill,
.topbar-button,
.topbar-link,
.topbar-lang,
.topbar-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 30px;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #d5dbe5;
    background: #f5f7fb;
    color: #2d3b4f;
    font-size: 0.8rem;
    line-height: 1.2;
    font-weight: 600;
    text-decoration: none;
    vertical-align: middle;
    box-sizing: border-box;
}
.topbar-link {
    color: #0f6d52;
    background: #edf9f4;
    border-color: #cfeadf;
}
.topbar-button {
    cursor: pointer;
    background: #f6f8fb;
}
.topbar-button.primary {
    background: #eaf3ff;
    border-color: #bdd8ff;
    color: #1157b8;
}
.topbar-button.danger {
    background: #fff1f0;
    border-color: #f7b5af;
    color: #b42318;
}
.topbar-text {
    background: #f7f9fc;
    color: #4b5563;
    font-weight: 500;
}
.topbar-lang {
    background: #f7f9fc;
    color: #4b5563;
    font-weight: 500;
    padding: 4px 8px;
}
.topbar-lang a {
    text-decoration: none;
    color: inherit;
    opacity: 0.8;
}
.topbar-lang a.active {
    color: #1f2937;
    font-weight: 700;
    opacity: 1;
}
.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.82rem;
    border: 1px solid transparent;
    white-space: wrap;
}
.opt-action-button,
.opt-reset-button {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin: 0;
    font: inherit;
}
.opt-action-button {
    background: #eaf3ff;
    border-color: #bdd8ff;
    color: #1157b8;
}
.opt-reset-button {
    background: #fff3e0;
    border-color: #ffb84d;
    color: #b86800;
    margin-left: 4px;
}
.status-executed {
    background: #e8f5e9;
    color: #1b5e20;
    border-color: #a5d6a7;
    border-radius: 4px;
}
.status-failed,
.status-queue_failed {
    background: #ffebee;
    color: #b71c1c;
    border-color: #ef9a9a;
    border-radius: 4px;
}
.status-retry_pending,
.status-processing,
.status-queued {
    background: #fff8e1;
    color: #e65100;
    border-color: #ffcc80;
    border-radius: 4px;
}
.status-skipped {
    background: #eceff1;
    color: #37474f;
    border-color: #b0bec5;
    border-radius: 4px;
}
.status-pending {
    background: #e3f2fd;
    color: #0d47a1;
    border-color: #90caf9;
    border-radius: 4px;
}
.opt-row-current {
    background: #e3f2fd !important;
    font-weight: 600;
}

.optimization-history-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    table-layout: auto;
}

.optimization-history-table .opt-col {
    vertical-align: top;
    word-break: break-word;
}

@media (max-width: 720px) {
    .optimization-history-table {
        font-size: 0.75rem;
        table-layout: fixed;
    }

    .optimization-history-table .opt-col-id,
    .optimization-history-table .opt-col-power,
    .optimization-history-table .opt-col-battery,
    .optimization-history-table .opt-col-consumption,
    .optimization-history-table .opt-col-executed,
    .optimization-history-table .opt-col-executed-at,
    .optimization-history-table .opt-col-attempts,
    .optimization-history-table .opt-col-updated,
    .optimization-history-table .opt-col-error {
        display: none;
    }

    .optimization-history-table .opt-col-time {
        width: 23%;
    }

    .optimization-history-table .opt-col-action {
        width: 22%;
    }

    .optimization-history-table .opt-col-price {
        width: 17%;
    }

    .optimization-history-table .opt-col-savings {
        width: 18%;
    }

    .optimization-history-table .opt-col-status {
        width: 20%;
    }

    .optimization-history-table .opt-col-time,
    .optimization-history-table .opt-col-action,
    .optimization-history-table .opt-col-price,
    .optimization-history-table .opt-col-savings,
    .optimization-history-table .opt-col-status {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .optimization-history-table .opt-col-time {
        line-height: 1.45;
    }
}

.status-box {
    border-radius: 8px;
    border: 1px solid #dfe5eb;
    background: #f4fbf8;
    color: #081525;
    padding: 10px 14px;
    font-size: 0.85rem;
    line-height: 1.5;
    margin-top: 20px;
}
.status-box.error {
    background: #fff1f2;
    border-color: #f0ccd0;
}
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 21, 37, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.auth-overlay.hidden {
    display: none;
}
/* Keep the dashboard markup out of view until auth is confirmed, so no
   authenticated-looking content is ever visible behind the login card.
   !important is required because several dashboard children carry their
   own inline display style, which otherwise wins over this rule. */
body:not(.authenticated) .container > :not(#authOverlay) {
    display: none !important;
}
.auth-card {
    width: 100%;
    max-width: 442px;
    background: #fff;
    border-radius: 10px;
    padding: 22px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.auth-card h2 {
    margin: 0 0 4px;
    font-size: 1.5rem;
}
.auth-card p {
    margin: 0 0 14px;
    font-size: 1rem;
    color: #56606a;
}
.auth-card label {
    display: block;
    margin: 10px 0 4px;
    font-size: 1.2rem;
    font-weight: 600;
}
.auth-card input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #bfc9d4;
    border-radius: 6px;
    font-size: 1.2rem;
}
.auth-card input.field-error {
    border-color: #c94848;
    box-shadow: 0 0 0 3px rgba(201, 72, 72, 0.12);
    background: #fff7f7;
}
.auth-card .password-input-wrap {
    position: relative;
}
.auth-card .password-input-wrap input {
    padding-right: 62px;
}
.auth-card .password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: #0f6d52;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    width: auto;
    margin: 0;
}
.auth-card .captcha-question {
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px dashed #95a4b3;
    border-radius: 6px;
    background: #f9fbfc;
    font-size: 1.2rem;
}
.auth-card button {
    margin-top: 14px;
    width: 100%;
    border: 0;
    border-radius: 6px;
    padding: 12px 10px;
    background: #0f6d52;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
}
.auth-card .auth-error {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #ffe8e8;
    border: 1px solid #f3b6b6;
    color: #a02626;
    font-size: 0.9rem;
    display: none;
}

.monitor-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.topbar-logo {
    height: 26px;
    width: auto;
    flex-shrink: 0;
}

.monitor-topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    white-space: nowrap;
}

.dashboard-layout {
    display: flex;
    gap: 16px;
    align-items: stretch;
}

.dashboard-power-flow-card {
    flex: 0 0 340px !important;
    height: auto !important;
    min-height: 600px !important;
}

.chart-shell {
    flex: 1;
    min-width: 0;
}

@media (max-width: 1024px) {
    .container {
        padding: 14px;
    }

    .monitor-topbar {
        flex-wrap: wrap;
        overflow: visible;
    }

    .monitor-topbar-actions {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .dashboard-layout {
        flex-direction: column;
    }

    .dashboard-power-flow-card {
        width: 100% !important;
        flex-basis: auto !important;
        min-height: 0 !important;
    }

    canvas {
        height: 420px !important;
        min-height: 420px;
    }
}

@media (max-width: 720px) {
    .container {
        padding: 12px;
    }

    .monitor-topbar {
        gap: 8px;
    }

    .monitor-topbar-actions {
        gap: 8px;
        justify-content: flex-start;
    }

    #stationSelector,
    #inverterSelector {
        min-width: 0 !important;
        width: 100% !important;
    }

    .topbar-text,
    .topbar-lang,
    .topbar-button,
    .topbar-link,
    .topbar-pill {
        width: auto;
        min-width: 0;
    }

    .power-flow-card {
        padding: 16px 10px;
    }

    .pf-node .pf-value {
        font-size: 0.98rem;
    }

    .pf-node .pf-label {
        font-size: 0.72rem;
    }

    canvas {
        height: 300px !important;
        min-height: 300px;
    }
}

@media (max-width: 520px) {
    .monitor-topbar-actions {
        align-items: stretch;
    }

    .topbar-text,
    .topbar-lang,
    .topbar-button,
    .topbar-link,
    .topbar-pill {
        flex: 1 1 auto;
        justify-content: center;
    }

    .topbar-lang {
        width: auto;
    }

    .power-flow-card {
        gap: 6px;
    }

    .pf-node .pf-icon {
        font-size: 1.3em;
    }

    .pf-node .pf-value {
        font-size: 0.9rem;
        padding: 2px 8px;
    }

    .pf-sub,
    .pf-node .pf-sub {
        font-size: 0.7rem;
    }

    .chart-shell > div {
        gap: 4px;
    }
}
