:root {
    color-scheme: dark;
    --bg: #09111f;
    --surface: #111c2e;
    --surface-soft: #16243a;
    --border: #293951;
    --text: #edf3fc;
    --muted: #9aabc1;
    --primary: #70a5ff;
    --primary-strong: #3b82f6;
    --success: #51d6a0;
    --danger: #ff7e8a;
    --warning: #f7c86b;
    --radius: 16px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    background:
        radial-gradient(circle at 10% 0%, rgba(59, 130, 246, .13), transparent 32rem),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: var(--primary);
}

a:hover {
    color: #a8c7ff;
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    letter-spacing: -.035em;
}

h2 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    letter-spacing: -.015em;
}

code,
pre {
    font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.site-header {
    border-bottom: 1px solid rgba(112, 165, 255, .15);
    background: rgba(9, 17, 31, .88);
}

.header-inner,
.container {
    width: min(1560px, calc(100% - 40px));
    margin-inline: auto;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding-block: 24px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.container {
    padding-block: 30px 44px;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--primary);
    font-size: .71rem;
    font-weight: 750;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.muted,
.field-hint {
    color: var(--muted);
}

.field-hint {
    margin: 7px 0 0;
    font-size: .78rem;
}

.panel {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(145deg, rgba(22, 36, 58, .8), rgba(17, 28, 46, .96));
    box-shadow: 0 18px 50px rgba(0, 0, 0, .13);
}

.control-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(290px, 1fr);
    gap: 20px;
    align-items: start;
}

.side-controls {
    display: grid;
    gap: 20px;
}

.compact-panel p:not(.eyebrow) {
    margin-bottom: 16px;
    font-size: .9rem;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.section-heading h2 {
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.form-grid-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stack-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    min-width: 0;
    color: #cbd7e8;
    font-size: .85rem;
    font-weight: 650;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid #34465f;
    border-radius: 10px;
    outline: none;
    background: #0c1728;
    color: var(--text);
    font-size: .9rem;
    font-weight: 400;
    transition: border-color .16s, box-shadow .16s;
}

input,
select {
    min-height: 43px;
    padding: 9px 12px;
}

textarea {
    min-height: 78px;
    padding: 11px 12px;
    line-height: 1.45;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: #6f819b;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(112, 165, 255, .14);
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: .5;
}

.mode-section {
    margin-block: 16px;
    padding: 16px;
    border: 1px solid rgba(112, 165, 255, .15);
    border-radius: 12px;
    background: rgba(9, 17, 31, .4);
}

.mode-section .form-grid {
    margin-bottom: 16px;
}

.mode-section .form-grid:last-child,
.mode-section > label:last-child {
    margin-bottom: 0;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    text-decoration: none;
    font-size: .85rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    transition: transform .12s, background .12s, border-color .12s;
}

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

.button:focus-visible,
summary:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(112, 165, 255, .5);
    outline-offset: 3px;
}

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

.button-primary:hover {
    background: #5695f8;
}

.button-secondary {
    border-color: #3a4b65;
    background: #18263b;
    color: #dbe7f8;
}

.button-secondary:hover {
    border-color: #58708f;
    background: #20314a;
}

.button-danger {
    border-color: rgba(255, 126, 138, .35);
    background: rgba(156, 48, 66, .23);
    color: #ffabb3;
}

.button-danger:hover {
    background: rgba(176, 51, 70, .38);
}

.button-small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: .75rem;
}

.button-wide {
    width: 100%;
}

.alert {
    margin-bottom: 20px;
    padding: 13px 16px;
    border: 1px solid;
    border-radius: 11px;
    font-size: .9rem;
}

.alert-success {
    border-color: rgba(81, 214, 160, .35);
    background: rgba(32, 133, 97, .15);
    color: #9ceccb;
}

.alert-error {
    border-color: rgba(255, 126, 138, .35);
    background: rgba(156, 48, 66, .15);
    color: #ffb7be;
}

.status-badge,
.online-badge,
.offline-badge {
    display: inline-flex;
    align-items: center;
    width: max-content;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 750;
    letter-spacing: .035em;
    white-space: nowrap;
}

.status-badge {
    padding: 4px 8px;
    border: 1px solid;
}

.status-pending {
    border-color: rgba(247, 200, 107, .28);
    background: rgba(247, 200, 107, .1);
    color: var(--warning);
}

.status-sent {
    border-color: rgba(112, 165, 255, .3);
    background: rgba(112, 165, 255, .1);
    color: #9ec0ff;
}

.status-completed {
    border-color: rgba(81, 214, 160, .3);
    background: rgba(81, 214, 160, .1);
    color: var(--success);
}

.status-failed {
    border-color: rgba(255, 126, 138, .3);
    background: rgba(255, 126, 138, .1);
    color: var(--danger);
}

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

.devices-heading {
    align-items: end;
    margin-bottom: 14px;
}

.devices-heading h2,
.devices-heading p {
    margin-bottom: 0;
}

.devices-heading > p {
    font-size: .78rem;
}

.devices-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.devices-table,
.commands-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    vertical-align: top;
}

.devices-table {
    min-width: 1180px;
}

.devices-table th,
.commands-table th {
    color: var(--muted);
    font-size: .7rem;
    font-weight: 750;
    letter-spacing: .055em;
    text-transform: uppercase;
}

.devices-table > thead > tr > th {
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
    background: #0e192a;
}

.devices-table > tbody > tr > td {
    min-width: 120px;
    padding: 17px 15px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: .82rem;
}

.devices-table > tbody > tr:last-child > td {
    border-bottom: 0;
}

.devices-table > tbody > tr:hover > td {
    background: rgba(112, 165, 255, .025);
}

.device-id {
    display: block;
    margin-top: 7px;
    color: var(--muted);
    font-size: .75rem;
    overflow-wrap: anywhere;
}

.date-cell {
    min-width: 172px !important;
    color: #c4d1e3;
    white-space: nowrap;
}

.online-badge,
.offline-badge {
    margin-top: 8px;
    padding: 3px 7px;
}

.online-badge {
    background: rgba(81, 214, 160, .1);
    color: var(--success);
}

.online-badge > span {
    width: 6px;
    height: 6px;
    margin-right: 5px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.offline-badge {
    background: rgba(154, 171, 193, .08);
    color: var(--muted);
}

.comment-cell {
    min-width: 220px !important;
}

.meta-form {
    display: grid;
    gap: 9px;
}

.meta-form .button {
    justify-self: start;
}

.link-cell {
    min-width: 220px !important;
    max-width: 310px;
}

.link-display,
[data-link-editor] {
    display: grid;
    gap: 10px;
    justify-items: start;
    width: 100%;
}

.link-display a,
.invalid-value {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.invalid-value {
    color: var(--danger);
}

.journal-cell {
    min-width: 160px !important;
}

summary {
    color: var(--primary);
    font-weight: 650;
    cursor: pointer;
}

summary span {
    color: var(--muted);
    font-weight: 400;
}

details[open] > summary {
    margin-bottom: 14px;
}

.journal-scroll {
    overflow: auto;
    width: min(1000px, 72vw);
    max-height: 540px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.commands-table {
    min-width: 1080px;
    background: #0d1828;
    font-size: .75rem;
}

.commands-table th,
.commands-table td {
    padding: 10px;
    border-bottom: 1px solid #24344a;
    vertical-align: top;
}

.commands-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #132137;
}

.commands-table td {
    min-width: 120px;
    color: #c4d1e3;
}

.commands-table td:first-child,
.commands-table td:nth-child(2) {
    min-width: 60px;
}

.commands-table pre {
    max-width: 340px;
    margin: 0;
    color: #c8d9f1;
    font-size: .7rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.result-cell {
    max-width: 300px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.empty-state {
    text-align: center;
}

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

.empty-state p {
    margin-bottom: 0;
    color: var(--muted);
}

.site-footer {
    padding: 0 20px 28px;
    color: #70839d;
    font-size: .75rem;
    text-align: center;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(410px, 100%);
    padding: 34px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 28px 80px rgba(0, 0, 0, .3);
    text-align: center;
}

.login-card h1 {
    margin-bottom: 6px;
    font-size: 1.55rem;
}

.login-card > p {
    margin-bottom: 24px;
}

.login-card form {
    text-align: left;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin: 0 auto 18px;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--primary), var(--primary-strong));
    color: #07101e;
    font-size: 1.4rem;
    font-weight: 900;
}

@media (max-width: 1100px) {
    .control-grid {
        grid-template-columns: 1fr;
    }

    .side-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .header-inner,
    .container {
        width: min(100% - 24px, 1560px);
    }

    .header-inner {
        align-items: flex-start;
        padding-block: 18px;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .header-actions .button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: .75rem;
    }

    .container {
        padding-top: 20px;
    }

    .panel {
        padding: 18px;
    }

    .form-grid-two,
    .side-controls {
        grid-template-columns: 1fr;
    }

    .section-heading,
    .devices-heading {
        display: block;
    }

    .devices-heading > p {
        margin-top: 8px;
    }

    .devices-table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .devices-table,
    .devices-table > tbody,
    .devices-table > tbody > tr,
    .devices-table > tbody > tr > td {
        display: block;
        width: 100%;
    }

    .devices-table {
        min-width: 0;
    }

    .devices-table > thead {
        display: none;
    }

    .devices-table > tbody > tr {
        margin-bottom: 16px;
        overflow: hidden;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface);
    }

    .devices-table > tbody > tr > td,
    .devices-table > tbody > tr > td:hover {
        display: grid;
        grid-template-columns: minmax(100px, 34%) minmax(0, 1fr);
        gap: 12px;
        min-width: 0 !important;
        max-width: none;
        padding: 13px 14px;
        border-bottom: 1px solid var(--border);
        background: transparent;
    }

    .devices-table > tbody > tr > td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: .7rem;
        font-weight: 700;
        text-transform: uppercase;
    }

    .devices-table > tbody > tr > td > * {
        min-width: 0;
    }

    .devices-table > tbody > tr > .journal-cell {
        display: block;
        border-bottom: 0;
    }

    .devices-table > tbody > tr > .journal-cell::before {
        display: block;
        margin-bottom: 10px;
    }

    .date-cell {
        white-space: normal;
    }

    .journal-scroll {
        width: 100%;
        max-height: 480px;
    }
}

@media (max-width: 460px) {
    .header-inner {
        display: block;
    }

    .header-actions {
        justify-content: flex-start;
        margin-top: 16px;
    }

    .login-card {
        padding: 26px 20px;
    }

    .devices-table > tbody > tr > td,
    .devices-table > tbody > tr > td:hover {
        grid-template-columns: 1fr;
        gap: 7px;
    }
}
