:root {
    color-scheme: dark;

    --bg: #0b0e12;
    --bg-soft: #0f1318;
    --panel: #141920;
    --panel-soft: #191f27;
    --panel-hover: #1c232c;
    --border: #28313c;
    --border-soft: #222a34;

    --text: #f1f4f8;
    --muted: #8f99a7;
    --muted-2: #697483;

    --accent: #5d83ff;
    --accent-hover: #7092ff;
    --accent-soft: rgba(93, 131, 255, .13);

    --success: #54d18a;
    --success-soft: rgba(84, 209, 138, .12);

    --warning: #e5ad55;
    --warning-soft: rgba(229, 173, 85, .12);

    --danger: #ef6a6a;
    --danger-hover: #fa7b7b;
    --danger-soft: rgba(239, 106, 106, .11);

    --shadow: 0 18px 55px rgba(0, 0, 0, .24);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 15% -15%, rgba(93, 131, 255, .10), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 64px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 6px;
    font-size: clamp(28px, 4vw, 38px);
    line-height: 1.08;
    letter-spacing: -.035em;
}

h2 {
    margin-bottom: 6px;
    font-size: 20px;
    letter-spacing: -.02em;
}

h3 {
    margin-bottom: 4px;
    font-size: 16px;
}

.muted {
    color: var(--muted);
}

.small-note,
.small-copy {
    font-size: 13px;
}

.eyebrow {
    margin-bottom: 8px;
    color: var(--accent-hover);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .18em;
}

.card {
    margin-bottom: 18px;
    padding: 22px;
    background: rgba(20, 25, 32, .95);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 1px 0 rgba(255,255,255,.015);
}

.card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}

.card-heading.compact {
    margin-bottom: 18px;
}

.card-heading p {
    margin-bottom: 0;
}

.topbar,
.user-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 28px;
}

.topbar p,
.user-topbar p {
    margin-bottom: 0;
}

.back {
    display: inline-block;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
    transition: color .18s ease;
}

.back:hover {
    color: var(--text);
}

.field {
    min-width: 0;
}

label {
    display: block;
    margin-bottom: 7px;
    color: #cbd2dc;
    font-size: 13px;
    font-weight: 650;
}

input,
textarea {
    width: 100%;
    margin: 0;
    padding: 11px 12px;
    color: var(--text);
    background: #10151b;
    border: 1px solid #303945;
    border-radius: 10px;
    outline: none;
    transition:
        border-color .18s ease,
        box-shadow .18s ease,
        background .18s ease;
}

input::placeholder,
textarea::placeholder {
    color: #626d7c;
}

input:hover,
textarea:hover {
    border-color: #3a4552;
}

input:focus,
textarea:focus {
    background: #11171e;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
    color: var(--muted);
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 8px 11px;
    color: var(--text);
    background: #222a34;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

textarea {
    min-height: 120px;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-all;
}

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 15px;
    color: var(--text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 650;
    text-decoration: none;
    transition:
        background .18s ease,
        border-color .18s ease,
        color .18s ease,
        transform .08s ease,
        opacity .18s ease;
}

.button:active {
    transform: translateY(1px);
}

.button:disabled {
    cursor: default;
    opacity: .82;
}

.button.primary {
    color: white;
    background: var(--accent);
}

.button.primary:hover {
    background: var(--accent-hover);
}

.button.secondary {
    background: #202731;
    border-color: #303945;
}

.button.secondary:hover {
    background: #29323e;
    border-color: #3a4654;
}

.button.tertiary {
    background: transparent;
    border-color: #303945;
}

.button.tertiary:hover {
    background: #202731;
}

.button.warning {
    color: #ffd99a;
    background: var(--warning-soft);
    border-color: rgba(229, 173, 85, .28);
}

.button.warning:hover {
    background: rgba(229, 173, 85, .18);
}

.button.danger {
    color: #fff;
    background: #ba4545;
}

.button.danger:hover {
    background: #cb5353;
}

.button.ghost-danger {
    color: #ff8989;
    background: transparent;
    border-color: rgba(239, 106, 106, .27);
}

.button.ghost-danger:hover {
    background: var(--danger-soft);
    border-color: rgba(239, 106, 106, .42);
}

.button.full {
    width: 100%;
}

.small-button {
    margin-top: 10px;
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    min-height: 26px;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge.enabled {
    color: #83e3aa;
    background: var(--success-soft);
    border: 1px solid rgba(84, 209, 138, .20);
}

.badge.disabled {
    color: #d29090;
    background: rgba(239, 106, 106, .08);
    border: 1px solid rgba(239, 106, 106, .15);
}

.badge.neutral {
    color: #b4bdc9;
    background: #202731;
    border: 1px solid #303945;
}

.message {
    margin-bottom: 18px;
    padding: 12px 15px;
    border: 1px solid transparent;
    border-radius: 11px;
    font-size: 14px;
}

.message.success {
    color: #91e8b5;
    background: var(--success-soft);
    border-color: rgba(84, 209, 138, .22);
}

.message.error {
    color: #ff9999;
    background: var(--danger-soft);
    border-color: rgba(239, 106, 106, .23);
}

/* Login */

.login-wrap {
    min-height: calc(100vh - 98px);
    display: grid;
    place-items: center;
}

.login-panel {
    width: min(410px, 100%);
    padding: 32px;
    background: rgba(20, 25, 32, .96);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    margin-bottom: 22px;
    color: #fff;
    background: var(--accent);
    border-radius: 12px;
    font-size: 18px;
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(93, 131, 255, .20);
}

.login-heading {
    margin-bottom: 24px;
}

.login-heading h1 {
    font-size: 30px;
}

.login-heading p {
    margin-bottom: 0;
    color: var(--muted);
}

.login-panel .field {
    margin-bottom: 16px;
}

.login-button {
    margin-top: 5px;
}

/* Admin main */

.grid-form {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.form-button {
    display: flex;
    align-items: end;
}

.installer-admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.installer-admin-item {
    padding: 17px;
    background: var(--panel-soft);
    border: 1px solid var(--border-soft);
    border-radius: 13px;
}

.installer-admin-top,
.section-title,
.download-title,
.device-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.installer-admin-top {
    margin-bottom: 14px;
}

.installer-admin-top h3,
.section-title h2,
.section-title h3,
.download-title strong,
.device-title h3 {
    margin-bottom: 2px;
}

.upload-form {
    display: grid;
    gap: 10px;
    margin-bottom: 9px;
}

.platform-badge {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: #dce4ff;
    background: #242d3a;
    border: 1px solid #344155;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 800;
}

.platform-badge.large {
    width: 40px;
    height: 40px;
    border-radius: 11px;
}

.status-text {
    margin: 0;
    font-size: 12px;
}

.success-text {
    color: #7edda7;
}

.users {
    display: flex;
    flex-direction: column;
}

.user-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 130px minmax(320px, auto) 126px;
    gap: 14px;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-soft);
}

.user-row:first-child {
    padding-top: 2px;
}

.user-row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.user-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.user-main strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.config-status {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.status-chip {
    display: inline-flex;
    padding: 5px 8px;
    color: #6f7a88;
    background: #171c22;
    border: 1px solid #252d37;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 700;
}

.status-chip.active {
    color: #94aaff;
    background: var(--accent-soft);
    border-color: rgba(93, 131, 255, .24);
}

.user-action {
    display: flex;
    justify-content: flex-end;
}

/* Admin user */

.admin-user-layout {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.left-column,
.right-column {
    min-width: 0;
}

.right-column {
    display: flex;
    flex-direction: column;
}

.settings-card {
    position: sticky;
    top: 18px;
}

.settings-card .field {
    margin-bottom: 12px;
}

.settings-divider {
    height: 1px;
    margin: 20px 0;
    background: var(--border-soft);
}

.delete-user-form {
    margin-top: 9px;
}

.section-card {
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 13px;
}

.section-header.no-margin {
    margin-bottom: 0;
}

.section-title {
    align-items: flex-start;
}

.section-title p {
    margin-bottom: 0;
}

.section-icon {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: #aebeff;
    background: var(--accent-soft);
    border: 1px solid rgba(93, 131, 255, .20);
    border-radius: 10px;
}

.section-icon svg,
.device-icon svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.section-meta {
    margin-bottom: 13px;
}

.installer-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.installer-item {
    padding: 15px;
    background: var(--panel-soft);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
}

/* Details */

.collapse-box {
    overflow: hidden;
    background: #11161c;
    border: 1px solid var(--border);
    border-radius: 11px;
}

.collapse-box summary {
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 13px;
    cursor: pointer;
    list-style: none;
    color: #d7dce4;
    font-size: 13px;
    font-weight: 700;
    user-select: none;
}

.collapse-box summary::-webkit-details-marker {
    display: none;
}

.summary-hint {
    color: var(--muted-2);
    font-size: 11px;
    font-weight: 650;
}

.collapse-box[open] .summary-hint {
    color: var(--accent-hover);
}

.collapse-content {
    padding: 14px;
    border-top: 1px solid var(--border-soft);
}

.collapse-content textarea,
.collapse-content input {
    margin-bottom: 11px;
}

/* Switch */

.switch {
    position: relative;
    width: 48px;
    height: 28px;
    flex: 0 0 auto;
    display: inline-block;
    margin: 0;
}

.switch input {
    width: 0;
    height: 0;
    margin: 0;
    opacity: 0;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: #333b47;
    border: 1px solid #404a58;
    border-radius: 999px;
    transition: .18s ease;
}

.slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #b8c0ca;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,.25);
    transition: .18s ease;
}

.switch input:checked + .slider {
    background: #397054;
    border-color: #4b8a69;
}

.switch input:checked + .slider::before {
    background: #e8fff1;
    transform: translateX(20px);
}

/* User dashboard */

.user-dashboard {
    width: min(840px, 100%);
    margin: 0 auto;
}

.dashboard-section {
    margin-top: 30px;
}

.section-label {
    margin-bottom: 14px;
}

.section-label h2 {
    margin-bottom: 4px;
    font-size: 18px;
}

.section-label p {
    margin-bottom: 0;
    font-size: 13px;
}

.connection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 14px;
}

.connection-card {
    padding: 19px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.018), transparent),
        var(--panel);
    border: 1px solid var(--border);
    border-radius: 15px;
}

.connection-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.device-title {
    align-items: flex-start;
}

.device-title h3 {
    font-size: 17px;
}

.device-title p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.device-icon {
    width: 39px;
    height: 39px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: #b5c3ff;
    background: var(--accent-soft);
    border: 1px solid rgba(93, 131, 255, .22);
    border-radius: 11px;
}

.ready-pill,
.waiting-pill {
    min-height: 25px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.ready-pill {
    color: #83e3aa;
    background: var(--success-soft);
}

.ready-pill i {
    width: 6px;
    height: 6px;
    display: block;
    background: var(--success);
    border-radius: 50%;
}

.waiting-pill {
    color: #a0a8b4;
    background: #202731;
}

.connection-description {
    min-height: 38px;
    margin: 20px 0 15px;
    color: #bdc5d0;
    font-size: 13px;
    line-height: 1.5;
}

.copy-button.copied {
    background: #33714f;
}

.copy-button.copy-error {
    background: #a44343;
}

.download-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
    gap: 12px;
}

.download-card {
    min-width: 0;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.download-title {
    margin-bottom: 15px;
}

.download-title > div:last-child {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.download-title strong {
    font-size: 14px;
}

.download-title span {
    color: var(--muted);
    font-size: 11px;
}

.empty-state {
    padding: 42px 24px;
    text-align: center;
}

.empty-state h2 {
    margin-bottom: 8px;
}

.empty-state p {
    margin-bottom: 0;
}

.empty-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    margin: 0 auto 15px;
    color: var(--muted);
    background: #1c222a;
    border: 1px solid var(--border);
    border-radius: 12px;
}

/* Responsive */

@media (max-width: 1000px) {
    .user-row {
        grid-template-columns: 1fr 130px;
    }

    .config-status {
        grid-column: 1 / -1;
    }

    .admin-user-layout {
        grid-template-columns: 1fr;
    }

    .settings-card {
        position: static;
    }
}

@media (max-width: 760px) {
    .page {
        width: min(100% - 24px, 1180px);
        padding-top: 20px;
        padding-bottom: 40px;
    }

    .card {
        padding: 18px;
        border-radius: 14px;
    }

    .topbar,
    .user-topbar {
        align-items: flex-start;
    }

    .grid-form,
    .installer-admin-grid {
        grid-template-columns: 1fr;
    }

    .form-button .button {
        width: 100%;
    }

    .user-row {
        grid-template-columns: 1fr;
        gap: 9px;
    }

    .config-status {
        grid-column: auto;
    }

    .user-action {
        justify-content: flex-start;
    }

    .user-action .button {
        width: 100%;
    }

    .section-header {
        align-items: flex-start;
    }

    .connection-grid,
    .download-grid {
        grid-template-columns: 1fr;
    }

    .login-panel {
        padding: 24px;
    }
}

@media (max-width: 430px) {
    .page {
        width: min(100% - 20px, 1180px);
    }

    h1 {
        font-size: 29px;
    }

    .button {
        min-height: 42px;
    }

    .topbar,
    .user-topbar {
        gap: 12px;
    }

    .topbar > form .button,
    .user-topbar > form .button {
        padding-inline: 12px;
    }
}
