/* The pages of the remote desktop in the browser: the connection form and the session, in the colors of the portal. */

:root {
    color-scheme: light;
    --background: #f1f5f9;
    --card: #ffffff;
    --foreground: #0f172a;
    --muted: #f1f5f9;
    --muted-foreground: #64748b;
    --border: #e2e8f0;
    --input: #cbd5e1;
    --primary: #1f6fd8;
    --primary-hover: #1a5fbb;
    --primary-foreground: #ffffff;
    --ring: #2c7be5;
    --destructive: #dc2626;
    --destructive-soft: #fef2f2;
    --navy: #152e4d;
    --session: #0c1d33;
    --radius: 10px;
    --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 8px 24px rgb(15 23 42 / 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --background: #0a1422;
        --card: #0f1d31;
        --foreground: #e2e8f0;
        --muted: #172a44;
        --muted-foreground: #94a3b8;
        --border: rgb(255 255 255 / 0.09);
        --input: rgb(255 255 255 / 0.16);
        --primary-hover: #2c7be5;
        --ring: #4b91ec;
        --destructive: #ef4444;
        --destructive-soft: rgb(239 68 68 / 0.12);
        --navy: #e2e8f0;
        --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 12px 32px rgb(0 0 0 / 0.35);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--background);
    color: var(--foreground);
    font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

/* --- connection form --- */

.page {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.logo {
    display: block;
    height: 28px;
    width: auto;
    margin-bottom: 24px;
    color: var(--navy);
}

.card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow);
    padding: 28px;
}

.card h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-align: center;
}

.card .lead {
    margin: 4px 0 20px;
    color: var(--muted-foreground);
    overflow-wrap: anywhere;
    text-align: center;
}

.alert {
    display: flex;
    justify-content: center;
    text-align: center;
    gap: 10px;
    margin: 0 0 18px;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--destructive) 35%, transparent);
    border-radius: var(--radius);
    background: var(--destructive-soft);
    color: var(--destructive);
}

.alert svg {
    flex: none;
    margin-top: 2px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    min-width: 0;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    font-weight: 500;
    font-size: 13px;
}

.optional {
    color: var(--muted-foreground);
    font-weight: 400;
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    background: var(--card);
    border: 1px solid var(--input);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
}

select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    text-overflow: ellipsis;
}

/* the menus of the form, drawn by the page rather than by the system; the select stays behind them, sent with the
   form, and in place when scripts do not run */
.menu {
    position: relative;
}

.menu select {
    display: none;
}

.menu-button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 38px;
    padding: 0 10px 0 12px;
    background: var(--card);
    border: 1px solid var(--input);
    border-radius: var(--radius);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s;
}

.menu-button span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-button svg {
    flex: none;
    color: var(--muted-foreground);
    transition: transform 0.15s;
}

.menu-button[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.menu-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: calc(100vw - 32px);
    max-height: 260px;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.menu-list.end {
    left: auto;
    right: 0;
}

.menu-list[hidden] {
    display: none;
}

.menu-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    white-space: nowrap;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;
}

.menu-list li svg {
    flex: none;
    visibility: hidden;
    color: var(--primary);
}

.menu-list li[aria-selected="true"] {
    font-weight: 500;
}

.menu-list li[aria-selected="true"] svg {
    visibility: visible;
}

.menu-list li.active {
    background: var(--muted);
}

.menu-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    border-color: var(--muted-foreground);
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0 14px;
    font-weight: 400;
    cursor: pointer;
}

.check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
}

details {
    margin: 0 0 18px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

summary {
    cursor: pointer;
    color: var(--muted-foreground);
    font-size: 13px;
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-foreground);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
}

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

.button:focus-visible {
    outline: none;
    background: var(--primary-hover);
}

.button:disabled {
    opacity: 0.7;
    cursor: progress;
}

.button.block {
    width: 100%;
}

.button.secondary {
    background: transparent;
    border-color: var(--input);
    color: var(--foreground);
}

.button.secondary:hover {
    background: var(--muted);
}

.note {
    display: flex;
    gap: 8px;
    margin: 18px 0 0;
    color: var(--muted-foreground);
    font-size: 12.5px;
}

.note svg {
    flex: none;
    margin-top: 2px;
}

@media (max-width: 480px) {
    .page {
        justify-content: flex-start;
        padding-top: 24px;
    }

    .card {
        padding: 20px;
    }

    .row {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

/* --- session --- */

body.session {
    background: var(--session);
    overflow: hidden;
    touch-action: none;
}

#display {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#display > div {
    flex: none;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: color-mix(in srgb, var(--session) 88%, transparent);
}

.overlay[hidden] {
    display: none;
}

.overlay .card {
    max-width: 360px;
    text-align: center;
}

.overlay h1 {
    font-size: 18px;
}

.overlay .lead {
    margin-bottom: 0;
}

.overlay .actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}

.spinner {
    width: 28px;
    height: 28px;
    margin: 0 auto 14px;
    border: 3px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* the toolbar hides above the screen; the mouse at the top edge, or the tab, shows it */
.toolbar {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 20;
    display: flex;
    gap: 2px;
    max-width: calc(100vw - 16px);
    padding: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 calc(var(--radius) + 2px) calc(var(--radius) + 2px);
    box-shadow: var(--shadow);
    transform: translate(-50%, -100%);
    transition: transform 0.18s ease;
}

.toolbar.shown {
    transform: translate(-50%, 0);
}

.toolbar button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
}

.toolbar button:hover,
.toolbar button[aria-pressed="true"] {
    background: var(--muted);
}

.toolbar button.danger {
    color: var(--destructive);
}

.toolbar .separator {
    width: 1px;
    margin: 6px 2px;
    background: var(--border);
}

.tab {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 19;
    width: 56px;
    height: 10px;
    padding: 0;
    border: none;
    border-radius: 0 0 8px 8px;
    background: color-mix(in srgb, var(--card) 70%, transparent);
    transform: translateX(-50%);
    cursor: pointer;
}

.tab::after {
    content: "";
    display: block;
    width: 24px;
    height: 2px;
    margin: 3px auto 0;
    border-radius: 2px;
    background: var(--muted-foreground);
}

@media (max-width: 760px) {
    .toolbar button span {
        display: none;
    }
}

.panel {
    position: fixed;
    top: 52px;
    left: 50%;
    z-index: 21;
    width: min(400px, calc(100vw - 32px));
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow);
    transform: translateX(-50%);
}

.panel[hidden] {
    display: none;
}

.panel h2 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
}

.panel p {
    margin: 0 0 10px;
    color: var(--muted-foreground);
    font-size: 12.5px;
}

.panel textarea {
    height: 120px;
    padding: 8px 10px;
    resize: vertical;
    font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.panel .actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.panel .actions .button {
    height: 34px;
    font-size: 13px;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    z-index: 40;
    max-width: calc(100vw - 32px);
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 13px;
    transform: translate(-50%, 12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, transform 0.18s;
}

.toast.shown {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
    .toolbar,
    .toast {
        transition: none;
    }

    .spinner {
        animation-duration: 2s;
    }
}
