﻿:root {
    --bg: #0b1220;
    --surf: #131c2e;
    --surf2: #1b2740;
    --line: #24314d;
    --txt: #e9eef8;
    --mut: #8a97b1;
    --pri: #4f8cff;
    --pri2: #7aa9ff;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #ef4444;
    --r: 18px;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: Vazirmatn, Tahoma, sans-serif;
    background: var(--bg);
    color: var(--txt);
    font-size: 14px;
    overflow: hidden;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ---------- Layout ---------- */
.app {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 520px;
    margin: auto;
    position: relative;
}

.top {
    padding: calc(env(safe-area-inset-top) + 14px) 16px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

    .top .logo {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        background: linear-gradient(135deg, var(--pri), #8b5cf6);
        display: grid;
        place-items: center;
        font-size: 18px;
        box-shadow: var(--shadow);
        flex: none;
    }

    .top .title {
        flex: 1;
        min-width: 0;
        cursor: pointer;
    }

        .top .title b {
            display: block;
            font-size: 16px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .top .title small {
            color: var(--mut);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            display: block;
            direction: ltr;
            text-align: right;
        }

.pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 99px;
    background: var(--surf);
    border: 1px solid var(--line);
    font-size: 12px;
    color: var(--mut);
    cursor: pointer;
    white-space: nowrap;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bad);
    box-shadow: 0 0 0 3px #ef444422;
}

    .dot.on {
        background: var(--ok);
        box-shadow: 0 0 0 3px #22c55e22;
    }

main {
    flex: 1;
    overflow-y: auto;
    padding: 4px 16px 110px;
    scroll-behavior: smooth;
}

.tab {
    display: none;
    animation: fade .25s ease;
}

    .tab.act {
        display: block;
    }

@keyframes fade {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

h2 {
    font-size: 17px;
    margin: 14px 2px 10px;
}

.card {
    background: var(--surf);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 14px;
    margin-bottom: 12px;
}

    .card h3 {
        margin: 0 0 12px;
        font-size: 14px;
        color: var(--pri2);
        display: flex;
        align-items: center;
        gap: 6px;
    }

/* ---------- Map ---------- */
#map {
    height: 300px;
    border-radius: var(--r);
    overflow: hidden;
    border: 1px solid var(--line);
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 12px;
}

.stat {
    background: var(--surf2);
    border-radius: 14px;
    padding: 12px;
}

    .stat small {
        color: var(--mut);
        display: block;
        margin-bottom: 4px;
    }

    .stat b {
        font-size: 16px;
        direction: ltr;
        display: inline-block;
    }

    .stat.big b {
        font-size: 22px;
    }

.fab {
    position: absolute;
    left: 16px;
    bottom: 100px;
    z-index: 500;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 0;
    background: var(--pri);
    color: #fff;
    font-size: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.leaflet-container {
    background: #0e1628;
}

.leaflet-control-attribution {
    font-size: 9px !important;
    background: #0008 !important;
    color: #ccc !important;
}

    .leaflet-control-attribution a {
        color: #9cf !important;
    }

.leaflet-bar a {
    background: var(--surf) !important;
    color: var(--txt) !important;
    border-color: var(--line) !important;
}

/* ---------- Event list ---------- */
.ev {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

    .ev:last-child {
        border: 0;
    }

    .ev .ic {
        width: 36px;
        height: 36px;
        border-radius: 12px;
        background: var(--surf2);
        display: grid;
        place-items: center;
        flex: none;
    }

    .ev .tx {
        flex: 1;
        min-width: 0;
    }

        .ev .tx b {
            display: block;
            font-weight: 500;
        }

        .ev .tx small {
            color: var(--mut);
            direction: ltr;
            display: block;
            text-align: right;
        }

.empty {
    color: var(--mut);
    text-align: center;
    padding: 18px 0;
    font-size: 13px;
}

/* ---------- Toggle ---------- */
.sw-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

    .sw-row:last-child {
        border: 0;
    }

    .sw-row span {
        flex: 1;
    }

.tg {
    position: relative;
    width: 46px;
    height: 26px;
    flex: none;
}

    .tg input {
        opacity: 0;
        width: 0;
        height: 0;
        position: absolute;
    }

    .tg i {
        position: absolute;
        inset: 0;
        background: var(--line);
        border-radius: 99px;
        transition: .2s;
        cursor: pointer;
    }

        .tg i::after {
            content: "";
            position: absolute;
            width: 20px;
            height: 20px;
            right: 3px;
            top: 3px;
            background: #fff;
            border-radius: 50%;
            transition: .2s;
            box-shadow: 0 1px 3px #0005;
        }

    .tg input:checked + i {
        background: var(--pri);
    }

        .tg input:checked + i::after {
            transform: translateX(-20px);
        }

/* ---------- Form ---------- */
.f {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

    .f label {
        color: var(--mut);
        font-size: 12px;
    }

input, select, textarea {
    width: 100%;
    background: var(--surf2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    outline: none;
    transition: border .2s;
}

    input:focus, select:focus, textarea:focus {
        border-color: var(--pri);
    }

    textarea {
        resize: vertical;
    }

.ltr {
    direction: ltr;
    text-align: left;
}

.g2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.seg {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

    .seg button {
        padding: 9px 4px;
        border-radius: 12px;
        border: 1px solid var(--line);
        background: var(--surf2);
        color: var(--mut);
        cursor: pointer;
        font-size: 12px;
    }

        .seg button.act {
            background: var(--pri);
            border-color: var(--pri);
            color: #fff;
        }

.btn {
    border: 0;
    border-radius: 14px;
    padding: 12px 14px;
    cursor: pointer;
    background: var(--pri);
    color: #fff;
    font-weight: 500;
    transition: transform .08s, opacity .2s;
}

    .btn:active {
        transform: scale(.97);
    }

    .btn:disabled {
        opacity: .6;
        cursor: default;
    }

    .btn.full {
        width: 100%;
    }

    .btn.ghost {
        background: var(--surf2);
        color: var(--txt);
        border: 1px solid var(--line);
    }

    .btn.danger {
        background: var(--bad);
    }

    .btn.ok {
        background: var(--ok);
    }

    .btn.sm {
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 10px;
    }

.row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

    .row > * {
        flex: 1;
    }

/* ---------- Control tiles ---------- */
.tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.tile {
    background: var(--surf2);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 6px;
    text-align: center;
    cursor: pointer;
    transition: transform .08s;
}

    .tile:active {
        transform: scale(.96);
    }

    .tile .e {
        font-size: 24px;
        display: block;
        margin-bottom: 6px;
    }

    .tile small {
        font-size: 11.5px;
        color: var(--txt);
    }

    .tile.red {
        border-color: #ef444455;
        background: #ef44441a;
    }

    .tile.green {
        border-color: #22c55e55;
        background: #22c55e1a;
    }

/* ---------- Status ---------- */
.kv {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

    .kv div {
        background: var(--surf2);
        border-radius: 14px;
        padding: 10px 12px;
        min-width: 0;
    }

    .kv small {
        color: var(--mut);
        display: block;
        font-size: 11px;
        margin-bottom: 3px;
    }

    .kv b {
        font-weight: 500;
        direction: ltr;
        display: inline-block;
        overflow-wrap: anywhere;
    }

.ota-bar {
    height: 10px;
    border-radius: 99px;
    background: var(--surf2);
    overflow: hidden;
    margin: 8px 0;
}

    .ota-bar div {
        height: 100%;
        width: 0;
        background: linear-gradient(90deg, var(--pri), #8b5cf6);
        transition: width .4s;
    }

.log {
    height: 160px;
    overflow: auto;
    background: #060b16;
    border-radius: 14px;
    padding: 10px;
    font: 11px/1.6 monospace;
    direction: ltr;
    text-align: left;
    color: #7ee2a8;
}

    .log div {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

/* ---------- Bottom nav ---------- */
nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 520px;
    background: rgba(19, 28, 46, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-around;
    padding: 8px 6px calc(env(safe-area-inset-bottom) + 8px);
    z-index: 1000;
}

    nav a {
        flex: 1;
        background: none;
        border: 0;
        color: var(--mut);
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        font-size: 11px;
        padding: 4px 0;
        cursor: pointer;
        text-decoration: none;
    }

        nav a .i {
            font-size: 20px;
            transition: transform .2s;
        }

        nav a.active {
            color: var(--pri2);
        }

            nav a.active .i {
                transform: translateY(-2px) scale(1.1);
            }

/* ---------- Sheet / toast ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: #000a;
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 2000;
}

    .overlay.show {
        display: flex;
        animation: fade .2s;
    }

.sheet {
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surf);
    border-radius: 24px 24px 0 0;
    padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
    border-top: 1px solid var(--line);
    animation: up .25s ease;
}

@keyframes up {
    from {
        transform: translateY(40px);
        opacity: .4;
    }

    to {
        transform: none;
        opacity: 1;
    }
}

.sheet .grab {
    width: 40px;
    height: 4px;
    border-radius: 9px;
    background: var(--line);
    margin: -8px auto 14px;
}

.sheet h4 {
    margin: 0 0 6px;
    font-size: 16px;
}

.sheet p {
    margin: 0 0 16px;
    color: var(--mut);
    line-height: 1.8;
}

.sheet .row {
    gap: 10px;
}

.toast {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surf2);
    border: 1px solid var(--line);
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: var(--shadow);
    z-index: 3000;
    font-size: 13px;
    opacity: 0;
    transition: .25s;
    pointer-events: none;
    max-width: 90%;
}

    .toast.show {
        opacity: 1;
    }

.chip {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 99px;
    font-size: 11px;
    background: var(--surf2);
    color: var(--mut);
}

/* ---------- Device list ---------- */
.dev-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surf2);
    margin-bottom: 8px;
    cursor: pointer;
}

    .dev-item.act {
        border-color: var(--pri);
        background: #4f8cff1a;
    }

    .dev-item .dv-tx {
        flex: 1;
        min-width: 0;
    }

        .dev-item .dv-tx b {
            display: block;
            font-size: 13.5px;
            font-weight: 500;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .dev-item .dv-tx small {
            display: block;
            color: var(--mut);
            font-size: 11.5px;
            direction: ltr;
            text-align: right;
        }

.dev-del {
    flex: none;
    border: 1px solid #ef444455;
    background: #ef44441a;
    color: #ffb4b4;
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 11.5px;
    cursor: pointer;
}

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 18px calc(env(safe-area-inset-bottom) + 24px);
    overflow-y: auto;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surf);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 26px 20px;
    box-shadow: var(--shadow);
}

.login-logo {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--pri), #8b5cf6);
    display: grid;
    place-items: center;
    font-size: 26px;
    margin: 0 auto 12px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0;
    font-size: 20px;
    text-align: center;
}

.login-card .sub {
    margin: 4px 0 20px;
    color: var(--mut);
    font-size: 12.5px;
    text-align: center;
}

.login-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: var(--surf2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 5px;
    margin-bottom: 16px;
}

    .login-tabs button {
        border: 0;
        background: none;
        color: var(--mut);
        padding: 9px 0;
        border-radius: 10px;
        cursor: pointer;
        font-size: 13px;
    }

        .login-tabs button.act {
            background: var(--pri);
            color: #fff;
        }

.login-error {
    background: #ef44441a;
    border: 1px solid #ef444455;
    color: #ffb4b4;
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 12.5px;
    margin-bottom: 12px;
}

.login-hint {
    margin-top: 14px;
    text-align: center;
    color: var(--mut);
    font-size: 11.5px;
}

    .login-hint code {
        background: var(--surf2);
        border-radius: 6px;
        padding: 1px 5px;
        direction: ltr;
        display: inline-block;
        color: var(--txt);
    }

.auth-loading {
    height: 100%;
    display: grid;
    place-items: center;
    color: var(--mut);
    font-size: 13px;
}

/* ---------- Blazor boot / error ---------- */
.loading-progress {
    position: relative;
    display: block;
    width: 6rem;
    height: 6rem;
    margin: 30vh auto 1rem auto;
}

    .loading-progress circle {
        fill: none;
        stroke: var(--line);
        stroke-width: 0.5rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: var(--pri);
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    inset: calc(30vh + 2.6rem) 0 auto 0;
    color: var(--mut);
    font-size: 13px;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "در حال بارگذاری…");
    }

#blazor-error-ui {
    color-scheme: dark;
    background: #7f1d1d;
    color: #fff;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .4);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 4000;
    font-size: 13px;
}

    #blazor-error-ui .reload {
        color: #fff;
        text-decoration: underline;
    }

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        left: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: #ef44441a;
    border: 1px solid #ef444455;
    border-radius: var(--r);
    padding: 1rem 1rem 1rem 3.2rem;
    color: #ffb4b4;
    position: relative;
}

    .blazor-error-boundary::before {
        content: "⚠";
        position: absolute;
        left: 1rem;
        top: 1rem;
        font-size: 1.4rem;
    }

    .blazor-error-boundary::after {
        content: "خطایی رخ داده است.";
    }

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--ok);
}

.invalid {
    outline: 1px solid var(--bad);
}

.validation-message {
    color: var(--bad);
    font-size: 12px;
}
