html,
body {
    min-height: 100%;
    margin: 0;
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
    background: #f2f2f2;
    color: #333333;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    touch-action: manipulation;
}

h1 {
    margin: 0;
    font-size: clamp(1.55rem, 1.1rem + 1vw, 2.2rem);
    font-weight: 760;
}

h1:focus {
    outline: none;
}

.app-shell {
    min-height: 100vh;
}

.devices-page {
    min-height: 100vh;
    box-sizing: border-box;
    padding: 28px;
}

.devices-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto 24px;
}

.add-device-button {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 44px;
    border-radius: 6px;
    padding: 0 16px;
    background: #004aad;
    color: #fff;
    font-weight: 800;
}

.add-device-button span {
    font-size: 1.35rem;
    line-height: 1;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    max-width: 1100px;
    margin: 0 auto;
}

.device-card {
    overflow: hidden;
    border: 1px solid #d7ded5;
    border-radius: 8px;
    background: #f8faf6;
    box-shadow: 0 8px 24px rgba(28, 40, 34, .07);
}

.device-open-area {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 94px;
    padding: 16px;
    text-align: left;
    background: transparent;
    color: #15201c;
}

.device-open-area:hover {
    background: #edf4fa;
}

.device-icon,
.empty-device-icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    background: #42456c;
    color: #fff;
    font-weight: 900;
}

.device-identity {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.device-identity strong,
.device-identity small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-identity strong {
    font-size: 1.05rem;
}

.device-identity small {
    color: #66736b;
}

.device-chevron {
    color: #7d8981;
    font-size: 1.8rem;
}

.device-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid #e3e9e1;
    padding: 9px 12px;
    color: #6a766f;
    font-size: .8rem;
}

.device-actions {
    display: flex;
    gap: 6px;
}

.device-actions button {
    border-radius: 5px;
    padding: 6px 9px;
    background: #e9eee8;
    color: #2b3832;
    font-weight: 750;
}

.device-actions .danger-action {
    background: #f4e4e1;
    color: #8a3e34;
}

.empty-devices {
    display: grid;
    justify-items: center;
    gap: 14px;
    max-width: 480px;
    margin: 15vh auto 0;
    text-align: center;
}

.empty-devices h2 {
    margin: 0;
    font-size: 1.2rem;
}

.empty-device-icon {
    width: 64px;
    height: 64px;
    background: #88958d;
    font-size: 1.35rem;
}

.dialog-backdrop {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(18, 29, 24, .46);
}

.device-dialog,
.confirm-dialog {
    width: min(430px, 100%);
    box-sizing: border-box;
    border-radius: 8px;
    padding: 18px;
    background: #f8faf6;
    box-shadow: 0 24px 70px rgba(15, 24, 20, .3);
}

.device-dialog > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.device-dialog h2,
.confirm-dialog h2 {
    margin: 0;
    font-size: 1.15rem;
}

.device-dialog > header button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #e9eee8;
    color: #26342e;
    font-size: 1.1rem;
}

.device-dialog > footer,
.confirm-dialog > footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
}

.delete-confirm-button {
    min-height: 42px;
    border-radius: 6px;
    background: #a9473a;
    color: #fff;
    font-weight: 800;
}

.confirm-dialog p {
    margin: 8px 0 0;
    color: #68756d;
}

.remote-app {
    min-height: 100vh;
    padding: 20px;
    outline: none;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1500px;
    margin: 0 auto 16px;
}

.remote-heading {
    display: flex;
    align-items: center;
    gap: 12px;
}

.desktop-back-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #dceaf5;
    color: #0f4577;
    font-size: 1.25rem;
    font-weight: 800;
}

.mobile-back-button {
    display: none;
}

.eyebrow {
    margin: 0 0 2px;
    color: #0f5f99;
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .08em;
}

.connection-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 116px;
    justify-content: center;
    border: 1px solid #cfd8ce;
    border-radius: 999px;
    padding: 8px 12px;
    background: #f8faf6;
    color: #4e5a52;
    font-weight: 700;
}

.connection-pill span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #b34f42;
}

.connection-pill.online span {
    background: #1471b5;
}

.mobile-settings-button,
.mobile-panel-header {
    display: none;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 16fr) minmax(260px, 7fr);
    gap: 16px;
    max-width: 1500px;
    margin: 0 auto;
    align-items: start;
}

.device-panel,
.keyboard-panel,
.terminal-area {
    background: #f8faf6;
    border: 1px solid #d7ded5;
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(28, 40, 34, .08);
}

.device-panel {
    padding: 16px;
}

.field-grid {
    display: grid;
    gap: 12px;
}

.field-grid label {
    display: grid;
    gap: 5px;
}

.field-grid span,
.meta-list dt {
    color: #65736a;
    font-size: .78rem;
    font-weight: 750;
}

.field-grid input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5ca;
    border-radius: 6px;
    padding: 10px 11px;
    background: #fff;
    color: #15201c;
}

.field-grid input:focus {
    outline: 3px solid rgba(20, 113, 181, .18);
    border-color: #1471b5;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

.primary-action,
.secondary-action {
    min-height: 42px;
    border-radius: 6px;
    font-weight: 800;
}

.primary-action {
    background: #004aad;
    color: #fff;
}

.secondary-action {
    background: #e9eee8;
    color: #25332d;
}

.primary-action:disabled,
.secondary-action:disabled,
.key-button:disabled {
    opacity: .45;
}

.profile-list {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.profile-item {
    display: grid;
    gap: 2px;
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    background: #edf3ef;
    color: #26342e;
}

.profile-item.active {
    background: #dcebf7;
    box-shadow: inset 3px 0 0 #1471b5;
}

.profile-item span {
    overflow: hidden;
    color: #65736a;
    font-size: .8rem;
    text-overflow: ellipsis;
}

.meta-list {
    display: grid;
    gap: 8px;
    margin: 16px 0 0;
}

.meta-list div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #e5ebe3;
    padding-bottom: 7px;
}

.meta-list dd {
    margin: 0;
    color: #26342e;
    font-weight: 750;
}

.status-message {
    margin: 14px 0 0;
    color: #9a3f34;
    font-size: .9rem;
}

.terminal-area {
    padding: 14px;
}

.terminal-frame {
    display: grid;
    grid-template-rows: repeat(16, 1fr);
    aspect-ratio: 1558 / 849;
    min-height: 360px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    border: 4px solid #42456c;
    background: #adbacb;
    padding: clamp(12px, 2vw, 28px);
}

.terminal-row {
    display: grid;
    grid-template-columns: repeat(40, minmax(0, 1fr));
    min-width: 0;
}

.terminal-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
    color: #42456c;
    font-family: Consolas, "Courier New", monospace;
    font-size: clamp(.58rem, 1.55vw, 1.95rem);
    font-weight: 900;
    line-height: 1;
    white-space: pre;
}

.terminal-cell.inverted {
    background: #42456c;
    color: #adbacb;
}

.keyboard-panel {
    padding: 14px;
}

.key-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(48px, 1fr));
    grid-auto-rows: minmax(56px, 1fr);
    gap: 9px;
}

.key-button {
    min-width: 0;
    border-radius: 6px;
    background: #ffffff;
    color: #18231f;
    box-shadow: inset 0 0 0 1px #cbd5ca;
    font-weight: 850;
}

.key-button:active {
    transform: translateY(1px);
    background: #e6eee8;
}

.key-button.arrow {
    background: #d8e8de;
    color: #1d5e42;
    font-size: 1.24rem;
}

.key-button.command {
    background: #f2e6d2;
    color: #6b4a1e;
}

.key-button.enter {
    grid-column: span 2;
    background: #004aad;
    color: #fff;
}

#blazor-error-ui {
    color-scheme: light only;
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: .75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

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

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #dbe3da;
    stroke-width: .6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #1471b5;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * .8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    inset: calc(20vh + 3.25rem) 0 auto 0;
    text-align: center;
    font-weight: 800;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}

@media (orientation: portrait) and (max-width: 900px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .terminal-area {
        order: -1;
    }

    .terminal-frame {
        min-height: 260px;
    }
}

@media (max-width: 620px) {
    .devices-page {
        padding: 18px 14px;
    }

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

    .add-device-button {
        width: 44px;
        padding: 0;
        justify-content: center;
        font-size: 0;
    }

    .add-device-button span {
        font-size: 1.35rem;
    }

    .devices-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .remote-app {
        padding: 12px;
    }

    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .terminal-frame {
        min-height: auto;
        padding: 10px;
        border-width: 3px;
    }

    .terminal-cell {
        font-size: clamp(.34rem, 2.08vw, .86rem);
    }

    .key-grid {
        grid-auto-rows: 52px;
    }
}

@media (orientation: landscape) and (max-width: 960px) and (max-height: 600px) {
    html,
    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .remote-app {
        width: 100%;
        height: 100dvh;
        min-height: 0;
        box-sizing: border-box;
        padding:
            max(8px, env(safe-area-inset-top))
            max(8px, env(safe-area-inset-right))
            max(8px, env(safe-area-inset-bottom))
            max(8px, env(safe-area-inset-left));
    }

    .app-header {
        display: none;
    }

    .mobile-back-button {
        position: fixed;
        z-index: 30;
        left: max(12px, env(safe-area-inset-left));
        bottom: max(12px, env(safe-area-inset-bottom));
        display: grid;
        place-items: center;
        width: 40px;
        height: 40px;
        border: 1px solid rgba(66, 69, 108, .35);
        border-radius: 50%;
        background: rgba(248, 250, 246, .94);
        color: #42456c;
        box-shadow: 0 5px 16px rgba(20, 30, 25, .18);
        font-size: 1.15rem;
        font-weight: 800;
    }

    .workspace {
        display: grid;
        grid-template-columns: minmax(0, 16fr) minmax(210px, 7fr);
        gap: 8px;
        width: 100%;
        height: 100%;
        max-width: none;
    }

    .terminal-area {
        grid-column: 1;
        order: 0;
        min-width: 0;
        height: 100%;
        box-sizing: border-box;
        padding: 6px;
        border-radius: 6px;
    }

    .terminal-frame {
        width: 100%;
        height: 100%;
        min-height: 0;
        aspect-ratio: auto;
        padding: 10px 12px;
        border-width: 3px;
    }

    .terminal-cell {
        font-size: clamp(.52rem, 1.9vw, 1.05rem);
    }

    .keyboard-panel {
        grid-column: 2;
        height: 100%;
        box-sizing: border-box;
        padding: 6px;
        border-radius: 6px;
    }

    .key-grid {
        height: 100%;
        grid-template-columns: repeat(4, minmax(38px, 1fr));
        grid-template-rows: repeat(6, minmax(0, 1fr));
        grid-auto-rows: minmax(0, 1fr);
        gap: 5px;
    }

    .key-button {
        min-height: 0;
        border-radius: 5px;
        font-size: clamp(.72rem, 1.8vw, 1rem);
    }

    .key-button.arrow {
        font-size: clamp(.95rem, 2.3vw, 1.3rem);
    }

    .device-panel {
        position: fixed;
        z-index: 20;
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        display: block;
        width: min(330px, calc(100vw - 32px));
        box-sizing: border-box;
        overflow-y: auto;
        transform: translateX(calc(100% + 24px));
        transition: transform .18s ease-out;
        box-shadow: 0 18px 48px rgba(18, 29, 24, .28);
    }

    .settings-open .device-panel {
        transform: translateX(0);
    }

    .mobile-panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 12px;
    }

    .mobile-panel-header button {
        width: 34px;
        height: 34px;
        border-radius: 50%;
        background: #e9eee8;
        color: #26342e;
        font-size: 1.2rem;
        font-weight: 800;
    }

    .mobile-settings-button {
        position: fixed;
        z-index: 30;
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        display: grid;
        place-items: center;
        width: 40px;
        height: 40px;
        border: 1px solid rgba(66, 69, 108, .35);
        border-radius: 50%;
        background: rgba(248, 250, 246, .94);
        color: #42456c;
        box-shadow: 0 5px 16px rgba(20, 30, 25, .18);
        font-size: 1.15rem;
    }

    .settings-open .mobile-settings-button {
        display: none;
    }

    .mobile-status-dot {
        position: absolute;
        top: 3px;
        right: 3px;
        width: 8px;
        height: 8px;
        border: 2px solid #f8faf6;
        border-radius: 50%;
        background: #b34f42;
    }

    .mobile-settings-button.online .mobile-status-dot {
        background: #1471b5;
    }
}

.session-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px clamp(16px, 4vw, 48px);
    border-bottom: 1px solid rgba(66, 69, 108, .16);
    background: rgba(248, 250, 246, .96);
}

.session-nav a,
.session-nav button {
    border: 0;
    background: transparent;
    color: #42456c;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.session-nav span {
    margin-left: auto;
    color: #5f6470;
    font-size: .9rem;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(115deg, #1471b5 0%, #0f4577 100%);
}

.login-page {
    box-sizing: border-box;
}

.session-nav + .auth-page {
    min-height: calc(100vh - 64px);
}

.auth-page form {
    display: grid;
    gap: 18px;
    width: min(100%, 440px);
    padding: clamp(24px, 5vw, 48px);
    border: 1px solid rgba(66, 69, 108, .2);
    border-radius: 24px;
    background: #f2f2f2;
    box-shadow: 0 20px 60px rgba(25, 31, 50, .12);
}

.auth-page label,
.confirm-dialog label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

.auth-page input,
.confirm-dialog input,
.device-dialog select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid rgba(66, 69, 108, .3);
    border-radius: 10px;
    background: #fff;
    color: #25283d;
}

.checkbox-field {
    display: flex !important;
    align-items: center;
    gap: 10px;
}

.checkbox-field input {
    width: auto;
}

.admin-users-grid {
    display: grid;
    gap: 14px;
}

.admin-user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px;
    border: 1px solid rgba(66, 69, 108, .18);
    border-radius: 16px;
    background: #fff;
}

.admin-user-card > div:first-child {
    display: grid;
    gap: 4px;
}

@media (max-width: 700px) {
    .session-nav { flex-wrap: wrap; gap: 10px; }
    .session-nav span { order: -1; width: 100%; margin-left: 0; }
    .admin-user-card { align-items: stretch; flex-direction: column; }
}
