/* ============================================================================
   Ark Alliance · Remote Desktop — console + sign-in styling
   A single dark theme, no external CSS frameworks.
   ============================================================================ */

:root {
    --bg: #0b0e14;
    --bg-elevated: #11151f;
    --panel: #161b27;
    --panel-2: #1d2433;
    --border: #28324a;
    --text: #e6e9f0;
    --text-dim: #94a0b8;
    --text-faint: #64708a;
    --accent: #4c8bf5;
    --accent-strong: #3a6fd0;
    --danger: #ff5d6c;
    --ok: #45d39a;
    --idle: #5a6883;
    --radius: 10px;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    background: radial-gradient(1200px 800px at 70% -10%, #14203a 0%, var(--bg) 55%);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ----------------------------------------------------------------- Buttons */
.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    white-space: nowrap;
}

.btn:hover {
    background: #232c40;
    border-color: #36436b;
}

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    border-color: var(--accent-strong);
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(180deg, #5b97f7 0%, #4076d8 100%);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
}

.btn-ghost:hover {
    background: var(--panel-2);
    color: var(--text);
}

.btn[aria-pressed="false"] {
    color: var(--text-faint);
    border-style: dashed;
}

.btn-block {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
}

/* ------------------------------------------------------------- Sign-in page */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
}

.auth-brand {
    font-weight: 800;
    letter-spacing: 0.3px;
    font-size: 18px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.auth-brand span {
    font-weight: 500;
    font-size: 12px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.auth-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
    margin: 18px 0 22px;
}

.auth-error {
    background: rgba(255, 93, 108, 0.12);
    border: 1px solid rgba(255, 93, 108, 0.4);
    color: #ffb3ba;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 18px;
}

.field {
    display: block;
    margin-bottom: 16px;
}

.field-label {
    display: block;
    font-size: 12px;
    color: var(--text-faint);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.field-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 11px 12px;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.2);
}

.auth-footnote {
    margin: 18px 0 0;
    font-size: 12px;
    color: var(--text-faint);
    text-align: center;
}

/* --------------------------------------------------------------- Console */
.console {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 18px;
    row-gap: 10px;
    padding: 10px 16px;
    background: rgba(17, 21, 31, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    min-width: 0;
}

.brand-name {
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.brand-sub {
    font-weight: 500;
    font-size: 10px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--accent);
}

.metrics {
    flex: 1 1 auto;
    justify-content: center;
    gap: 22px;
    color: var(--text-dim);
}

.metric {
    display: inline-flex;
    flex-direction: column;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

.metric-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
}

.actions {
    justify-content: flex-end;
}

.operator {
    color: var(--text-dim);
    font-size: 13px;
    padding: 0 4px;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-form {
    margin: 0;
}

/* ------------------------------------------------------- Icon buttons + menu */
.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.btn-icon.icon-only {
    padding: 8px;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn:disabled:hover {
    background: var(--panel-2);
    border-color: var(--border);
}

/* Brief green confirmation pulse after a successful clipboard action. */
.btn.flash-ok {
    border-color: var(--ok);
    color: var(--ok);
    box-shadow: 0 0 0 2px rgba(69, 211, 154, 0.35);
}

.toolbar-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 2px;
}

.menu {
    position: relative;
}

.menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 224px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px;
    z-index: 50;
}

.menu-panel[hidden] {
    display: none;
}

/* Administration sidebar — the panel is portalled out of the (backdrop-filtered) toolbar by JS so it
   paints above everything, then slides in from the right. */
.menu-panel.sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    width: 340px;
    max-width: 86vw;
    min-width: 0;
    padding: 0;
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    box-shadow: -14px 0 44px rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.24s ease;
}

.menu-panel.sidebar.is-open {
    transform: translateX(0);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.sidebar-head h2 {
    margin: 0;
    font-size: 16px;
}

.sidebar-close {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 9px;
    border-radius: 8px;
}

.sidebar-close:hover {
    background: var(--panel-2);
    color: var(--text);
}

.sidebar-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(6, 9, 14, 0.5);
    z-index: 190;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.24s ease, visibility 0.24s ease;
}

.sidebar-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

.menu-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
    padding: 4px 6px 8px;
}

.menu-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 6px;
    font-size: 13px;
}

.menu-key {
    color: var(--text-dim);
}

.menu-val {
    color: var(--text);
    font-weight: 600;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-sep {
    height: 1px;
    background: var(--border);
    margin: 8px 4px;
}

.btn-danger {
    background: rgba(255, 93, 108, 0.12);
    border-color: rgba(255, 93, 108, 0.4);
    color: #ffb3ba;
}

.btn-danger:hover {
    background: rgba(255, 93, 108, 0.22);
    border-color: var(--danger);
    color: #fff;
}

/* A menu entry styled as a flat, left-aligned row rather than a heavy button. */
.menu-item {
    justify-content: flex-start;
    background: transparent;
    border-color: transparent;
    color: var(--text);
    font-weight: 500;
}

.menu-item:hover {
    background: var(--panel-2);
    border-color: transparent;
}

/* --------------------------------------------------------- Settings modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 9, 14, 0.66);
    backdrop-filter: blur(3px);
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 460px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--panel);
}

.modal-head h2 {
    margin: 0;
    font-size: 17px;
}

.modal-close {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    display: inline-flex;
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-close:hover {
    background: var(--panel-2);
    color: var(--text);
}

.settings-form {
    padding: 18px 20px 20px;
}

.form-section {
    margin-bottom: 18px;
}

.form-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
    margin-bottom: 10px;
}

.field2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 10px;
}

.field2 > span {
    color: var(--text-dim);
    font-size: 13px;
}

.field2-input {
    width: 200px;
    max-width: 55%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 9px 10px;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field2-input:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(76, 139, 245, 0.3);
}

.field2.checkbox {
    justify-content: flex-start;
}

.field2.checkbox input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.field2.checkbox > span {
    color: var(--text);
    font-size: 13px;
}

.field2-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-faint);
}

.form-msg {
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.form-msg.is-error {
    background: rgba(255, 93, 108, 0.12);
    border: 1px solid rgba(255, 93, 108, 0.4);
    color: #ffb3ba;
}

.form-msg.is-ok {
    background: rgba(69, 211, 154, 0.12);
    border: 1px solid rgba(69, 211, 154, 0.4);
    color: #9be9cd;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Wide modals (file picker, logs) with a fixed header/footer and a scrolling body. */
.modal-card-wide {
    max-width: 860px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.list-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.check-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
}

.check-inline input,
.file-row input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.foot-info {
    color: var(--text-dim);
    font-size: 13px;
    margin-right: auto;
}

.empty-state {
    text-align: center;
    color: var(--text-faint);
    padding: 40px 16px;
    font-size: 14px;
}

.empty-state code {
    background: var(--panel-2);
    padding: 1px 6px;
    border-radius: 5px;
}

.file-list,
.log-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
}

.file-row:hover {
    border-color: #36436b;
}

.file-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.file-meta {
    flex: 0 0 auto;
    color: var(--text-faint);
    font-size: 12px;
    white-space: nowrap;
}

.log-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 4px 14px;
    padding: 9px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: 8px;
}

.log-time {
    color: var(--text-faint);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.log-badge {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.log-main {
    min-width: 0;
    grid-column: 3;
}

.log-msg {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.log-sub {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}

.log-row.kind-ok { border-left-color: var(--ok); }
.log-row.kind-ok .log-badge { background: rgba(69, 211, 154, 0.16); color: #9be9cd; }
.log-row.kind-warn { border-left-color: #f0a93b; }
.log-row.kind-warn .log-badge { background: rgba(240, 169, 59, 0.16); color: #f2c98a; }
.log-row.kind-error { border-left-color: var(--danger); }
.log-row.kind-error .log-badge { background: rgba(255, 93, 108, 0.16); color: #ffb3ba; }
.log-row.kind-info { border-left-color: var(--accent); }
.log-row.kind-info .log-badge { background: rgba(76, 139, 245, 0.16); color: #a9c6fb; }

.logs-datelabel {
    display: inline-flex;
    align-items: center;
    color: var(--text-dim);
    font-size: 13px;
}

.logs-datelabel select {
    width: auto;
    max-width: none;
    padding: 6px 8px;
}

.upload-toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 120;
    width: 320px;
    max-width: calc(100vw - 40px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.upload-toast[hidden] {
    display: none;
}

.upload-toast-name {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 8px;
}

.upload-bar {
    height: 6px;
    background: var(--panel-2);
    border-radius: 999px;
    overflow: hidden;
}

.upload-bar-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width 0.15s ease;
}

.upload-toast-status {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.upload-toast-status.is-error { color: #ffb3ba; }
.upload-toast-status.is-ok { color: #9be9cd; }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--idle);
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.status-dot[data-state="on"] {
    background: var(--ok);
    box-shadow: 0 0 10px 1px rgba(69, 211, 154, 0.6);
}

.status-dot[data-state="connecting"] {
    background: #f5c451;
    box-shadow: 0 0 10px 1px rgba(245, 196, 81, 0.55);
}

.status-dot[data-state="error"] {
    background: var(--danger);
    box-shadow: 0 0 10px 1px rgba(255, 93, 108, 0.6);
}

/* ----------------------------------------------------------------- Stage */
.stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    background:
        linear-gradient(45deg, #0a0d13 25%, transparent 25%) -10px 0 / 20px 20px,
        linear-gradient(-45deg, #0a0d13 25%, transparent 25%) -10px 0 / 20px 20px,
        linear-gradient(45deg, transparent 75%, #0a0d13 75%) -10px 0 / 20px 20px,
        linear-gradient(-45deg, transparent 75%, #0a0d13 75%) -10px 0 / 20px 20px,
        var(--bg);
    overflow: hidden;
}

.screen {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: #000;
    box-shadow: var(--shadow);
    cursor: crosshair;
    touch-action: none;
}

.screen:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.console.is-streaming .screen {
    cursor: none;
}

/* --------------------------------------------------- Remote cursor overlay */
/* The host cursor is streamed on its own channel and drawn here as a sprite,
   decoupled from the screen frames so pointer motion stays fluid even when the
   desktop image itself is static. Positioned/scaled via JS transform. */
.remote-cursor {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    pointer-events: none;
    image-rendering: pixelated;
    display: none;
    z-index: 5;
    will-change: transform;
}

.console.is-streaming .remote-cursor.is-visible {
    display: block;
}

/* --------------------------------------------------------------- Overlay */
.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(11, 14, 20, 0.72);
    backdrop-filter: blur(2px);
    transition: opacity 0.25s ease;
}

.console.is-streaming .overlay {
    opacity: 0;
    pointer-events: none;
}

.overlay-card {
    text-align: center;
    max-width: 440px;
    padding: 28px;
}

.overlay-glyph {
    width: 56px;
    height: 56px;
    margin: 0 auto 18px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    box-shadow: 0 10px 30px rgba(76, 139, 245, 0.35);
    position: relative;
}

.overlay-glyph::after {
    content: "";
    position: absolute;
    inset: 16px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 5px;
}

.overlay-card h1 {
    font-size: 20px;
    margin: 0 0 10px;
}

.overlay-card p {
    color: var(--text-dim);
    margin: 0 0 8px;
    line-height: 1.5;
}

.overlay-hint {
    font-size: 12px;
    color: var(--text-faint);
}
