:root {
    --bg: #f3f7ff;
    --panel: rgba(255,255,255,.82);
    --panel-solid: #fff;
    --text: #14233d;
    --muted: #70809b;
    --line: rgba(39, 93, 171, .13);
    --blue: #3477f6;
    --blue-2: #69a8ff;
    --shadow: 0 18px 55px rgba(51, 92, 150, .12);
    --ok-bg: #eaf9f0;
    --ok: #16824b;
    --bad-bg: #ffefef;
    --bad: #c74444;
    --warn-bg: #fff5dd;
    --warn: #ad7413;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at 85% 8%, rgba(105,168,255,.24), transparent 28%),
        radial-gradient(circle at 8% 88%, rgba(52,119,246,.12), transparent 26%),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body:before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255,255,255,.25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.25) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,.35), transparent 70%);
}

a { color: inherit; text-decoration: none; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 244px;
    position: fixed;
    inset: 0 auto 0 0;
    padding: 28px 20px;
    background: rgba(255,255,255,.72);
    backdrop-filter: blur(22px);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 0 8px 20px;
}

.brand-cloud {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: white;
    font-size: 25px;
    background: linear-gradient(145deg, var(--blue-2), var(--blue));
    box-shadow: 0 9px 24px rgba(52,119,246,.28);
}

.brand strong {
    display: block;
    letter-spacing: .08em;
    font-size: 17px;
}
.brand small { color: var(--muted); }

.readonly {
    margin: 4px 8px 22px;
    padding: 7px 9px;
    text-align: center;
    border-radius: 9px;
    color: #3267be;
    background: #eaf2ff;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .16em;
}

nav { display: grid; gap: 7px; }

nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 13px;
    border-radius: 12px;
    color: #506079;
    font-size: 14px;
    font-weight: 650;
}

nav a span {
    width: 24px;
    text-align: center;
    color: #7a91b4;
}

nav a:hover, nav a.active {
    color: var(--blue);
    background: #edf4ff;
}

nav a.active {
    box-shadow: inset 3px 0 0 var(--blue);
}

.side-footer {
    margin-top: auto;
    padding: 15px 8px 0;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

.main {
    margin-left: 244px;
    width: calc(100% - 244px);
    padding: 34px 38px 60px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 27px;
}

.eyebrow {
    color: var(--blue);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .18em;
    margin-bottom: 5px;
}

h1 { margin: 0; font-size: 29px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    background: rgba(255,255,255,.7);
    border: 1px solid var(--line);
    padding: 9px 12px;
    border-radius: 999px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #24b76d;
    box-shadow: 0 0 0 4px rgba(36,183,109,.12);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 15px;
    margin-bottom: 16px;
}

.stat-card, .panel {
    background: var(--panel);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255,255,255,.8);
    box-shadow: var(--shadow);
}

.stat-card {
    border-radius: 19px;
    padding: 20px;
    min-height: 130px;
    display: flex;
    flex-direction: column;
}

.stat-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.stat-card strong {
    margin-top: 12px;
    font-size: 34px;
    line-height: 1;
    letter-spacing: -.04em;
}

.stat-card small {
    margin-top: auto;
    color: #8d99ad;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.panel {
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    overflow: hidden;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-head p, .detail-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.kv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.kv-grid > div {
    background: #f7faff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
}
.kv-grid span { display: block; color: var(--muted); font-size: 11px; }
.kv-grid strong { display: block; margin-top: 5px; font-size: 20px; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eef2f7;
    color: #65738a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .03em;
    white-space: nowrap;
}
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.neutral { color: #5f6f86; background: #edf2f8; }

.ghost-link {
    color: var(--blue);
    font-size: 12px;
    font-weight: 750;
}

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
th {
    text-align: left;
    color: #8290a5;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 10px 10px;
    border-bottom: 1px solid var(--line);
}
td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(39,93,171,.08);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(238,245,255,.65); }

td small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}
.strong-link { color: #244a83; font-weight: 750; }

code {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 11px;
    color: #446281;
    background: #f0f5fb;
    padding: 3px 6px;
    border-radius: 7px;
}

.empty {
    padding: 22px;
    border-radius: 14px;
    background: #f7faff;
    border: 1px dashed var(--line);
    color: var(--muted);
    text-align: center;
    font-size: 12px;
}
.empty.compact { padding: 12px; }

.toolbar {
    display: flex;
    gap: 9px;
    align-items: center;
    margin-bottom: 18px;
}
input, select, button, .button-secondary {
    min-height: 40px;
    border-radius: 11px;
    border: 1px solid var(--line);
    font: inherit;
}
input, select {
    background: #fff;
    color: var(--text);
    padding: 0 12px;
}
input { flex: 1; min-width: 180px; }
button, .button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    cursor: pointer;
    font-weight: 750;
    font-size: 12px;
}
button {
    color: white;
    border-color: transparent;
    background: linear-gradient(135deg, var(--blue-2), var(--blue));
}
.button-secondary {
    color: var(--blue);
    background: #eef5ff;
}

.detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding: 18px 20px;
    border-radius: 20px;
    background: var(--panel);
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,.8);
}
.detail-head.inline {
    box-shadow: none;
    border: 0;
    background: transparent;
    padding: 0;
}
.detail-head > div {
    display: flex;
    align-items: center;
    gap: 12px;
}
.detail-head h2 { font-size: 18px; }
.avatar {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: white;
    background: linear-gradient(145deg, var(--blue-2), var(--blue));
    font-weight: 900;
}

.detail-list {
    display: grid;
    gap: 0;
}
.detail-list > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 11px 0;
    border-bottom: 1px solid rgba(39,93,171,.08);
}
.detail-list > div:last-child { border-bottom: 0; }
.detail-list span { color: var(--muted); font-size: 12px; }
.detail-list strong { font-size: 12px; text-align: right; }

.device-summary {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-bottom: 11px;
}
.device-summary strong { font-size: 29px; }
.device-summary span { color: var(--muted); }

.device-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid rgba(39,93,171,.08);
}
.device-row:last-child { border-bottom: 0; }
.device-row strong, .device-row small { display: block; }
.device-row small, .device-row > span { color: var(--muted); font-size: 11px; }

.devices-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 12px;
}
.device-card {
    display: flex;
    gap: 12px;
    padding: 15px;
    border-radius: 15px;
    background: #f7faff;
    border: 1px solid var(--line);
}
.device-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: var(--blue);
    background: #e9f2ff;
}
.device-card strong, .device-card span, .device-card small, .device-card code {
    display: block;
}
.device-card span { margin-top: 3px; color: #58708f; font-size: 12px; }
.device-card small { margin: 7px 0; color: var(--muted); }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2,1fr); }
    .devices-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 760px) {
    .sidebar {
        position: static;
        width: 100%;
        min-height: auto;
    }
    .shell { display: block; }
    .side-footer { display: none; }
    nav {
        grid-template-columns: repeat(2,1fr);
    }
    .main {
        margin-left: 0;
        width: 100%;
        padding: 24px 15px 45px;
    }
    .grid-2, .stats-grid, .devices-grid {
        grid-template-columns: 1fr;
    }
    .topbar { align-items: flex-start; gap: 15px; }
    .top-actions { display: none; }
    .toolbar { flex-wrap: wrap; }
    input { width: 100%; flex-basis: 100%; }
}


.top-actions-wrap {
    display: flex;
    align-items: center;
    gap: 9px;
}

.logout-button {
    min-height: 36px;
    padding: 0 12px;
    color: #5b6b83;
    background: rgba(255,255,255,.72);
    border: 1px solid var(--line);
}

.logout-button:hover {
    color: var(--blue);
    background: #fff;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
}

.login-shell {
    width: 100%;
    max-width: 430px;
}

.login-card {
    padding: 30px;
    border-radius: 26px;
    background: rgba(255,255,255,.82);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(255,255,255,.92);
    box-shadow: 0 28px 90px rgba(40,86,148,.18);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 38px;
}

.login-brand strong {
    display: block;
    font-size: 17px;
    letter-spacing: .08em;
}

.login-brand small {
    color: var(--muted);
}

.login-copy h1 {
    margin-top: 0;
    font-size: 30px;
}

.login-copy p {
    margin: 9px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.login-form {
    display: grid;
    gap: 15px;
    margin-top: 27px;
}

.login-form label {
    display: grid;
    gap: 7px;
}

.login-form label > span {
    color: #53657f;
    font-size: 12px;
    font-weight: 750;
}

.login-form input {
    width: 100%;
    min-height: 46px;
}

.login-form button {
    min-height: 46px;
    margin-top: 4px;
}

.login-error {
    margin-top: 19px;
    padding: 12px 14px;
    border-radius: 12px;
    color: var(--bad);
    background: var(--bad-bg);
    font-size: 12px;
    font-weight: 700;
}

.login-note {
    margin-top: 22px;
    color: #91a0b5;
    text-align: center;
    font-size: 11px;
}

@media (max-width: 760px) {
    .top-actions-wrap {
        display: none;
    }
}


.readonly.manage-mode {
    color: #127847;
    background: #e9f9f0;
}

.flash {
    margin: -8px 0 16px;
    padding: 12px 15px;
    border-radius: 13px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid transparent;
}
.flash-ok {
    color: var(--ok);
    background: var(--ok-bg);
    border-color: rgba(22,130,75,.12);
}
.flash-error {
    color: var(--bad);
    background: var(--bad-bg);
    border-color: rgba(199,68,68,.12);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
}
.form-grid > label {
    display: grid;
    gap: 7px;
}
.form-grid > label > span,
.control-label {
    color: #53657f;
    font-size: 11px;
    font-weight: 800;
}
.form-grid input,
.form-grid select {
    width: 100%;
    min-height: 43px;
}
.form-grid small,
.tariff-box small {
    color: var(--muted);
    font-size: 10px;
}
.tariff-box {
    grid-column: span 2;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    background: #f8fbff;
}
.tariff-box legend {
    color: #53657f;
    font-size: 11px;
    font-weight: 800;
    padding: 0 5px;
}
.tariff-box .check {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 3px 14px 5px 0;
    font-size: 12px;
}
.tariff-box input[type="checkbox"] {
    width: auto;
    min-height: auto;
}
.form-actions {
    display: flex;
    align-items: end;
    height: 100%;
}
.form-actions button {
    min-height: 43px;
    width: 100%;
}

.row-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.row-actions form { margin: 0; }

.mini-button {
    min-height: 30px;
    border-radius: 9px;
    padding: 0 9px;
    font-size: 10px;
    white-space: nowrap;
}
.mini-button.secondary {
    color: var(--blue);
    background: #eef5ff;
    border: 1px solid rgba(52,119,246,.15);
}
.mini-button.danger,
.danger-button {
    color: #b63a3a;
    background: #fff0f0;
    border: 1px solid rgba(182,58,58,.15);
}

.hwid-controls {
    display: grid;
    gap: 12px;
}
.inline-control {
    display: flex;
    align-items: end;
    gap: 10px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f8fbff;
}
.inline-control label,
.inline-control > div {
    display: grid;
    gap: 5px;
    flex: 1;
}
.inline-control input[type="number"] {
    width: 120px;
}
.inline-control strong {
    font-size: 16px;
}
.inline-control small {
    color: var(--muted);
    font-size: 10px;
}

.device-card.managed .device-body {
    min-width: 0;
    flex: 1;
}
.device-card.managed form {
    margin-top: 11px;
}
.managed-row .device-row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}
.device-summary form {
    margin-left: auto;
}

@media (max-width: 900px) {
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
    .tariff-box {
        grid-column: 1 / -1;
    }
}
@media (max-width: 620px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .tariff-box {
        grid-column: auto;
    }
    .inline-control {
        align-items: stretch;
        flex-direction: column;
    }
    .inline-control input[type="number"] {
        width: 100%;
    }
}
