/* Same colours as SingleLine.Mobile/DiagramPage.cs and the Windows toolbar */

:root {
    --bar: #1A365D;
    --tab-active: #2C4A73;
    --stage: #FFFFFF;
    --focus: #93C5FD;
    color-scheme: light;
}

.app.dark {
    --bar: #0B1220;
    --tab-active: #22324D;
    --stage: #0D1117;
    color-scheme: dark;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: #1A365D;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font: 14px/1.4 "Segoe UI", system-ui, -apple-system, "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
    color: #FFFFFF;
}

#app {
    height: 100%;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bar);
}

/* ------------------------------------------------------------------ toolbar */

.bar {
    background: var(--bar);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
    user-select: none;
    -webkit-user-select: none;
}

.row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
}

.top {
    justify-content: space-between;
}

.tabs {
    display: flex;
    gap: 6px;
    min-width: 0;
}

.tab {
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: #B9C6DC;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 0 12px;
    min-height: 40px;
    cursor: pointer;
    white-space: nowrap;
}

    .tab:hover:not(.active) {
        background: rgba(255, 255, 255, 0.08);
    }

    .tab.active {
        background: var(--tab-active);
        color: #FFFFFF;
    }

.actions {
    padding-top: 0;
    padding-bottom: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

    .actions::-webkit-scrollbar {
        display: none;
    }

.btn {
    flex: none;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: #FFFFFF;
    background: #334155;
    border: 0;
    border-radius: 8px;
    padding: 0 12px;
    min-width: 44px;
    min-height: 40px;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.12s, transform 0.06s;
}

    .btn:hover:not(:disabled) {
        filter: brightness(1.12);
    }

    .btn:active:not(:disabled) {
        transform: scale(0.97);
    }

    .btn:disabled {
        opacity: 0.5;
        cursor: default;
    }

    .btn.icon {
        width: 44px;
        padding: 0;
        font-size: 18px;
    }

    .btn.mea { background: #DC143C; }
    .btn.gen { background: #D97706; }
    .btn.close { background: #059669; }
    .btn.reset { background: #3B82F6; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* switch: "บังคับจ่ายไฟเข้า" */
.toggle {
    flex: none;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 6px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

    .toggle input {
        position: absolute;
        opacity: 0;
        width: 1px;
        height: 1px;
    }

.track {
    position: relative;
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: #475569;
    transition: background 0.15s;
}

    .track::after {
        content: "";
        position: absolute;
        top: 3px;
        left: 3px;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: #FFFFFF;
        transition: transform 0.15s;
    }

.toggle input:checked + .track {
    background: #2DD4BF;
}

    .toggle input:checked + .track::after {
        transform: translateX(18px);
    }

.toggle input:focus-visible + .track {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.status {
    padding: 2px 10px 6px;
    font-size: 12px;
    color: #93C5FD;
}

.message {
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 700;
    color: #FFFFFF;
}

    .message.interlock { background: #7C3AED; }
    .message.fault { background: #B91C1C; }

/* ------------------------------------------------------------------ diagram */

.stage {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--stage);
}

    .stage canvas {
        position: absolute;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        touch-action: none;
        cursor: grab;
    }

        .stage canvas:active {
            cursor: grabbing;
        }

.loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    text-align: center;
    font-weight: 600;
    color: #64748B;
    pointer-events: none;
}

/* ------------------------------------------------------------------ boot screen (before .NET starts) */

.boot {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: #061A33;
    color: #E2E8F0;
}

    .boot img {
        border-radius: 22px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    }

.boot-title {
    font-size: 18px;
    font-weight: 700;
}

.boot-progress {
    width: 160px;
    height: 4px;
    overflow: hidden;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
}

    .boot-progress span {
        display: block;
        height: 100%;
        width: var(--blazor-load-percentage, 0%);
        background: #2DD4BF;
        transition: width 0.1s;
    }

.boot-text::after {
    content: var(--blazor-load-percentage-text, "กำลังโหลด");
    font-size: 12px;
    color: #94A3B8;
}

#blazor-error-ui {
    color-scheme: light only;
    display: none;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 1000;
    width: 100%;
    padding: 0.6rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom));
    background: lightyellow;
    color: #111827;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
}

    #blazor-error-ui .dismiss {
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
        cursor: pointer;
    }

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