:root {
  --bg: #11151c; --panel: #181e27; --panel-2: #1f2631; --raised: #263040; --line: #2c3645;
  --text: #e6ebf2; --muted: #8c97a8; --accent: #2f6fe4; --accent-text: #fff; --accent-soft: #1d3766;
  --ok: #33c27f; --warn: #e3a33b; --danger: #e5534b; --focus: #7fb0ff;
  --radius: 8px; --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f5; --panel: #ffffff; --panel-2: #f5f7fa; --raised: #e8ecf2; --line: #d8dee8;
    --text: #18202b; --muted: #5f6b7b; --accent-soft: #dbe7fd; --shadow: 0 12px 40px rgba(20, 30, 50, .18);
    color-scheme: light;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--focus); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

button { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover:not(:disabled) { background: var(--raised); filter: none; }
button.wide { width: 100%; }
button.icon { padding: 5px 8px; line-height: 1; }
input[type=text], input[type=password], input:not([type]), select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; }

/* sign in */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 32px; border-radius: 12px; width: min(380px, 100%); box-shadow: var(--shadow); }
.login-card h1 { font-size: 21px; margin: 0 0 4px; display: flex; gap: 10px; align-items: center; }
.login-card p { margin: 0 0 20px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login-card input { width: 100%; padding: 10px 12px; }
.login-card button { margin-top: 16px; padding: 10px; }
.form-error { color: var(--danger); min-height: 1.5em; margin-top: 10px; font-size: 13.5px; }

/* layout */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; font-weight: 650; font-size: 15px; border-bottom: 1px solid var(--line); }
.brand .spacer { flex: 1; }
.computers { flex: 1; overflow: auto; padding: 8px; }
.computer { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 9px 10px; }
.computer:hover { background: var(--panel-2); filter: none; }
.computer.active { background: var(--accent-soft); }
.computer .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.computer .meta { font-size: 12px; color: var(--muted); }
.computer .text { min-width: 0; flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--line); display: grid; gap: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 52px; }
.topbar h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar h2 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-button { display: none; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs button { background: transparent; border-color: transparent; color: var(--muted); }
.tabs button.active { background: var(--raised); color: var(--text); border-color: var(--line); }
.content { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.empty { margin: auto; text-align: center; max-width: 480px; padding: 24px; }
.empty h3 { font-size: 18px; margin: 0 0 8px; }

/* screen */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.toolbar .grow { flex: 1; }
.toolbar select { padding: 5px 8px; }
.stats { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.screen-area { flex: 1; min-height: 0; overflow: auto; background: #05070a; position: relative; display: grid; }
.screen-area.fit { overflow: hidden; }
.screen-stage { margin: auto; position: relative; line-height: 0; }
.screen-stage canvas { display: block; outline: none; touch-action: none; }
.screen-area.fit .screen-stage canvas { max-width: 100%; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 7, 10, .72); color: #e6ebf2; text-align: center; padding: 24px; z-index: 2; }
.overlay .box { max-width: 460px; display: grid; gap: 12px; justify-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: calc(100% + 4px); left: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; z-index: 20; min-width: 190px; display: grid; }
.dropdown-menu button { text-align: left; background: transparent; border: 0; padding: 7px 10px; border-radius: 6px; }
.dropdown-menu button:hover { background: var(--raised); filter: none; }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

/* terminal */
.term-tabs { display: flex; gap: 4px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); overflow-x: auto; }
.term-tab { display: inline-flex; gap: 6px; align-items: center; background: transparent; border: 1px solid transparent; }
.term-tab.active { background: var(--raised); border-color: var(--line); }
.term-tab .x { opacity: .6; padding: 0 2px; }
.terminals { flex: 1; min-height: 0; position: relative; background: #0b0e13; color-scheme: dark; }
.terminal-host { position: absolute; inset: 0; padding: 6px 0 0 8px; }
.terminal-host.hidden { visibility: hidden; }

/* files */
.files { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; min-width: 0; }
.crumbs button { padding: 4px 6px; }
.crumbs .sep { color: var(--muted); }
.file-table-wrap { flex: 1; min-height: 0; overflow: auto; position: relative; }
.file-table-wrap.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; background: color-mix(in srgb, var(--accent) 8%, transparent); }
table.file-table { width: 100%; border-collapse: collapse; }
.file-table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; z-index: 1; }
.file-table td { padding: 6px 10px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: nowrap; }
.file-table tr:hover td { background: var(--panel-2); }
.file-table tr.selected td { background: var(--accent-soft); }
.file-table td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
.file-table td.name button { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.file-table td.name button:hover { text-decoration: underline; filter: none; }
.file-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.file-icon { display: inline-block; width: 18px; margin-right: 6px; text-align: center; }
.transfers { border-top: 1px solid var(--line); background: var(--panel-2); max-height: 160px; overflow: auto; padding: 6px 12px; display: grid; gap: 4px; }
.transfer { display: grid; grid-template-columns: 1fr 160px 60px; gap: 10px; align-items: center; font-size: 12.5px; }
.transfer progress { width: 100%; }
.status-line { padding: 5px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); display: flex; gap: 12px; }
.status-line .error { color: var(--danger); }

/* details */
.details { padding: 20px; overflow: auto; display: grid; grid-template-columns: minmax(0, 900px); gap: 20px; align-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row code { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }
.steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* dialogs */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 650; display: flex; align-items: center; }
.modal header .spacer { flex: 1; }
.modal .body { padding: 16px 18px; display: grid; gap: 12px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--raised); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 60; max-width: calc(100vw - 32px); }
.toast.error { border-color: var(--danger); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(290px, 85vw); z-index: 40; transform: translateX(-100%); transition: transform .2s; visibility: hidden; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); visibility: visible; }
  .nav-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 39; }
  .menu-button { display: inline-flex; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
  .file-table .hide-narrow { display: none; }
  .transfer { grid-template-columns: 1fr 90px 50px; }
}
button.primary.danger-fill { background: var(--danger); border-color: var(--danger); }
.toolbar .crumbs { flex: 0 1 auto; min-width: 0; }
.route-switch { display: grid; gap: 4px; }
.route-switch select { width: 100%; }
.direct-toggle { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; }
.direct-toggle input { margin-top: 2px; }
