:root {
  --bg: #0b0e14;
  --panel: #141821;
  --panel-2: #1c2130;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #d97757;
  --accent-2: #c25e3f;
  --ok: #4caf50;
  --danger: #e5484d;
  --border: #262c3a;
}
* { box-sizing: border-box; }
/* Ensure the `hidden` attribute always wins over element display rules below
   (e.g. .modal/.tab/main use display:flex, which would otherwise override it). */
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
body { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0;
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { font-weight: 600; letter-spacing: .3px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }

button {
  font: inherit; border: 0; border-radius: 10px; padding: 11px 16px;
  cursor: pointer; color: var(--text); background: var(--panel-2);
}
button.primary { background: var(--accent); color: #14100e; font-weight: 600; }
button.primary:active { background: var(--accent-2); }
button.ghost { background: transparent; border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }

input {
  font: inherit; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); flex: 1; min-width: 0;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.center { max-width: 420px; margin: 12vh auto; text-align: center; }
.center h1 { margin: 0 0 6px; }
.center button { width: 100%; margin-top: 14px; }
#enroll-row { margin-top: 12px; }
#enroll-row input { width: 100%; text-align: center; letter-spacing: 3px; text-transform: uppercase; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 8px; padding: 12px 16px 0; }
.tabs button { border-radius: 10px 10px 0 0; background: transparent; color: var(--muted); }
.tabs button.active { color: var(--text); background: var(--panel); border-bottom: 2px solid var(--accent); }

.tab { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 14px 16px; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

#terminal { flex: 1; min-height: 240px; background: #0b0e14; border: 1px solid var(--border); border-radius: 10px; padding: 6px; overflow: hidden; }
.session-term { flex: 1; min-height: 180px; background: #0b0e14; border: 1px solid var(--border); border-radius: 10px; padding: 6px; overflow: hidden; cursor: text; }

.session-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px; cursor: pointer;
}
.session-row:hover { background: var(--panel-2); }
.session-row .dot { flex: none; }
.session-row .s-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.session-row .s-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .s-dir { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .s-status { flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.online { background: #4caf50; }
.dot.starting { background: #e0a52e; }
.dot.exited { background: #555; }

/* Status badges */
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; text-transform: lowercase;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.online { color: #7fdc86; border-color: #2c5a30; background: #15291a; }
.badge.starting { color: #f0c463; border-color: #5a4a1e; background: #2a2412; }
.badge.exited { color: #9aa3b2; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; padding: 16px; z-index: 20; }
.modal-body { margin: auto; width: min(520px, 100%); max-height: 90vh; overflow: auto; position: relative; }
.close { position: absolute; top: 10px; right: 10px; }
.qr { display: flex; justify-content: center; margin: 8px 0; }
.qr img { width: 220px; height: 220px; border-radius: 10px; background: #fff; padding: 8px; }
.link { display: block; text-align: center; color: var(--accent); margin: 8px 0 14px; font-weight: 600; text-decoration: none; }
#modal-stop { width: 100%; margin-top: 12px; }

/* ---- Connection status ---- */
.spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn[data-state="connected"] .dot { background: #4caf50; }
.conn[data-state="connecting"] .dot { background: #e0a52e; }
.conn[data-state="disconnected"] .dot { background: var(--danger); }

/* ---- Working-directory bar + breadcrumb ---- */
.cwd-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  border-bottom: 1px solid var(--border); background: var(--panel); overflow-x: auto; }
.cwd-icon { flex: none; }
.breadcrumb { display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.crumb { background: transparent; padding: 4px 7px; color: var(--accent); border-radius: 6px; font-size: 13px; }
.crumb:hover { background: var(--panel-2); }
.crumb-sep { color: var(--muted); }

/* ---- Hints / empty states / code ---- */
.hint { font-size: 12.5px; margin: 6px 0 10px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; font-family: ui-monospace, monospace; }
.empty { text-align: center; padding: 26px 12px; }

/* ---- Terminal input row ---- */
.term-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.term-form input { flex: 1; }
.term-prompt { font-family: ui-monospace, monospace; color: var(--accent); font-size: 13px;
  white-space: nowrap; max-width: 38%; overflow: hidden; text-overflow: ellipsis; }
button.busy { opacity: .7; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---- Files browser ---- */
.files-toolbar { align-items: center; }
.files-list { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 5px; }
.file-row { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 11px 12px; }
.file-row:hover { background: var(--panel-2); }
.file-row .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row.dir .fn { font-weight: 500; }
.fsz { font-size: 12px; }
.fchev { font-size: 18px; line-height: 1; }

/* ---- File viewer ---- */
.file-title { font-family: ui-monospace, monospace; font-size: 14px; word-break: break-all; padding-right: 40px; }
.file-content { background: #0b0e14; border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  overflow: auto; max-height: 62vh; font: 12px/1.5 ui-monospace, monospace; white-space: pre; }

/* ---- Toasts ---- */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(420px, 92vw); }
.toast { padding: 11px 14px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(8px);
  transition: opacity .25s, transform .25s; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #3a1618; border: 1px solid var(--danger); color: #ffd7d9; }
.toast.info { background: var(--panel-2); border: 1px solid var(--border); }

/* ---- Working-dir label ---- */
.cwd-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  background: var(--panel-2); padding: 3px 8px; border-radius: 6px; flex: none; white-space: nowrap; }

/* ---- Session modal (interactive, resizable) ---- */
.modal-body.wide {
  display: flex; flex-direction: column;
  width: min(780px, 96vw); height: min(76vh, 720px);
  min-width: 340px; min-height: 420px; max-width: 96vw; max-height: 92vh;
  resize: both; overflow: auto;
}
.modal-body.wide > * { flex: none; }
.modal-body.wide > .mpane { flex: 1; min-height: 0; }
.mpane { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
.mpane > .session-term { flex: 1; }

/* Modal Control/Commands tabs */
.modal-tabs { display: flex; gap: 6px; margin: 4px 0 10px; }
.modal-tabs button { background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 14px; font-size: 13px; }
.modal-tabs button.active { color: var(--text); background: var(--panel-2); border-color: var(--accent); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding-right: 40px; }
.modal-head h2 { margin: 0; }
.link-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.link-row .link { margin: 0; }
button.small { padding: 6px 10px; font-size: 13px; }
.mono-hint { margin: 8px 0 0; font-size: 11.5px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions button { flex: 1; }

/* ---- Demos ---- */
.demo-row { display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px; }
.demo-row .s-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.demo-open { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; }
.demo-del { padding: 6px 10px; flex: none; }
.chk { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.chk input { flex: none; width: auto; }

/* ---- Add / invite device ---- */
.block { width: 100%; }
.linklike { background: transparent; border: 0; color: var(--accent); text-decoration: underline;
  width: 100%; margin-top: 10px; font-size: 13px; cursor: pointer; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.invite-out { margin: 10px 0 4px; }
.code-badge { font: 700 22px/1 ui-monospace, monospace; letter-spacing: 4px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--accent); color: var(--text);
  border-radius: 10px; padding: 14px; user-select: all; }
