/* ============================================================================
   Web CC Terminal - compact Fluent-inspired workspace, light and dark.
   ========================================================================== */

@font-face {
  font-family: "CC UI Sans";
  src: url("/vendor/fonts/DejaVuSans.ttf?v=1") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "CC Terminal Mono";
  src: url("/vendor/fonts/DejaVuSansMono.ttf?v=1") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "CC Terminal Symbols";
  src: url("/vendor/fonts/DejaVuSans.ttf?v=1") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+2190-2BFF, U+FFF9-FFFD, U+1F300-1FAFF;
}

:root, [data-theme="light"] {
  --win-bg:       #E9E9EB;
  --sidebar-bg:   rgba(245,245,247,0.75);
  --content-bg:   #FFFFFF;
  --raised:       #FFFFFF;
  --text:         #1D1D1F;
  --text-2:       #6E6E73;
  --text-3:       #9A9AA0;
  --separator:    rgba(0,0,0,0.10);
  --separator-2:  rgba(0,0,0,0.06);
  --hover:        rgba(0,0,0,0.05);
  --hover-2:      rgba(0,0,0,0.08);
  --accent:       #007AFF;
  --accent-fg:    #FFFFFF;
  --accent-soft:  rgba(0,122,255,0.12);
  --control-bg:   #FFFFFF;
  --control-bd:   rgba(0,0,0,0.14);
  --green:        #34C759;
  --grey:         #C2C2C7;
  --red:          #FF3B30;
  --shadow:       0 18px 50px rgba(0,0,0,0.22);
  --blur:         saturate(180%) blur(28px);
  --term-bg:      #FFFFFF;
}
[data-theme="dark"] {
  --win-bg:       #1B1B1D;
  --sidebar-bg:   rgba(44,44,46,0.66);
  --content-bg:   #1E1E20;
  --raised:       #2C2C2E;
  --text:         #F5F5F7;
  --text-2:       #A1A1A6;
  --text-3:       #6E6E73;
  --separator:    rgba(255,255,255,0.12);
  --separator-2:  rgba(255,255,255,0.07);
  --hover:        rgba(255,255,255,0.06);
  --hover-2:      rgba(255,255,255,0.10);
  --accent:       #0A84FF;
  --accent-fg:    #FFFFFF;
  --accent-soft:  rgba(10,132,255,0.22);
  --control-bg:   rgba(255,255,255,0.09);
  --control-bd:   rgba(255,255,255,0.14);
  --green:        #32D74B;
  --grey:         #5A5A5E;
  --red:          #FF453A;
  --shadow:       0 18px 50px rgba(0,0,0,0.55);
  --blur:         saturate(180%) blur(28px);
  --term-bg:      #1E1E1E;
}

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: "CC Terminal Mono", "CC Terminal Symbols", "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, "Segoe UI Symbol", "Segoe UI Emoji", "Microsoft YaHei UI", monospace;
  --sb-w: 256px;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--win-bg);
  color: var(--text);
  font-size: 12.5px; line-height: 1.38;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  letter-spacing: 0;
}
button { font-family: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 1px; border-radius: 6px; }
::selection { background: var(--accent-soft); }

#app { display: flex; flex-direction: column; height: 100dvh; }
#titlebar {
  flex: none; height: 38px; display: flex; align-items: center; padding: 0 16px; position: relative;
  background: var(--sidebar-bg); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--separator);
}
.traffic { display: flex; gap: 8px; z-index: 1; }
.tl { position: relative; width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.16); transition: filter .12s ease; }
.tl::after { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; font-weight: 700; line-height: 1; color: rgba(0,0,0,0.55); opacity: 0; transition: opacity .1s ease; }
.traffic:hover .tl.red::after { content: "×"; opacity: 1; }
.traffic:hover .tl.yellow::after { content: "−"; opacity: 1; }
.traffic:hover .tl.green::after { content: "+"; opacity: 1; }
.tl.red { background: #FF5F57; } .tl.yellow { background: #FEBC2E; } .tl.green { background: #28C840; cursor: pointer; }
.titlebar-title { position: absolute; left: 0; right: 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--text-2); pointer-events: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 90px; }
#body {
  flex: 1; display: grid; grid-template-columns: var(--sb-w) 1fr; min-height: 0;
  transition: grid-template-columns .22s cubic-bezier(.32,.72,0,1);
}
#sidebar { min-width: 0; overflow: hidden; }
/* collapsed sidebar (desktop) */
body.sb-collapsed #body { grid-template-columns: 0 1fr; }
body.sb-collapsed #sidebar { border-right-width: 0; }
/* titlebar sidebar toggle — sits just right of the traffic lights, macOS style */
.tb-btn {
  z-index: 1; margin-left: 14px; width: 26px; height: 22px; border-radius: 6px;
  border: none; background: none; cursor: pointer; color: var(--text-2);
  font-size: 13px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s ease, color .12s ease;
}
.tb-btn:hover { background: var(--hover); color: var(--text); }
.tb-btn:active { background: var(--hover-2); }
#scrim { display: none; }

/* scrollbars — macOS overlay style */
* { scrollbar-width: thin; scrollbar-color: var(--separator) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--separator); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ---- sidebar (vibrancy source list) ------------------------------------- */
#sidebar {
  background: var(--sidebar-bg);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-right: 1px solid var(--separator);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 14px 12px 8px; }
.logo { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; margin: 0 4px 10px; color: var(--text); }
.sidebar-toolbar {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 6px;
}
.toolbar-btn {
  min-width: 0; height: 34px; cursor: pointer; border: 0.5px solid var(--control-bd);
  background: color-mix(in srgb, var(--control-bg) 88%, transparent); color: var(--text);
  font-weight: 500; font-size: 12px; padding: 0 10px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.25), 0 1px 1px rgba(0,0,0,0.035);
  transition: background .12s ease, border-color .12s ease;
}
.toolbar-btn:hover { background: var(--hover); }
.toolbar-btn:active { background: var(--hover-2); }
.toolbar-btn.primary { background: var(--control-bg); }
.toolbar-ic { font-size: 14px; line-height: 1; color: var(--text-2); }
.new-btn {
  width: 100%; cursor: pointer; border: 0.5px solid var(--control-bd);
  background: var(--control-bg); color: var(--text); font-weight: 500; font-size: 12px;
  padding: 7px 12px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.04);
  transition: background .12s ease;
}
.new-btn:hover { background: var(--hover); }
.new-btn:active { background: var(--hover-2); }
.new-btn.lg { width: auto; padding: 9px 22px; background: var(--accent); color: var(--accent-fg); border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.new-btn.lg:hover { filter: brightness(1.05); background: var(--accent); }
.empty-inner .new-btn.lg { margin: 0 auto; }
.new-btn.sub { margin-top: 6px; padding: 6px 12px; font-size: 12px; font-weight: 500; color: var(--text-2); box-shadow: none; }
.new-btn.sub:hover { color: var(--text); }

.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px; }

/* project groups (directory-tree style) */
.chat-group { margin-bottom: 3px; }
.group-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 6px; cursor: pointer; border-radius: 6px; color: var(--text-2); font-size: 11px; font-weight: 600; user-select: none; letter-spacing: 0; }
.group-head:hover { background: var(--hover); }
.group-caret { font-size: 9px; color: var(--text-3); transition: transform .12s ease; width: 10px; text-align: center; flex: none; }
.group-head.collapsed .group-caret { transform: rotate(-90deg); }
.group-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-rename { border: 0; background: none; cursor: pointer; color: var(--text-3); font-size: 11px; padding: 2px 5px; border-radius: 5px; opacity: 0; transition: opacity .12s ease; flex: none; }
.group-head:hover .group-rename { opacity: 1; }
.group-rename:hover { background: var(--hover-2); color: var(--text); }
.group-count { font-size: 10.5px; font-weight: 500; color: var(--text-3); background: var(--hover-2); border-radius: 9px; padding: 0 6px; min-width: 16px; text-align: center; }
.group-icon { font-size: 11px; flex: none; }
.group-head.manual .group-name { color: var(--accent); }
.group-del { border: 0; background: none; cursor: pointer; color: var(--text-3); font-size: 11px; padding: 2px 5px; border-radius: 5px; opacity: 0; transition: opacity .12s ease; flex: none; }
.group-head:hover .group-del { opacity: 1; }
.group-del:hover { background: var(--hover-2); color: var(--red); }
.group-empty { color: var(--text-3); font-size: 11px; padding: 6px 10px 8px 24px; font-style: italic; }
.chat-group .chat-item { margin-left: 8px; }

/* group picker (move-to-group) */
.pick-list { display: flex; flex-direction: column; gap: 3px; margin: 4px 0 14px; max-height: 240px; overflow-y: auto; }
.pick-row { text-align: left; border: 0.5px solid var(--separator); background: var(--control-bg); color: var(--text); cursor: pointer; font-size: 13px; padding: 8px 12px; border-radius: 8px; }
.pick-row:hover { background: var(--hover); }
.pick-row.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.chat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 7px; cursor: pointer; margin-bottom: 1px; position: relative;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent); }
.chat-item.active .chat-title { color: #fff; }
.chat-item.active .chat-sub { color: rgba(255,255,255,0.78); }
.chat-item.active .status-dot.green { box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.green { background: var(--green); }
.status-dot.blue { background: var(--accent); }
.status-dot.yellow { background: #FFCC00; }
.status-dot.grey  { background: var(--grey); }

.chat-meta { min-width: 0; flex: 1; }
.chat-title { font-size: 12.5px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.stopped .chat-title { color: var(--text-2); }
.chat-sub { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-actions { display: flex; gap: 1px; flex: none; opacity: 0; transition: opacity .12s ease; }
.chat-item:hover .chat-actions, .chat-item.active .chat-actions { opacity: 1; }
.mini { border: 0; background: none; cursor: pointer; color: var(--text-2); font-size: 11px; padding: 3px 7px; border-radius: 6px; white-space: nowrap; }
.chat-item.active .mini { color: rgba(255,255,255,0.85); }
.mini:hover { background: var(--hover-2); color: var(--text); }
.chat-item.active .mini:hover { background: rgba(255,255,255,0.18); color: #fff; }
.mini.danger:hover { color: var(--red); }
.chat-item.active .mini.danger:hover { color: #fff; background: rgba(255,255,255,0.2); }
.chat-empty { color: var(--text-3); font-size: 12px; padding: 18px 12px; text-align: center; line-height: 1.6; }

/* presence */
.side-presence { position: relative; border-top: 1px solid var(--separator); }
.presence-btn { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 0; cursor: pointer; padding: 9px 14px; color: var(--text-2); font-size: 12px; }
.presence-btn:hover { background: var(--hover); }
.presence-btn b { color: var(--text); font-weight: 600; }
.presence-btn .caret { margin-left: auto; font-size: 10px; color: var(--text-3); }
.presence-btn.alert { color: var(--accent); }
.pdot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--green); }
.pdot.alert { background: var(--red); }
.presence-panel { position: absolute; left: 8px; right: 8px; bottom: 44px; background: var(--raised); border: 0.5px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow); padding: 9px; z-index: 30; }
.pp-head { font-size: 11px; color: var(--text-2); font-weight: 600; margin: 2px 4px 8px; }
.pp-list { display: flex; flex-direction: column; gap: 3px; max-height: 210px; overflow-y: auto; }
.pp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 7px; font-family: var(--mono); font-size: 11.5px; }
.pp-row.other { background: var(--accent-soft); }
.pp-ip { color: var(--text); overflow: hidden; text-overflow: ellipsis; flex: none; }
.pp-dev { flex: 1; min-width: 0; color: var(--text-3); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-tags { display: flex; gap: 4px; flex: none; }
.tag { font-family: var(--font); font-size: 10.5px; padding: 1px 7px; border-radius: 10px; background: var(--hover-2); color: var(--text-2); }
.tag.you { background: rgba(52,199,89,0.18); color: var(--green); }
.pp-note { font-size: 10.5px; color: var(--text-3); margin: 8px 4px 2px; line-height: 1.45; }

.side-foot { display: flex; gap: 4px; padding: 7px 10px; border-top: 1px solid var(--separator); }
.link-btn { flex: 1; border: 0; background: none; cursor: pointer; color: var(--text-2); font-size: 11.5px; padding: 6px 4px; border-radius: 7px; white-space: nowrap; }
.link-btn:hover { background: var(--hover); color: var(--text); }

/* ---- main --------------------------------------------------------------- */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--content-bg); }
#topbar { display: none; }
.icon-btn { border: 0.5px solid var(--control-bd); background: var(--control-bg); cursor: pointer; color: var(--text); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 15px; flex: none; }
.icon-btn:hover { background: var(--hover); }

/* empty state */
.empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px; }
.empty-inner { text-align: center; max-width: 34em; }
.empty-mark { width: 56px; height: 56px; margin: 0 auto 20px; border-radius: 15px; background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000)); display: grid; place-items: center; font-size: 26px; color: #fff; box-shadow: 0 8px 22px -8px var(--accent); }
.empty h1 { font-size: 20px; font-weight: 600; letter-spacing: 0; margin: 0 0 8px; }
.empty p { color: var(--text-2); margin: 0 0 22px; font-size: 13px; }

/* terminal view */
#term-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#term-header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 14px; border-bottom: 1px solid var(--separator);
  background: var(--sidebar-bg); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
#term-title { font-weight: 600; font-size: 12.5px; flex: none; }
#term-path { font-family: var(--mono); font-size: 11px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#term-header .spacer { flex: 1; }
.conn { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.conn.connected { color: var(--green); }
.conn.connecting, .conn.reconnecting { color: var(--accent); }
.conn.closed { color: var(--text-3); }

.sizer { display: inline-flex; align-items: center; border: 0.5px solid var(--control-bd); border-radius: 7px; overflow: hidden; background: var(--control-bg); }
.sizer button { background: none; border: 0; color: var(--text); width: 26px; height: 26px; cursor: pointer; font-size: 14px; }
.sizer button:hover { background: var(--hover); }
.sizer .val { font-family: var(--mono); font-size: 11px; color: var(--text-2); min-width: 28px; text-align: center; }

.hdr-btn { border: 0.5px solid var(--control-bd); background: var(--control-bg); color: var(--text-2); cursor: pointer; font-size: 11.5px; padding: 5px 12px; border-radius: 7px; }
.hdr-btn:hover { background: var(--hover); color: var(--text); }
.hdr-btn.danger { color: var(--red); }
.hdr-btn.danger:hover { border-color: var(--red); background: rgba(255,59,48,0.10); color: var(--red); }

/* ---- split panes ---- */
.panes {
  flex: 1; min-height: 0; min-width: 0; display: grid; gap: 6px; padding: 6px;
  background: var(--panel-2, rgba(127,127,127,0.06));
  position: relative;   /* dividers are positioned over the gaps */
}
/* draggable dividers — cells keep summing to the container, so no blank strips */
.gutter { position: absolute; z-index: 5; touch-action: none; }
.gutter.v { width: 11px; margin-left: -5.5px; cursor: col-resize; }
.gutter.h { height: 11px; margin-top: -5.5px; cursor: row-resize; }
.gutter::after {
  content: ""; position: absolute; border-radius: 3px;
  background: transparent; transition: background .12s ease;
}
.gutter.v::after { top: 0; bottom: 0; left: 4px; right: 4px; }
.gutter.h::after { left: 0; right: 0; top: 4px; bottom: 4px; }
.gutter::after { background: var(--separator, rgba(127,127,127,.35)); }   /* faint, so it's findable on touch */
.gutter:hover::after, .gutter.dragging::after { background: var(--accent); }
body.gutter-dragging { user-select: none; -webkit-user-select: none; }
body.gutter-dragging .pane { pointer-events: none; }
/* single cell, and the fallback before JS sets data-eff */
.panes { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.panes[data-n="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
/* wide: side-by-side */
.panes[data-eff="row"][data-n="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.panes[data-eff="row"][data-n="3"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.panes[data-eff="row"][data-n="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
/* narrow (or forced): stack top-to-bottom */
.panes[data-eff="col"] { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 1fr; }
.pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: var(--term-bg); border-radius: 8px; border: 1px solid transparent;
  container-type: inline-size;
}
.panes[data-n="1"] > .pane { border-radius: 6px; }
.pane.focused { border-color: var(--accent); }
.pane-bar {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px; font-size: 11px;
  border-bottom: 1px solid var(--border, rgba(127,127,127,.25));
  background: var(--panel, rgba(127,127,127,0.08)); cursor: pointer; user-select: none;
}
.panes[data-n="1"] > .pane > .pane-bar { display: none; }
.pane-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-conn { margin-left: auto; opacity: .7; white-space: nowrap; }
.pane-x { border: none; background: none; cursor: pointer; opacity: .55; font-size: 12px; padding: 0 2px; color: inherit; }
.pane-x:hover { opacity: 1; }
.pane-swap { border: none; background: none; cursor: pointer; opacity: .55; font-size: 12px; padding: 0 2px; color: inherit; }
.pane-swap:hover { opacity: 1; }
/* the title bar doubles as a drag handle for swapping cells */
.pane-bar { cursor: grab; }
.pane-bar:active { cursor: grabbing; }
.pane.dragging { opacity: .5; }
.pane.drop-target { outline: 2px dashed var(--accent); outline-offset: -3px; }
.pane-host { flex: 1; min-height: 0; min-width: 0; padding: 6px 8px; }
.quota-battery {
  display: inline-flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 102px;
  height: 32px;
  padding: 0 4px;
  margin: 0 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}
.quota-battery-main { display: flex; align-items: center; justify-content: center; gap: 4px; height: 20px; line-height: 20px; }
.quota-battery-icon { position: relative; display: block; width: 20px; height: 20px; flex: none; }
.quota-battery-icon .ui-icon { display: block; width: 100%; height: 100%; }
.quota-battery-icon i { position: absolute; left: 16.6667%; top: 33.3333%; width: calc(var(--battery-level, 0%) / 2); height: 33.3333%; background: currentColor; border-radius: 1px; }
.quota-battery-value { min-width: 34px; text-align: right; }
.quota-battery-reset { font-size: 10px; line-height: 11px; color: var(--text-3); }
.quota-battery.warning .quota-battery-main { color: var(--warning); }
.quota-battery.critical .quota-battery-main { color: var(--red); }
.quota-battery.is-stale .quota-battery-value::after { content: "*"; padding-left: 1px; }
.quota-battery:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) { .quota-battery:hover { background: var(--hover); color: var(--text); } }
@media (max-width: 820px) { .quota-battery { width: 96px; height: 40px; margin: 0; } }
.pane-host.drag-over { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; }
.pane-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; font-size: 13px; opacity: .6; text-align: center; padding: 10px; cursor: pointer;
}
.pane-empty .big { font-size: 26px; }
/* hard floor: never squeeze two columns onto a phone, whatever the setting */
@media (max-width: 560px) {
  .panes[data-n="2"], .panes[data-n="3"], .panes[data-n="4"] { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 1fr; }
}

/* image → terminal modal */
.img-box { width: min(520px, 92vw); }
.img-drop {
  margin: 4px 0 10px; padding: 26px 16px; border-radius: 12px; cursor: pointer;
  border: 2px dashed var(--border, #c8c8cc); background: var(--panel-2, rgba(127,127,127,0.06));
  text-align: center; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.img-drop:hover, .img-drop:focus { border-color: var(--accent); outline: none; }
.img-drop.drag-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.img-drop-ic { font-size: 30px; line-height: 1; }
.img-drop-main { font-weight: 600; font-size: 14px; }
.img-drop-sub { font-size: 12px; opacity: .7; }
.img-drop-sub b { opacity: 1; }
.img-previews { display: flex; flex-wrap: wrap; gap: 8px; }
.img-previews:empty { display: none; }
.img-thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border, #ccc); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-thumb .rm {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 18px; cursor: pointer; padding: 0;
}
.img-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.img-hint { font-size: 12px; opacity: .65; }
.reference-box { width: min(520px, 100%); display: flex; flex-direction: column; min-height: 0; }
.reference-drop { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 64px; width: 100%; margin: 4px 0 10px; padding: 12px; border: 1px dashed var(--separator); border-radius: 4px; background: var(--layer-2); color: var(--text); cursor: pointer; }
.reference-drop:hover, .reference-drop:focus-visible, .reference-drop.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.reference-drop:disabled { opacity: .55; cursor: default; }
.reference-list { overflow: auto; min-height: 0; max-height: min(40vh, 320px); }
.reference-row { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 5px 2px; border-bottom: 1px solid var(--separator); }
.reference-file-icon { flex: none; color: var(--text-2); }
.reference-file-details { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.reference-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-file-meta { color: var(--text-3); font-size: 11px; }
.reference-row .icon-btn { width: 30px; height: 30px; }
.reference-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 12px; }
#reference-state { flex: 1; min-width: 0; color: var(--text-2); font-size: 12px; overflow-wrap: anywhere; }
.reference-actions { display: flex; flex: none; align-items: center; gap: 6px; }
#reference-copy[hidden] { display: none; }
@media (max-width: 560px) { .reference-footer { align-items: stretch; flex-direction: column; } .reference-actions { justify-content: flex-end; } }
.btn-sm.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-sm.primary:disabled { opacity: .45; cursor: default; }

/* aux key bar — Esc & friends for keyboards lacking them (iPad, phones) */
#auxbar { display: none; }
@media (any-pointer: coarse) { #auxbar { display: flex; } }   /* iPad / touch always */
body.aux-shown #auxbar { display: flex !important; }
body.aux-hidden #auxbar { display: none !important; }
.auxbar { gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--term-bg); border-top: 1px solid var(--separator); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.keycap { flex: none; font-family: var(--mono); font-size: 12.5px; min-width: 40px; height: 38px; padding: 0 11px; border: 0.5px solid var(--control-bd); border-radius: 9px; background: var(--control-bg); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; user-select: none; -webkit-user-select: none; }
.keycap:active { background: var(--hover-2); }
.keycap.armed { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- modal (macOS sheet) ------------------------------------------------ */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.28); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.modal-box { width: 540px; max-width: 100%; max-height: 84vh; background: var(--content-bg); border: 0.5px solid var(--separator); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--separator-2); }
.modal-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.crumb { padding: 9px 16px; font-family: var(--mono); font-size: 11.5px; color: var(--text-2); border-bottom: 1px solid var(--separator-2); display: flex; flex-wrap: wrap; gap: 2px 6px; word-break: break-all; }
.crumb a { color: var(--accent); cursor: pointer; text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.crumb .sep { color: var(--text-3); }

.dir-toolbar { padding: 9px 14px 2px; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.dir-search {
  flex: 1 1 190px; min-width: 0; height: 28px; display: flex; align-items: center; gap: 6px;
  padding: 0 9px; border: 0.5px solid var(--control-bd); border-radius: 7px;
  background: var(--control-bg); color: var(--text-3);
}
.dir-search input {
  min-width: 0; flex: 1; border: 0; outline: none; background: transparent; color: var(--text);
  font: inherit; font-size: 12.5px;
}
.dir-search input::placeholder { color: var(--text-3); }
.btn-sm { font-size: 12px; cursor: pointer; border: 0.5px solid var(--control-bd); background: var(--control-bg); color: var(--text); padding: 5px 11px; border-radius: 7px; box-shadow: 0 1px 1px rgba(0,0,0,0.04); }
.btn-sm:hover { background: var(--hover); }
.btn-sm.hidden { display: none; }

.dir-list { flex: 1; min-height: 130px; overflow-y: auto; padding: 6px; }
.dir-row { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.dir-row:hover { background: var(--hover); }
.dir-row .ic { color: var(--text-3); width: 16px; text-align: center; flex: none; font-size: 11px; }
.dir-row.up .ic { color: var(--accent); }
.dir-row.file { color: var(--text-2); }
.dir-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.row-actions { display: flex; gap: 1px; flex: none; opacity: 0; transition: opacity .12s ease; }
.dir-row:hover .row-actions { opacity: 1; }
.dir-row.up .row-actions { display: none; }
.icon-btn-sm { border: 0; background: none; cursor: pointer; font-size: 13px; padding: 3px 6px; border-radius: 6px; line-height: 1; }
.icon-btn-sm:hover { background: var(--hover-2); }
.dir-empty { color: var(--text-3); font-size: 12px; padding: 16px; text-align: center; }

.modal-foot { border-top: 1px solid var(--separator-2); padding: 12px 16px; }
.cur { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); word-break: break-all; margin-bottom: 10px; }
.mode-row { display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 100%; }
.mode-hint { font-size: 11.5px; font-weight: 500; color: var(--text-2); padding: 0; flex: none; }
.mode-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mode-group { display: inline-flex; align-items: stretch; border-radius: 6px; overflow: hidden; border: 1px solid var(--control-bd); background: var(--control-bg); box-shadow: 0 1px 2px rgba(0,0,0,0.035); }
.mode-group .mode-btn { border: 0; border-right: 1px solid var(--separator-2); border-radius: 0; box-shadow: none; min-height: 30px; padding: 5px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.mode-group .mode-btn:last-child { border-right: 0; }
.mode-group .mode-btn.mode-sub { color: var(--text-2); font-weight: 400; padding: 5px 8px; font-size: 11.5px; }
.mode-btn { border: 0.5px solid var(--control-bd); background: var(--control-bg); color: var(--text); cursor: pointer; font-size: 12px; padding: 6px 12px; border-radius: 6px; }
.mode-btn:hover { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* ---- toast -------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 80; max-width: min(92vw, 460px);
  background: rgba(40,40,42,0.92); color: #fff; -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  padding: 10px 16px; border-radius: 11px; font-size: 13px; line-height: 1.4;
  box-shadow: var(--shadow); word-break: break-word;
}

/* macOS-style alert / prompt dialog (replaces native prompt/confirm) */
.ui-dialog-backdrop { position: fixed; inset: 0; z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 16vh 20px 20px; background: rgba(0,0,0,.30); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.ui-dialog { width: 290px; max-width: 92vw; background: var(--content-bg); border: 0.5px solid var(--separator); border-radius: 14px; box-shadow: var(--shadow); padding: 20px 20px 16px; text-align: center; }
.ui-dialog-icon { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 12px; background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 65%, #000)); display: grid; place-items: center; color: #fff; font-size: 22px; box-shadow: 0 6px 16px -6px var(--accent); }
.ui-dialog-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.ui-dialog-msg { font-size: 12.5px; color: var(--text-2); margin-bottom: 12px; line-height: 1.5; }
.ui-dialog-input { width: 100%; box-sizing: border-box; font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--control-bd); border-radius: 8px; background: var(--control-bg); color: var(--text); margin: 4px 0 14px; }
.ui-dialog-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ui-dialog-btns { display: flex; gap: 8px; }
.ui-btn { flex: 1; cursor: pointer; font-size: 13px; font-weight: 500; padding: 7px 12px; border-radius: 8px; border: 0.5px solid var(--control-bd); background: var(--control-bg); color: var(--text); }
.ui-btn:hover { background: var(--hover); }
.ui-btn.primary { background: var(--accent); color: #fff; border: 0; }
.ui-btn.primary:hover { filter: brightness(1.06); }
.ui-btn.primary.danger { background: var(--red); }

/* macOS login window (token entry) */
.login {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  width: 100vw; height: 100vh; height: 100dvh; min-height: 100dvh; overflow: hidden;
  background:
    radial-gradient(40% 50% at 18% 22%, rgba(96,142,214,0.85), transparent 60%),
    radial-gradient(42% 50% at 82% 14%, rgba(150,104,200,0.80), transparent 60%),
    radial-gradient(48% 52% at 76% 84%, rgba(54,156,166,0.75), transparent 60%),
    radial-gradient(48% 52% at 22% 88%, rgba(46,90,168,0.80), transparent 60%),
    linear-gradient(155deg, #232f56 0%, #2a1f57 100%);
}
body.login-open { overflow: hidden; }
.login::before { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,0.16); }
.login-center { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; margin-top: -7vh; }
.login-avatar {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; font-size: 42px; color: #fff;
  background: rgba(255,255,255,0.16); -webkit-backdrop-filter: blur(24px) saturate(160%); backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid rgba(255,255,255,0.4); box-shadow: 0 10px 34px rgba(0,0,0,0.32), inset 0 1px 1px rgba(255,255,255,0.25);
}
.login-name { color: #fff; font-size: 17px; font-weight: 500; letter-spacing: -0.01em; margin: 15px 0 18px; text-shadow: 0 1px 4px rgba(0,0,0,0.35); }
.login-field {
  position: relative; width: 230px; height: 30px; display: flex; align-items: center;
  background: rgba(255,255,255,0.18); -webkit-backdrop-filter: blur(20px) saturate(150%); backdrop-filter: blur(20px) saturate(150%);
  border: 0.5px solid rgba(255,255,255,0.45); border-radius: 15px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18), inset 0 0.5px 0 rgba(255,255,255,0.25);
}
.login-field input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: #fff; font: inherit; font-size: 13px; text-align: center; padding: 0 32px; letter-spacing: 0.06em; }
.login-field input::placeholder { color: rgba(255,255,255,0.72); letter-spacing: normal; }
.login-go { position: absolute; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer; background: rgba(255,255,255,0.92); color: #2a2a2a; display: grid; place-items: center; font-size: 13px; opacity: 0; transition: opacity .15s ease; }
.login-go:hover { background: #fff; }
.login-hint { color: rgba(255,255,255,0.82); font-size: 12px; margin-top: 18px; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.login-hint.err { color: #ffc9c9; }
.login.shake .login-center { animation: login-shake .45s cubic-bezier(.36,.07,.19,.97); }
@keyframes login-shake { 10%,90%{transform:translateX(-2px)} 20%,80%{transform:translateX(4px)} 30%,50%,70%{transform:translateX(-9px)} 40%,60%{transform:translateX(9px)} }

.hidden { display: none !important; }

/* ============================================================================
   Responsive — sidebar becomes a drawer; aux keys appear on small screens
   ========================================================================== */
@media (max-width: 820px) {
  #titlebar { display: none; }
  #body { grid-template-columns: 1fr; }

  #topbar {
    display: flex; align-items: center; gap: 12px;
    padding: calc(9px + env(safe-area-inset-top)) 14px 9px;
    background: var(--sidebar-bg); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--separator);
  }
  .topbar-title { font-weight: 600; font-size: 14px; }
  .topbar-presence { margin-left: auto; font-size: 12px; color: var(--text-2); }
  .topbar-presence.alert { color: var(--red); font-weight: 600; }
  .topbar-status { font-size: 12px; color: var(--text-2); }

  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    width: min(82vw, var(--sb-w));
    background: var(--content-bg);
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.32,.72,0,1);
    box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top);
  }
  body.drawer-open #sidebar { transform: translateX(0); }
  #scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0); pointer-events: none; transition: background .25s ease; }
  body.drawer-open #scrim { background: rgba(0,0,0,.34); pointer-events: auto; }

  .chat-actions, .row-actions, .group-rename, .group-del { opacity: 1; }   /* no hover on touch */
  #auxbar { display: flex; }
  #term-path, #term-conn { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.hdr-btn.auto-mode { position: relative; }
.hdr-btn.auto-mode::after {
  content: "A"; position: absolute; top: 1px; right: 1px;
  font-size: 8px; line-height: 1; opacity: .65; font-weight: 700;
}

/* ---- GPU monitor -------------------------------------------------------- */
.gpu-box { width: 900px; }
.gpu-head-right { display: flex; align-items: center; gap: 8px; }
.gpu-age { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.gpu-body { padding: 12px 16px; overflow-y: auto; flex: 1; min-height: 160px; }
.gpu-loading, .gpu-err { padding: 18px 4px; color: var(--text-2); font-size: 13px; }
.gpu-err { color: var(--danger, #d93025); }
.gpu-host + .gpu-host { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--separator-2); }
.gpu-host-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; }
.gpu-addr { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.gpu-sum { margin-left: auto; font-size: 11.5px; color: var(--text-2); }
.gpu-del { border: 0; background: none; color: var(--text-2); cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 5px; }
.gpu-del:hover { background: var(--hover-2); color: var(--danger, #d93025); }
.gpu-users { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.gpu-user { font-size: 11px; font-family: var(--mono); padding: 3px 8px; border-radius: 20px; background: var(--control-bg); border: 0.5px solid var(--control-bd); color: var(--text-2); }
.gpu-user b { color: var(--accent); font-weight: 600; }
.gpu-grid { display: grid; align-items: start; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 10px; }
.gpu-card { border: 0.5px solid var(--separator); border-radius: 10px; padding: 9px 11px; background: var(--control-bg); }
.gpu-card.busy { border-color: rgba(52,199,89,.55); }
.gpu-card.held { border-color: rgba(255,159,10,.5); }
.gpu-card-head { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.gpu-idx { font-family: var(--mono); font-size: 11px; min-width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; background: var(--hover-2); color: var(--text-2); }
.gpu-name { font-size: 12px; font-weight: 600; }
.gpu-state { margin-left: auto; font-size: 10.5px; padding: 2px 7px; border-radius: 20px; }
.gpu-state.idle { background: var(--hover-2); color: var(--text-2); }
.gpu-state.busy { background: rgba(52,199,89,.16); color: #1e8e3e; }
.gpu-state.held { background: rgba(255,159,10,.18); color: #b06000; }
.gpu-metric { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.gpu-lab { font-size: 10.5px; color: var(--text-2); width: 34px; flex: none; }
.gpu-bar { flex: 1; height: 6px; border-radius: 4px; background: var(--hover-2); overflow: hidden; }
.gpu-bar i { display: block; height: 100%; border-radius: 4px; transition: width .35s ease; }
.gpu-bar i.cool { background: #34c759; }
.gpu-bar i.warm { background: #ff9f0a; }
.gpu-bar i.hot  { background: #ff453a; }
.gpu-val { font-family: var(--mono); font-size: 10.5px; color: var(--text-2); width: 76px; text-align: right; flex: none; }
.gpu-sub { font-family: var(--mono); font-size: 10px; color: var(--text-2); margin: 5px 0 3px; }
.gpu-procs { border-top: 1px dashed var(--separator-2); padding-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.gpu-procs.empty { font-size: 10.5px; color: var(--text-2); }
.gpu-proc { display: flex; align-items: baseline; gap: 6px; font-family: var(--mono); font-size: 10.5px; }
.gpu-pu { color: var(--accent); font-weight: 600; flex: none; }
.gpu-pm { color: var(--text-2); flex: none; }
.gpu-pc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.gpu-pt { flex: none; color: var(--text-2); opacity: .7; }
.gpu-foot { flex-direction: column; align-items: stretch; gap: 6px; }
.gpu-add { display: flex; gap: 6px; }
.gpu-add input { flex: 1; min-width: 0; font-size: 12px; padding: 6px 9px; border-radius: 7px; border: 0.5px solid var(--control-bd); background: var(--content-bg); color: var(--text); }
.gpu-add input:last-of-type { flex: 0 0 130px; }
.gpu-note { font-size: 10.5px; color: var(--text-2); }
@media (max-width: 560px) {
  .gpu-grid { grid-template-columns: 1fr; }
  .gpu-add { flex-wrap: wrap; }
  .gpu-add input:last-of-type { flex: 1 1 100%; }
}

/* ---- IP ledger ---------------------------------------------------------- */
.pp-name { color: var(--accent); font-weight: 600; flex: none; }
.pp-edit { border: 0; background: none; color: var(--text-3); cursor: pointer; font-size: 11px; padding: 1px 4px; border-radius: 5px; flex: none; }
.pp-edit:hover { background: var(--hover-2); color: var(--text); }
.pp-more { display: block; width: 100%; text-align: left; margin-top: 6px; }
.tag.warn { background: rgba(255,159,10,.2); color: #b06000; }
.ips-box { width: 620px; }
.ips-body { padding: 10px 16px; overflow-y: auto; flex: 1; min-height: 140px; }
.ip-row { padding: 9px 10px; border-radius: 9px; border: 0.5px solid var(--separator); margin-bottom: 8px; }
.ip-row.unknown { border-color: rgba(255,159,10,.55); background: rgba(255,159,10,.06); }
.ip-row.blocked { border-color: rgba(255,69,58,.6); background: rgba(255,69,58,.07); }
.ip-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ip-addr { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.ip-name { color: var(--accent); font-size: 12px; }
.ip-tag { font-size: 10.5px; padding: 2px 7px; border-radius: 20px; background: var(--hover-2); color: var(--text-2); }
.ip-tag.warn { background: rgba(255,159,10,.2); color: #b06000; }
.ip-meta { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); margin: 4px 0 7px; }
.ip-acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- selection mode ----------------------------------------------------- */
.hdr-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pane.selecting .pane-host { outline: 1px dashed var(--accent); outline-offset: -1px; }
.pane.selecting .xterm-screen { cursor: text; }

.pane.selecting .xterm-screen { touch-action: none; }

/* ---- resource tabs + storage --------------------------------------------- */
.res-tabs { display: flex; gap: 4px; }
.res-tab { border: 0; background: none; color: var(--text-2); cursor: pointer; font-size: 13px; font-weight: 600; padding: 5px 11px; border-radius: 8px; }
.res-tab:hover { background: var(--hover-2); color: var(--text); }
.res-tab.on { background: var(--accent); color: #fff; }
.mnt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-bottom: 12px; }
.mnt { border: 0.5px solid var(--separator); border-radius: 10px; padding: 9px 11px; background: var(--control-bg); }
.mnt-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 6px; }
.mnt-target { font-family: var(--mono); font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mnt-src { font-family: var(--mono); font-size: 10px; color: var(--text-3); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mnt-free { font-family: var(--mono); font-size: 11px; color: var(--text-2); flex: none; }
.mnt-free.warm { color: #b06000; }
.mnt-free.hot { color: #d93025; font-weight: 600; }
.mnt-sub { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); margin-top: 4px; }
.du-roots { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.du-root { font-family: var(--mono); font-size: 11px; padding: 4px 9px; border-radius: 7px; cursor: pointer; border: 0.5px solid var(--control-bd); background: var(--control-bg); color: var(--text-2); }
.du-root:hover { background: var(--hover-2); color: var(--text); }
.du-root.on { border-color: var(--accent); color: var(--accent); }
.du-root b { font-weight: 600; }
.du-area { border-top: 1px solid var(--separator-2); padding-top: 9px; }
.du-crumb { font-family: var(--mono); font-size: 11px; margin-bottom: 6px; word-break: break-all; }
.du-crumb a { color: var(--accent); cursor: pointer; }
.du-crumb a:hover { text-decoration: underline; }
.du-sep { color: var(--text-3); margin: 0 3px; }
.du-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-2); margin-bottom: 8px; }
.du-scan { font-size: 12px; color: var(--text-2); padding: 12px 2px; }
.du-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.du-row:hover { background: var(--hover-2); }
.du-size { font-family: var(--mono); font-size: 11.5px; width: 58px; text-align: right; flex: none; font-weight: 600; }
.du-bar { width: 90px; height: 6px; border-radius: 4px; background: var(--hover-2); overflow: hidden; flex: none; }
.du-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.du-name { font-family: var(--mono); font-size: 11.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.du-pct { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); flex: none; width: 44px; text-align: right; }
@media (max-width: 560px) { .mnt-grid { grid-template-columns: 1fr; } .du-bar { width: 50px; } }
/* .gpu-bar is sized by its flex parent in the GPU cards; here it is a plain
   block child, so it needs its own box or it renders inline and overflows. */
.mnt .gpu-bar { display: block; width: 100%; height: 6px; }

/* ---- iPhone fixes --------------------------------------------------------- */
/* The on-screen keyboard shrinks the VISUAL viewport but not the layout one, so
   100dvh keeps the terminal full height and its bottom half (cursor included)
   hides behind the keyboard. app.js feeds the real height in as --vvh. */
#app { height: var(--vvh, 100dvh); }
/* vh on iOS means the LARGE viewport (toolbars hidden), so 84vh overflows the
   screen whenever Safari's bars are showing. */
.modal-box { max-height: 84dvh; }

@media (any-pointer: coarse) {
  /* iOS auto-zooms when a focused field is under 16px and never zooms back —
     the xterm helper textarea is the worst one: every tap to type zoomed the
     whole page in. It is invisible, so the size only matters to Safari. */
  input, textarea, select, .ui-dialog-input, .xterm-helper-textarea { font-size: 16px !important; }
  /* Fingers, not cursors: these were 19-24px tall. */
  .mini, .group-rename, .group-del { min-width: 34px; min-height: 34px; }
  .link-btn { min-height: 36px; }
  .toolbar-btn, .presence-btn { min-height: 40px; }
  .hdr-btn, .icon-btn { min-height: 34px; }
  .keycap { min-height: 40px; }
}

@media (max-width: 560px) {
  /* Wrapping put the 8 header buttons on two rows and ate ~90px of a phone
     screen. One scrollable row instead — nothing is hidden, just swipeable. */
  #term-header { flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 7px 10px; -webkit-overflow-scrolling: touch; }
  #term-header::-webkit-scrollbar { display: none; }
  #term-header > * { flex: none; }
  #term-header .spacer { flex: 1 1 0; min-width: 0; }
  #term-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw; }
  .hdr-btn { padding: 5px 9px; }
  .sizer { flex: none; }
}
@media (max-width: 560px) {
  /* Both are inert on a phone: iOS Safari has no Fullscreen API on iPhone, and
     the split direction is force-stacked below 560px regardless of the toggle.
     Dropping them is what lets the rest fit without sideways scrolling. */
  #btn-fs, #btn-dir { display: none; }
}
@media (max-width: 560px) {
  /* Last few pixels: on a 375px iPhone SE the row was still 23px over, which
     pushed 停止 off the edge. */
  #term-header { gap: 5px; padding: 7px 8px; }
  #term-title { max-width: 22vw; }
  .hdr-btn { padding: 5px 8px; }
  .sizer { gap: 2px; padding: 1px 2px; }
  .sizer button { padding: 0 5px; }
}
@media (max-width: 560px) { .sizer button { width: 22px; height: 26px; } }
/* The on-screen keyboard is summoned explicitly on touch; pointless on desktop. */
#btn-kbd { display: none; }
@media (any-pointer: coarse) { #btn-kbd { display: inline-block; } }
@media (max-width: 560px) {
  /* Splitting a 393px screen leaves two ~200px-tall terminals — not worth the
     header space it costs, and the 停止 button was getting pushed off the edge.
     Still available on iPad and desktop. */
  #btn-split { display: none; }
  .hdr-btn { padding: 5px 7px; }
}

/* A downward swipe that starts at the top of the document triggers iOS Safari's
   pull-to-refresh and reloads the page mid-session. Nothing here is a
   scrollable document, so no overscroll should chain anywhere. */
html, body { overscroll-behavior: none; }
.dir-list, .gpu-body, .ips-body, .pp-list, .img-previews, #auxbar { overscroll-behavior: contain; }
@media (any-pointer: coarse) {
  /* Inside a terminal every gesture is ours — drag scrolls, or selects in
     选择模式 — so the browser should not also try to pan or bounce. */
  .pane-host { touch-action: none; }
}

/* xterm's own stylesheet paints .xterm-viewport #000 and relies on an inline
   theme colour to cover it. Whenever that inline style is missing or a repaint
   is dropped (iOS does this around keyboard show/hide), the terminal shows up as
   a pure black block. Make the fallback the theme background instead — higher
   specificity than xterm's rule but no !important, so xterm's inline style
   still wins whenever it is actually there. */
.pane-host .xterm .xterm-viewport { background-color: var(--term-bg); }
.pane-host .xterm { background-color: var(--term-bg); }

/* ---- file browser + previewer -------------------------------------------- */
.files-box { width: 860px; height: 84dvh; }
.files-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px; }
.fl-row { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 8px; cursor: pointer; }
.fl-row:hover { background: var(--hover-2); }
.fl-ic { flex: none; width: 20px; text-align: center; font-size: 14px; }
.fl-name { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-size { flex: none; width: 62px; text-align: right; font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.fl-time { flex: none; width: 82px; text-align: right; font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.files-list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; align-content: start; }
.fg-cell { cursor: pointer; border-radius: 9px; padding: 6px; }
.fg-cell:hover { background: var(--hover-2); }
.fg-thumb { aspect-ratio: 1; border-radius: 7px; overflow: hidden; background: var(--control-bg);
  border: 0.5px solid var(--separator); display: flex; align-items: center; justify-content: center; }
.fg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fg-ic { font-size: 30px; opacity: .8; }
.fg-name { margin-top: 5px; font-size: 11.5px; line-height: 1.3; max-height: 2.6em; overflow: hidden; word-break: break-all; }

/* #fv is a child of #files-modal (position: fixed), so inset:0 makes the viewer
   a full-screen lightbox above the browser — which is what you want on a phone. */
.fv { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column;
  background: var(--content-bg); overflow: hidden; }
.fv-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--separator-2); background: var(--sidebar-bg); }
.fv-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.fv-meta { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); flex: none; }
.fv-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain;
  display: flex; align-items: center; justify-content: center; padding: 10px; background: var(--hover-2); }
.fv-img, .fv-vid { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.fv-pdf { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 8px; }
.fv-audio { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.fv-text { align-self: stretch; margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre; overflow: auto; background: var(--content-bg); border-radius: 8px; padding: 12px; width: 100%; }
.fv-none { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
@media (max-width: 560px) {
  .files-box { height: 88dvh; }
  .fl-time { display: none; }
  .files-list.grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .fv-meta { display: none; }
}
/* A deep path wrapped to four lines on a phone and ate the listing area. */
#files-crumb { max-height: 3.4em; overflow-y: auto; overscroll-behavior: contain; }

/* ---- Fluent workspace refresh (v62) -------------------------------------- */
:root, [data-theme="light"] {
  --win-bg: #f5f5f5;
  --sidebar-bg: #f5f5f5;
  --content-bg: #ffffff;
  --raised: #ffffff;
  --layer-2: #fafafa;
  --text: #242424;
  --text-2: #616161;
  --text-3: #8a8a8a;
  --separator: #d1d1d1;
  --separator-2: #e5e5e5;
  --hover: #ebebeb;
  --hover-2: #e0e0e0;
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-pressed: #0c3b5e;
  --accent-fg: #ffffff;
  --accent-soft: #e5f1fb;
  --control-bg: #ffffff;
  --control-bd: #bdbdbd;
  --green: #107c10;
  --grey: #a6a6a6;
  --red: #c50f1f;
  --warning: #f7630c;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  --blur: none;
  --term-bg: #ffffff;
}
[data-theme="dark"] {
  --win-bg: #202020;
  --sidebar-bg: #242424;
  --content-bg: #1f1f1f;
  --raised: #292929;
  --layer-2: #292929;
  --text: #ffffff;
  --text-2: #d6d6d6;
  --text-3: #adadad;
  --separator: #474747;
  --separator-2: #3d3d3d;
  --hover: #333333;
  --hover-2: #3b3b3b;
  --accent: #479ef5;
  --accent-hover: #62abf5;
  --accent-pressed: #2886de;
  --accent-fg: #0f0f0f;
  --accent-soft: #0e3a5f;
  --control-bg: #292929;
  --control-bd: #666666;
  --green: #54b054;
  --grey: #737373;
  --red: #ff99a4;
  --warning: #fce100;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.46);
  --blur: none;
  --term-bg: #1e1e1e;
}
:root {
  --font: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "CC UI Sans", system-ui, sans-serif;
  --sb-w: 264px;
  --radius: 6px;
}

body {
  background: var(--win-bg);
  font-size: 12.5px;
  line-height: 1.4;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { letter-spacing: 0; }
button:disabled { cursor: not-allowed; opacity: .48; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
* { scrollbar-color: var(--text-3) transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb {
  min-height: 28px;
  background: var(--text-3);
  border: 4px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-2); background-clip: content-box; }

#titlebar {
  height: 44px;
  gap: 4px;
  padding: 0 8px;
  background: var(--raised);
  border-bottom: 1px solid var(--separator);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.traffic { display: none; }
.tb-btn, .icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1;
  box-shadow: none;
}
.tb-btn:hover, .icon-btn:hover { background: var(--hover); color: var(--text); }
.tb-btn:active, .icon-btn:active { background: var(--hover-2); }
.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 130px;
  padding: 0 8px 0 4px;
  user-select: none;
}
.app-brand-name { color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }
.app-mark {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2px;
  width: 16px;
  height: 16px;
  flex: none;
}
.app-mark i { display: block; background: var(--accent); }
.app-mark i:first-child { border-radius: 2px 0 0; }
.app-mark i:nth-child(2) { border-radius: 0 2px 0 0; }
.app-mark i:nth-child(3) { border-radius: 0 0 0 2px; }
.app-mark i:nth-child(4) { border-radius: 0 0 2px; }
.titlebar-divider { width: 1px; height: 20px; margin: 0 8px 0 4px; background: var(--separator-2); }
.titlebar-title {
  position: static;
  flex: 1;
  min-width: 0;
  padding: 0;
  text-align: left;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 400;
  line-height: 32px;
}
.titlebar-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }

#body { transition: grid-template-columns .16s ease; }
#sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--separator);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.side-head { padding: 12px 12px 8px; }
.sidebar-toolbar { grid-template-columns: 1fr 32px; gap: 6px; }
.toolbar-btn, .new-btn, .btn-sm, .mode-btn, .ui-btn {
  min-height: 32px;
  border: 1px solid var(--control-bd);
  border-radius: 4px;
  background: var(--control-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
}
.toolbar-btn { height: 32px; padding: 0 10px; border-width: 1px; border-radius: 4px; }
.toolbar-btn.primary, .new-btn.lg, .btn-sm.primary, .ui-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.toolbar-btn.primary:hover, .new-btn.lg:hover, .btn-sm.primary:hover, .ui-btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  filter: none;
}
.toolbar-btn:active, .new-btn:active, .btn-sm:active, .mode-btn:active, .ui-btn:active { background: var(--hover-2); }
.toolbar-ic { color: inherit; font-size: 16px; }
.chat-list { padding: 4px 6px 8px; }
.chat-group { margin-bottom: 4px; }
.group-head {
  min-height: 28px;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.group-count, .tag, .ip-tag, .gpu-state {
  border-radius: 999px;
}
.chat-item {
  min-height: 44px;
  gap: 8px;
  margin-bottom: 1px;
  padding: 6px 8px 6px 12px;
  border-radius: 4px;
}
.chat-item::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: transparent;
}
.chat-item.active { background: var(--accent-soft); }
.chat-item.active::before { background: var(--accent); }
.chat-item.active .chat-title { color: var(--text); }
.chat-item.active .chat-sub { color: var(--text-2); }
.chat-item.active .status-dot.green { box-shadow: none; }
.chat-item.active .mini { color: var(--text-2); }
.chat-item.active .mini:hover { background: var(--hover-2); color: var(--text); }
.chat-item.active .mini.danger:hover { color: var(--red); background: var(--hover-2); }
.chat-title { font-size: 12px; font-weight: 600; }
.chat-sub { font-size: 10.5px; }
.mini, .group-rename, .group-del, .icon-btn-sm {
  border-radius: 4px;
}
.side-presence, .side-foot { border-color: var(--separator-2); }
.presence-btn { min-height: 36px; padding: 8px 12px; }
.presence-panel {
  bottom: 40px;
  border: 1px solid var(--separator);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.side-foot { gap: 2px; padding: 6px; }
.link-btn { min-height: 30px; padding: 5px 3px; border-radius: 4px; }

#main { background: var(--content-bg); }
.empty { align-items: center; padding: 24px; }
.empty-inner { max-width: 28em; }
.empty-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 1px solid var(--separator);
  border-radius: 8px;
  background: var(--raised);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}
.empty-mark .app-mark { width: 22px; height: 22px; }
.empty h1 { margin-bottom: 5px; font-size: 18px; font-weight: 600; }
.empty p { margin-bottom: 18px; font-size: 12px; color: var(--text-2); }
.new-btn.lg { min-height: 34px; padding: 6px 16px; border-radius: 4px; font-size: 12px; }

#term-header {
  min-height: 42px;
  flex-wrap: nowrap;
  gap: 5px;
  padding: 5px 8px 5px 12px;
  background: var(--layer-2);
  border-bottom: 1px solid var(--separator);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
#term-title { max-width: 22vw; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#term-path { font-size: 10.5px; }
.conn { font-size: 11px; }
.status-dot { width: 8px; height: 8px; }
.sizer {
  height: 30px;
  border: 1px solid var(--control-bd);
  border-radius: 4px;
  background: var(--control-bg);
}
.sizer button { width: 26px; height: 28px; }
.sizer .val { min-width: 24px; font-size: 10.5px; }
.hdr-btn {
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1;
}
.hdr-btn:hover { background: var(--hover); border-color: transparent; color: var(--text); }
.hdr-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.hdr-btn.danger { width: auto; min-width: 44px; padding: 0 10px; color: var(--red); }
.hdr-btn.danger:hover { border-color: var(--red); background: transparent; }
.panes { gap: 4px; padding: 4px; background: var(--win-bg); }
.pane {
  border: 1px solid var(--separator);
  border-radius: 4px;
  box-shadow: none;
}
.panes[data-n="1"] > .pane { border-radius: 0; }
.pane.focused { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pane-bar { min-height: 28px; padding: 4px 8px; background: var(--layer-2); border-color: var(--separator-2); }
.pane-host { padding: 5px 7px; }
.gutter::after { border-radius: 0; background: var(--separator); }
.keycap { min-width: 40px; height: 36px; border: 1px solid var(--control-bd); border-radius: 4px; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); }

.modal {
  padding: 20px;
  background: rgba(0, 0, 0, .38);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.modal-box {
  border: 1px solid var(--separator);
  border-radius: 8px;
  background: var(--raised);
  box-shadow: var(--shadow);
}
.modal-head { min-height: 48px; padding: 8px 12px 8px 16px; border-color: var(--separator-2); }
.modal-head h3 { font-size: 14px; font-weight: 600; }
.modal-foot { padding: 10px 16px; background: var(--layer-2); border-color: var(--separator-2); }
.crumb { padding: 8px 16px; background: var(--layer-2); border-color: var(--separator-2); }
.dir-toolbar { padding: 10px 14px 4px; }
.dir-search {
  height: 32px;
  border: 1px solid var(--control-bd);
  border-radius: 4px;
  background: var(--control-bg);
}
.dir-search:focus-within, .gpu-add input:focus, .ui-dialog-input:focus {
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.btn-sm { padding: 5px 10px; }
.dir-row, .fl-row { border-radius: 4px; }
.mode-btn { padding: 6px 12px; }
.mode-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.img-drop { border-radius: 6px; background: var(--layer-2); }
.img-thumb, .fg-cell, .fg-thumb, .fv-img, .fv-vid, .fv-pdf, .fv-text { border-radius: 4px; }
.gpu-card, .mnt, .ip-row { border: 1px solid var(--separator); border-radius: 6px; box-shadow: none; }
.gpu-user { border-width: 1px; border-radius: 999px; }
.res-tab { min-height: 32px; padding: 5px 10px; border-radius: 4px; font-weight: 600; }
.res-tab.on { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

#toast {
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 6px;
  background: rgba(32, 32, 32, .96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
  font-size: 12px;
}
.ui-dialog-backdrop {
  align-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .38);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.ui-dialog {
  width: 340px;
  padding: 20px;
  border: 1px solid var(--separator);
  border-radius: 8px;
  background: var(--raised);
  text-align: left;
}
.ui-dialog-icon {
  width: 28px;
  height: 28px;
  margin: 0 0 12px;
  border-radius: 4px;
  background: var(--accent-soft);
  box-shadow: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}
.ui-dialog-title { font-size: 15px; }
.ui-dialog-msg { font-size: 12px; }
.ui-dialog-input { border-radius: 4px; }
.ui-dialog-btns { justify-content: flex-end; }
.ui-btn { flex: 0 0 auto; min-width: 76px; padding: 5px 12px; }

.login {
  background: var(--win-bg);
  color: var(--text);
}
.login::before {
  background: linear-gradient(180deg, transparent 0 44px, var(--separator) 44px 45px, transparent 45px);
}
.login-center {
  width: min(360px, calc(100vw - 32px));
  margin-top: -4vh;
  padding: 32px;
  border: 1px solid var(--separator);
  border-radius: 8px;
  background: var(--raised);
  box-shadow: var(--shadow);
}
.login-avatar {
  width: 48px;
  height: 48px;
  border: 1px solid var(--separator);
  border-radius: 8px;
  background: var(--layer-2);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.login-avatar .app-mark { width: 22px; height: 22px; }
.login-name {
  margin: 14px 0 18px;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  text-shadow: none;
}
.login-field {
  width: 100%;
  height: 34px;
  border: 1px solid var(--control-bd);
  border-radius: 4px;
  background: var(--control-bg);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.login-field:focus-within { border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.login-field input {
  color: var(--text);
  font-size: 13px;
  text-align: left;
  padding: 0 38px 0 10px;
}
.login-field input::placeholder { color: var(--text-3); }
.login-go {
  right: 3px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--accent);
  color: #ffffff;
}
.login-go:hover { background: var(--accent-hover); }
.login-hint { margin-top: 10px; color: var(--text-2); font-size: 11px; text-shadow: none; }
.login-hint.err { color: var(--red); }

@media (max-width: 1100px) {
  #term-path { display: none; }
  #term-title { max-width: 18vw; }
}
@media (max-width: 820px) {
  #topbar {
    min-height: calc(44px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 6px 0;
    gap: 4px;
    background: var(--raised);
    border-bottom: 1px solid var(--separator);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .topbar-title { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
  .topbar-presence { margin-left: auto; font-size: 11px; }
  .topbar-status { font-size: 11px; }
  #sidebar {
    width: min(288px, 88vw);
    background: var(--sidebar-bg);
    box-shadow: 8px 0 24px rgba(0, 0, 0, .22);
  }
  #scrim { background: transparent; }
  body.drawer-open #scrim { background: rgba(0, 0, 0, .42); }
  #term-header { min-height: 40px; padding-left: 8px; }
  #term-title { max-width: 30vw; }
}
@media (max-width: 560px) {
  .modal { align-items: flex-end; padding: 8px; }
  .modal-box { width: 100%; max-height: calc(var(--vvh, 100dvh) - 16px); border-radius: 8px; }
  .files-box { height: calc(var(--vvh, 100dvh) - 16px); }
  .modal-head { min-height: 44px; }
  #term-header { gap: 3px; padding: 5px 6px; }
  #term-title { max-width: 24vw; }
  .hdr-btn { width: 30px; min-width: 30px; height: 30px; padding: 0; }
  .hdr-btn.danger { width: auto; min-width: 42px; padding: 0 8px; }
  .sizer { gap: 0; padding: 0; }
  .login-center { padding: 24px; }
}
@media (any-pointer: coarse) {
  .tb-btn, .icon-btn, .hdr-btn { min-width: 36px; min-height: 36px; }
  .toolbar-btn, .presence-btn, .keycap { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (forced-colors: active) {
  .chat-item.active, .hdr-btn.on, .res-tab.on { outline: 2px solid Highlight; outline-offset: -2px; }
  .chat-item.active::before, .app-mark i { background: Highlight; }
  .pane.focused { border: 2px solid Highlight; box-shadow: none; }
  .status-dot { border: 1px solid CanvasText; }
  .quota-battery { color: ButtonText; }
  .quota-battery-reset { color: ButtonText; }
  .quota-battery-icon i { background: CanvasText; forced-color-adjust: none; }
}

/* ---- Interaction polish (v63) ------------------------------------------- */
:root {
  --motion-fast: 80ms;
  --motion-normal: 140ms;
  --motion-slow: 180ms;
  --ease-fluent: cubic-bezier(.1, .9, .2, 1);
  --ease-exit: cubic-bezier(.7, 0, .84, 0);
}
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

.tb-btn, .icon-btn, .toolbar-btn, .new-btn, .btn-sm, .mode-btn, .ui-btn,
.hdr-btn, .link-btn, .mini, .icon-btn-sm, .keycap, .res-tab,
.chat-item, .group-head, .dir-row, .fl-row, .fg-cell {
  transition:
    background-color var(--motion-fast) linear,
    border-color var(--motion-fast) linear,
    color var(--motion-fast) linear,
    box-shadow var(--motion-fast) linear,
    opacity var(--motion-fast) linear,
    transform var(--motion-fast) var(--ease-fluent);
}
.tb-btn:active, .icon-btn:active, .toolbar-btn:active, .new-btn:active,
.btn-sm:active, .mode-btn:active, .ui-btn:active, .hdr-btn:active,
.link-btn:active, .mini:active, .icon-btn-sm:active, .keycap:active,
.res-tab:active {
  transform: scale(.96);
}
.toolbar-btn.primary, .new-btn.lg, .btn-sm.primary, .ui-btn.primary {
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .16), 0 1px 2px rgba(0, 0, 0, .08);
}
.toolbar-btn.primary:active, .new-btn.lg:active, .btn-sm.primary:active, .ui-btn.primary:active {
  background: var(--accent-pressed);
  border-color: var(--accent-pressed);
}
#titlebar {
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
[data-theme="dark"] #titlebar { box-shadow: none; }
.app-mark i { transition: opacity var(--motion-normal) linear, transform var(--motion-normal) var(--ease-fluent); }
.app-brand:hover .app-mark i:nth-child(2), .app-brand:hover .app-mark i:nth-child(3) { opacity: .74; }

.command-divider {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  flex: none;
  background: var(--separator);
}
.touch-divider { display: none; }
@media (any-pointer: coarse) { .touch-divider { display: block; } }
@media (max-width: 1100px) { .command-divider { display: none; } }

#body { transition-duration: var(--motion-slow); transition-timing-function: var(--ease-fluent); }
#sidebar { will-change: transform; }
.chat-item::before {
  transition: background-color var(--motion-fast) linear, top var(--motion-normal) var(--ease-fluent), bottom var(--motion-normal) var(--ease-fluent);
}
.chat-item.active::before { top: 8px; bottom: 8px; }
.chat-actions { transform: translateX(3px); transition: opacity var(--motion-fast) linear, transform var(--motion-normal) var(--ease-fluent); }
.chat-item:hover .chat-actions, .chat-item.active .chat-actions { transform: translateX(0); }
.pane { transition: border-color var(--motion-fast) linear, box-shadow var(--motion-fast) linear; }
.pane.focused { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 1px rgba(15, 108, 189, .06); }
.gutter::after { transition: background-color var(--motion-fast) linear, transform var(--motion-fast) var(--ease-fluent); }
.gutter:hover::after, .gutter.dragging::after { transform: scaleX(1.35); }
.gutter.h:hover::after, .gutter.h.dragging::after { transform: scaleY(1.35); }

.presence-panel.is-opening { animation: cc-fly-in var(--motion-slow) var(--ease-fluent) both; transform-origin: bottom center; }
.presence-panel.is-closing { animation: cc-fly-out var(--motion-normal) var(--ease-exit) both; pointer-events: none; }
.modal.is-opening, .ui-dialog-backdrop.is-opening { animation: cc-backdrop-in var(--motion-normal) linear both; }
.modal.is-closing, .ui-dialog-backdrop.is-closing { animation: cc-backdrop-out var(--motion-normal) linear both; pointer-events: none; }
.modal.is-opening .modal-box, .ui-dialog-backdrop.is-opening .ui-dialog {
  animation: cc-dialog-in var(--motion-slow) var(--ease-fluent) both;
}
.modal.is-closing .modal-box, .ui-dialog-backdrop.is-closing .ui-dialog {
  animation: cc-dialog-out var(--motion-normal) var(--ease-exit) both;
}
.login.is-opening { animation: cc-backdrop-in var(--motion-normal) linear both; }
.login.is-opening .login-center { animation: cc-login-in var(--motion-slow) var(--ease-fluent) both; }
.login.is-closing { animation: cc-backdrop-out var(--motion-normal) linear both; pointer-events: none; }
.login.is-closing .login-center { animation: cc-dialog-out var(--motion-normal) var(--ease-exit) both; }
.fv.is-opening { animation: cc-view-in var(--motion-slow) var(--ease-fluent) both; }
.fv.is-closing { animation: cc-view-out var(--motion-normal) var(--ease-exit) both; pointer-events: none; }

@keyframes cc-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes cc-backdrop-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes cc-dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cc-dialog-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(5px) scale(.99); }
}
@keyframes cc-login-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cc-fly-in {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cc-fly-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(4px) scale(.99); }
}
@keyframes cc-view-in {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes cc-view-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(8px); }
}

#toast.is-opening { animation: cc-toast-in var(--motion-slow) var(--ease-fluent) both; }
#toast.is-closing { animation: cc-toast-out var(--motion-normal) var(--ease-exit) both; pointer-events: none; }
@keyframes cc-toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes cc-toast-out {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, 6px); }
}

#tooltip {
  position: fixed;
  z-index: 200;
  max-width: min(280px, calc(100vw - 16px));
  padding: 5px 8px 6px;
  border: 1px solid var(--separator);
  border-radius: 4px;
  background: var(--raised);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .16);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  pointer-events: none;
}
#tooltip.is-opening { animation: cc-tooltip-in var(--motion-normal) var(--ease-fluent) both; }
@keyframes cc-tooltip-in {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}

.gpu-loading {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gpu-loading::before, .btn-pending::before {
  content: "";
  width: 12px;
  height: 12px;
  flex: none;
  border: 2px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cc-spin .7s linear infinite;
}
.btn-pending {
  position: relative;
  cursor: wait !important;
  pointer-events: none;
  color: transparent !important;
}
.btn-pending::before {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -7px 0 0 -7px;
}
.toolbar-btn.primary.btn-pending::before, .new-btn.lg.btn-pending::before,
.btn-sm.primary.btn-pending::before, .ui-btn.primary.btn-pending::before {
  border-color: rgba(255, 255, 255, .48);
  border-top-color: #ffffff;
}
@keyframes cc-spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  #sidebar { transition-duration: var(--motion-slow); transition-timing-function: var(--ease-fluent); }
  #scrim { transition-duration: var(--motion-slow); transition-timing-function: linear; }
}
@media (display-mode: standalone) {
  #titlebar { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
}
@media (hover: none) {
  .chat-actions { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .modal, .modal-box, .ui-dialog-backdrop, .ui-dialog, .login, .login-center,
  .presence-panel, .fv, #toast, #tooltip, .gpu-loading::before, .btn-pending::before {
    animation: none !important;
  }
  .tb-btn:active, .icon-btn:active, .toolbar-btn:active, .new-btn:active,
  .btn-sm:active, .mode-btn:active, .ui-btn:active, .hdr-btn:active,
  .link-btn:active, .mini:active, .icon-btn-sm:active, .keycap:active,
  .res-tab:active { transform: none; }
}
