:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e5ea;
  --accent: #2563eb; --ok: #16a34a; --bad: #dc2626; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); }
button {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.small { padding: 2px 8px; font-size: 12px; }
button.danger { color: var(--bad); }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
label { display: block; margin: 8px 0; }
label.small { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
label.small select { width: auto; }

.login { min-height: 100vh; display: grid; place-items: center; }
.note { background: #eef4ff; border: 1px solid #c7d7fe; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.qr { display: block; margin: 8px auto; width: 220px; height: 220px; image-rendering: pixelated; }
code.secret { font-size: 14px; letter-spacing: 1px; word-break: break-all; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.inline-form input, .inline-form select { width: auto; }
.row-actions { white-space: nowrap; }
#userRows select { width: auto; min-width: 96px; }
.row-actions button { margin-left: 4px; }
.pill-s { display: inline-block; font-size: 11px; padding: 0 6px; margin-left: 6px; border-radius: 99px; background: #e5e7eb; }
.pill-s.bad { background: #fee2e2; color: var(--bad); }
.warn-text { color: #a16207; }
.dot.inline { display: inline-block; vertical-align: middle; }
.dot.on { background: var(--ok); }
#updatesDialog .button-like { background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 7px; cursor: pointer; margin: 0; }
.card { background: var(--panel); padding: 28px; border-radius: var(--radius); width: 320px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.card h1 { margin: 0 0 4px; }
.card button { width: 100%; margin-top: 8px; }

.topbar { display: flex; gap: 10px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.hint { margin: 12px 16px 0; font-size: 13px; }
.banner { margin: 12px 16px 0; padding: 10px 14px; background: #eef4ff; border: 1px solid #c7d7fe; border-radius: var(--radius); display: flex; gap: 8px; align-items: center; }
code.big { font-size: 20px; letter-spacing: 2px; font-weight: 700; }

.board { display: flex; gap: 14px; padding: 14px 16px; overflow-x: auto; align-items: flex-start; }
.column { background: #eceef2; border-radius: var(--radius); padding: 10px; min-width: 260px; width: 260px; min-height: 140px; border: 2px dashed transparent; }
.column.drop { border-color: var(--accent); background: #e4ecfd; }
.column-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.column-head > span { flex: none; white-space: nowrap; }
.column h2 { font-size: 14px; margin: 2px 0 8px; display: flex; gap: 6px; align-items: center; }
.count { background: #d6dae2; border-radius: 99px; padding: 0 7px; font-size: 11px; }
.empty { text-align: center; padding: 18px 0; }
.device { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.device-head { display: flex; align-items: center; gap: 6px; }
.device-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b4b9c3; flex: none; }
.device.online .dot { background: var(--ok); }
.device-actions { display: flex; justify-content: space-between; margin-top: 8px; }

dialog { border: none; border-radius: var(--radius); width: min(900px, 95vw); max-height: 80vh; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

/* viewer */
body.viewer { background: #111318; color: #e8eaf0; height: 100vh; display: flex; flex-direction: column; }
body.viewer .topbar { background: #1a1d24; border-color: #2a2e38; }
body.viewer select, body.viewer input { background: #22262f; color: inherit; border-color: #333845; }
body.viewer button.ghost { color: inherit; border-color: #333845; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #333845; }
.pill.ok { background: var(--ok); color: #fff; }
.pill.bad { background: var(--bad); color: #fff; }
.viewer-body { flex: 1; display: flex; min-height: 0; }
.screen-wrap { flex: 1; position: relative; display: grid; place-items: center; padding: 12px; min-height: 0; }
#screen { max-width: 100%; max-height: calc(100vh - 80px); background: #000; cursor: crosshair; touch-action: none; border-radius: 4px; }
.screen-overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #aab; font-size: 15px; pointer-events: none; text-align: center; padding: 20px; }
.controls { width: 220px; padding: 12px; border-left: 1px solid #2a2e38; display: flex; flex-direction: column; gap: 8px; }
.controls button { width: 100%; }
.screen-wrap.typing #screen { box-shadow: 0 0 0 2px var(--ok); }
.kbd-sink { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  resize: none; overflow: hidden; pointer-events: none; }
.toast { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); background: #2a2e38; color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.4); pointer-events: none; }
.kbd { border-radius: 8px; padding: 8px 10px; font-weight: 600; font-size: 14px; }
.kbd .small { font-weight: 400; }
.kbd.on { background: rgba(22,163,74,.18); color: #86efac; border: 1px solid #166534; }
.kbd.off { background: #22262f; color: #9aa1ad; border: 1px solid #333845; }
.files-btn { background: #1f2937; border-color: #3b4252; }
.screen-wrap.drop { outline: 3px dashed var(--accent); outline-offset: -8px; }

/* files dialog (dark, matches the viewer) */
dialog.files { background: #1a1d24; color: #e8eaf0; width: min(960px, 96vw); max-height: 88vh; padding: 18px; }
dialog.files::backdrop { background: rgba(0,0,0,.55); }
dialog.files h2 { font-size: 17px; margin: 0; }
dialog.files section { margin-top: 14px; }
dialog.files code { color: #c7d2fe; }
.send-box { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px;
  border: 1px dashed #3b4252; border-radius: 8px; }
.send-box.drop { border-color: var(--accent); background: rgba(37,99,235,.12); }
.button-like { display: inline-block; margin: 0; background: var(--accent); color: #fff; padding: 6px 12px;
  border-radius: 7px; cursor: pointer; white-space: nowrap; }
.browse-bar { display: flex; gap: 6px; align-items: center; }
.cur-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #22262f;
  padding: 4px 8px; border-radius: 6px; font-size: 12px; }
.warn { background: rgba(234,179,8,.15); border: 1px solid #854d0e; color: #fde68a; padding: 6px 10px; border-radius: 6px; margin-top: 8px; }
.file-list { margin-top: 8px; max-height: 42vh; overflow: auto; border: 1px solid #2a2e38; border-radius: 8px; }
.file-list > p { padding: 10px; margin: 0; }
.file-row { display: grid; grid-template-columns: 24px 1fr 90px 170px 110px; gap: 8px; align-items: center;
  padding: 5px 10px; border-bottom: 1px solid #23272f; font-size: 13px; }
.file-row:hover { background: #20242c; }
.f-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; }
.file-row.dir .f-name { color: #93c5fd; text-decoration: none; font-weight: 600; }
.f-size, .f-date { font-size: 12px; text-align: right; }
.transfers { list-style: none; padding: 0; margin: 6px 0 0; max-height: 18vh; overflow: auto; font-size: 13px; }
.transfers li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid #23272f; }
.t-status.ok { color: #86efac; }
.t-status.error { color: #fca5a5; }

.help { margin: 8px 0 0; color: #aab1bd; }

/* ===================== phone / touch layout (switches on automatically) ===================== */
.mobile-bar, .key-bar { display: none; }
#screen { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

@media (max-width: 820px), (pointer: coarse) and (max-width: 1100px) {
  /* viewer: the till fills the screen, controls move to a bottom bar */
  body.viewer { height: var(--vvh, 100dvh); overflow: hidden; touch-action: manipulation;
    -webkit-user-select: none; user-select: none; }
  body.viewer .topbar { padding: 6px 10px; gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); }
  body.viewer .topbar label.small, body.viewer #stats { display: none; }
  body.viewer #title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
  body.viewer .controls { display: none; }
  body.viewer .viewer-body { flex-direction: column; }
  body.viewer .screen-wrap { padding: 4px; }
  body.viewer #screen { max-height: calc(var(--vvh, 100dvh) - 44px - 56px - 12px); border-radius: 2px; }
  body.viewer.kbd-open #screen { max-height: calc(var(--vvh, 100dvh) - 44px - 56px - 48px - 12px); }

  .mobile-bar { display: flex; justify-content: space-around; gap: 4px; padding: 6px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom)); background: #1a1d24; border-top: 1px solid #2a2e38; }
  .mobile-bar button { flex: 1; font-size: 22px; padding: 8px 0; min-height: 44px; background: #22262f; border-color: #333845; }
  .mobile-bar button.active { background: var(--ok); border-color: var(--ok); }
  .key-bar { display: flex; gap: 4px; padding: 4px 8px; background: #22262f; }
  .key-bar button { flex: 1; font-size: 18px; min-height: 40px; padding: 4px 0; background: #2f3440; border-color: #3b4252; }
  /* iOS zooms into inputs under 16px; keep the hidden keyboard sink at 16px and out of the layout */
  .kbd-sink { position: fixed; bottom: 0; left: 0; font-size: 16px; }
  .toast { top: 8px; max-width: 92vw; }

  /* Files sheet */
  dialog.files { width: 100vw; max-width: 100vw; max-height: var(--vvh, 100dvh); height: var(--vvh, 100dvh);
    margin: 0; border-radius: 0; padding: 12px; }
  .send-box { flex-direction: column; align-items: stretch; }
  .file-row { grid-template-columns: 22px 1fr 64px 96px; font-size: 14px; padding: 8px; }
  .file-row .f-date { display: none; }
  .file-list { max-height: 45vh; }

  /* dashboard */
  .topbar { flex-wrap: wrap; }
  .topbar .spacer { display: none; }
  .topbar button { padding: 6px 9px; font-size: 14px; }
  .hint { display: none; }
  .board { flex-direction: column; padding: 10px; }
  .column { width: 100%; min-width: 0; }
  .device-actions button { min-height: 40px; padding: 6px 16px; }
  dialog { width: 96vw; max-width: 96vw; padding: 12px; }
  dialog table { display: block; overflow-x: auto; }
  .inline-form { flex-wrap: wrap; }
  .card { width: min(320px, 92vw); }
}
.help dt { font-weight: 600; color: #d6dae2; margin-top: 6px; }
.help dd { margin: 2px 0 0; }
