/* MobiSSH PWA — Mobile-first styles */

:root {
  --bg-deep: #0d0d1a;
  --bg-panel: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --accent: #00ff88;
  --accent-dim: #00cc6a;
  --danger: #ff4444;
  --text: #e0e0e0;
  --text-dim: #888;
  --border: #2a2a4a;
  --compose: #7c6ff7;
  --tab-height: 56px;
  --keybar-height: 34px;
  --keybar-row-height: 34px;
  --keybar-handle-height: 22px;
  /* key-btn-height: keybar row minus 10px vertical clearance; keep in sync with --keybar-row-height */
  --key-btn-height: 24px;
  /* Shared font stacks */
  --font-mono: ui-monospace, Menlo, 'Cascadia Code', Consolas, monospace;
  --font-condensed: 'Roboto Condensed', 'Arial Narrow', 'Liberation Sans Narrow', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none; /* prevent iOS rubber-band scroll (#12) */
  background: var(--bg-deep);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Generic hidden class — one rule to hide any element via .hidden toggle */
.hidden { display: none !important; }

/* Hidden IME inputs — invisible but reachable by Android IME.
   #imeInput    = textarea, normal keyboard (IME/swipe mode)
   #directInput = password input, suppresses Gboard predictions (direct mode) */
#imeInput,
#directInput {
  position: fixed;
  opacity: 0;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  border: none;
  outline: none;
  resize: none;
  padding: 0;
  font-size: 16px; /* prevents iOS zoom on focus */
  background: transparent;
  color: transparent;
  caret-color: transparent;
  pointer-events: none;
  z-index: -1;
}

/* IME textarea: visible when it has content. Position set by JS via inline style. */
#imeInput.ime-visible {
  opacity: 1;
  width: 90%;
  left: 5%;
  min-height: 3em;
  max-height: calc(var(--viewport-height, 100svh) / 2);
  height: auto;
  background: var(--bg-card);
  color: var(--text);
  caret-color: var(--accent);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px 10px 0 0;
  padding: 8px 8px;
  pointer-events: auto;
  z-index: 9998;
  font-size: 16px;
  overflow-y: auto;
}

/* IME editing state — user tapped in to manually edit (active, highlighted) */
#imeInput.ime-editing {
  border-width: 3px;
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(0, 255, 160, 0.4);
}

/* Preview style: subtle (default) — solid dark, white text, works on any theme */
#imeInput.preview-subtle {
  background: #1a1a2e;
  color: #fff;
  caret-color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}

/* Preview style: accent — accent bg, bold white text, unmistakable staging area */
#imeInput.preview-accent {
  background: var(--accent);
  color: #fff;
  caret-color: #fff;
  border-color: var(--accent-dim);
  font-weight: bold;
}

/* Preview style: glass — solid charcoal with accent border, works on any theme */
#imeInput.preview-glass {
  background: #2a2a3a;
  color: #e0e0e0;
  caret-color: var(--accent);
  border-color: rgba(0, 255, 136, 0.4);
  box-shadow: 0 0 6px rgba(0, 255, 136, 0.15);
}
.ime-actions.ime-editing .ime-commit {
  background: var(--accent);
  color: #000;
}

/* Preview mode toggle button (handle bar) */
.handle-preview-btn.preview-active {
  color: var(--accent);
  background: rgba(0, 255, 136, 0.15);
}
.handle-preview-btn:active { opacity: 0.7; }

/* IME action buttons — horizontal row below the textarea (#106) */
.ime-actions {
  position: fixed;
  z-index: 9998;
  left: 5%;
  width: 90%;
  display: flex;
  flex-direction: row;
}
.ime-action-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-top: none;
  color: var(--accent);
  height: 36px;
  padding: 0;
  font-size: 14px;
  font-family: var(--font-ui);
  touch-action: manipulation;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
}
.ime-action-btn:first-child { border-radius: 0 0 0 10px; }
.ime-action-btn:last-child { border-radius: 0 0 10px 0; }
.ime-action-btn:active { background: var(--accent); color: #000; }
.ime-history-btn { flex: 0.5; font-size: 12px; }
.ime-history-btn.disabled { color: var(--text-dim); pointer-events: none; }
.ime-history-btn:active { background: var(--accent); color: #000; }
.ime-commit {
  font-weight: 700;
  position: relative;
}
/* SVG countdown ring centered inside the commit button (#169) */
.commit-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -50%) rotate(-90deg);
  pointer-events: none;
}
.commit-ring-track,
.commit-ring-progress {
  fill: none;
  stroke-width: 2.5;
}
.commit-ring-track {
  stroke: transparent;
}
.commit-ring-progress {
  stroke: transparent;
  stroke-dasharray: 100.53;
  stroke-dashoffset: 100.53;
  stroke-linecap: round;
}
/* When countdown is active, show the ring */
.ime-commit.countdown-active .commit-ring-track {
  stroke: rgba(255, 255, 255, 0.1);
}
.ime-commit.countdown-active .commit-ring-progress {
  stroke: var(--accent);
}
.commit-label { position: relative; z-index: 1; }
.commit-countdown {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  font-size: 8px;
  opacity: 0.6;
  font-weight: 400;
  line-height: 1;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height for mobile */
  padding-top: env(safe-area-inset-top); /* notch / Dynamic Island */
}

/* Tab bar */
#tabBar {
  display: flex;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  order: 2; /* bottom nav on mobile */
  height: calc(var(--tab-height) + env(safe-area-inset-bottom)); /* home indicator */
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
  overflow: hidden;
  transition: height 0.2s ease;
}

#tabBar.hidden {
  height: 0;
  border-top: none;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s;
  padding: 6px 8px;
  min-width: 44px; /* WCAG 2.5.5 minimum touch target */
  -webkit-user-select: none;
  user-select: none;
}

.tab.active {
  color: var(--accent);
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Panels */
.panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  order: 1;
}

.panel.active {
  display: flex;
  flex-direction: column;
}

/* Terminal panel */
#panel-terminal {
  padding: 0;
}

#terminal {
  flex: 1;
  background: var(--terminal-bg, #000);
  padding: 4px;
  overflow: hidden;
  overscroll-behavior: none; /* prevent iOS rubber-band scroll (#12) */
  min-height: 0;
  touch-action: none; /* #37: prevent browser panning so JS touch-scroll handles all gestures */
  position: relative;
  -webkit-user-select: none;
  user-select: none; /* prevent Chrome double-tap text selection on terminal */
}

/* Per-session terminal theme scoping (#61).
   When a profile has a theme set, applyTheme() writes data-theme on #terminal.
   These rules override --terminal-bg so the terminal background matches the theme. */
#terminal[data-theme="dark"]          { --terminal-bg: #000000; }
#terminal[data-theme="light"]         { --terminal-bg: #ffffff; }
#terminal[data-theme="solarizedDark"] { --terminal-bg: #002b36; }
#terminal[data-theme="solarizedLight"]{ --terminal-bg: #fdf6e3; }
#terminal[data-theme="highContrast"]  { --terminal-bg: #000000; }
#terminal[data-theme="dracula"]       { --terminal-bg: #282a36; }
#terminal[data-theme="nord"]          { --terminal-bg: #2e3440; }
#terminal[data-theme="gruvboxDark"]   { --terminal-bg: #282828; }
#terminal[data-theme="monokai"]       { --terminal-bg: #272822; }
#terminal[data-theme="tokyoNight"]    { --terminal-bg: #1a1b26; }

/* Block pointer/touch events on the xterm.js a11y overlay to prevent native
   paste/URL-open context menus (#55), while preserving screen reader access.
   The a11y tree is invisible — it needs no pointer interaction. */
#terminal .xterm-accessibility-tree {
  pointer-events: none;
}

/* (Old #imePreview pill removed — actions are now on #imeContainer, #106) */


/* Key bar handle — ≡ | session identity | ▾ */
#key-bar-handle {
  display: flex;
  align-items: center;
  height: var(--keybar-handle-height);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  position: relative; /* anchor for #sessionMenu */
}
#key-bar-handle:active { background: rgba(255,255,255,0.05); }

/* Center zone: current session identity */
#sessionMenuBtn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
  touch-action: manipulation;
  cursor: pointer;
  text-align: center;
  height: 100%;
  touch-action: manipulation;
}

#sessionMenuBtn.connected { color: var(--text); }
#sessionMenuBtn:active { color: var(--accent); }

/* Session menu popover — floats upward above handle strip */
@keyframes sessionMenuSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#sessionMenu {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  min-width: 180px;
  max-width: min(220px, 90vw);
  top: 8px;
  bottom: 120px;
  z-index: 200;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: sessionMenuSlideUp 0.15s ease-out;
}


/* Session list — visible when 2+ active sessions (#60) */
.session-list {
  border-bottom: 1px solid var(--border);
  padding: 4px 0;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.session-item:active { background: var(--bg-card); }

.session-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  flex-shrink: 0;
}

.session-item.active .session-item-dot {
  background: var(--accent);
}

.session-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  touch-action: manipulation;
  flex-shrink: 0;
}

.session-item-close:active { color: var(--danger); }

.session-item-dot-connected { background: var(--accent); }
.session-item.session-connected .session-item-dot { border-color: var(--accent); }
.session-item.session-disconnected .session-item-dot { border-color: var(--danger); background: var(--danger); }
.session-item.session-connecting .session-item-dot,
.session-item.session-reconnecting .session-item-dot { border-color: var(--warning, #e6a700); background: var(--warning, #e6a700); }
.session-item.session-failed .session-item-dot { border-color: var(--danger); }

.session-disconnected { opacity: 0.7; }

.session-list-new {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--bg-card);
  border: none;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  color: var(--accent);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.session-list-new:active { background: var(--bg-card); }

/* Transparent backdrop — covers viewport when session menu is open so outside
   clicks (including on the xterm.js canvas) dismiss the menu. */
#menuBackdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
}

.session-menu-item {
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  display: block;
  touch-action: manipulation;
}

.session-menu-item:first-child { border-top: none; }
.session-menu-item:active { background: var(--bg-card); }
.session-menu-item.danger { color: var(--danger); }

/* Font size row — inline +/− controls that keep menu open */
.font-size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
  gap: 8px;
}
.font-size-row:active { background: none; }

#fontSizeLabel {
  font-size: 13px;
  color: var(--text-dim);
  min-width: 32px;
  text-align: center;
  flex: 1;
}

.font-adj-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

/* Shared base for icon-only handle bar buttons */
.handle-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0 8px;
  flex-shrink: 0;
  touch-action: manipulation;
  cursor: pointer;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Hamburger menu button — toggles tab bar */
.handle-menu-btn { font-size: 18px; }
.handle-menu-btn:active { color: var(--accent); }

/* Compose/IME toggle in handle bar — always visible, compact icon */
.handle-compose-btn.compose-active { color: var(--accent); }
.handle-compose-btn:active { opacity: 0.7; }

/* Bell notification indicator in handle bar (#33) */
.handle-bell-btn {
  position: relative;
  padding: 4px 6px;
}

.bell-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  background: var(--accent);
  color: var(--bg-deep);
  font-size: 10px;
  font-weight: bold;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  border-radius: 7px;
  text-align: center;
  padding: 0 3px;
}
.session-notif-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg-deep);
  font-size: 10px;
  font-weight: bold;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  border-radius: 7px;
  text-align: center;
  padding: 0 3px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Notification drawer (#34) */
#notifDrawer {
  position: absolute;
  bottom: 100%;
  right: 0;
  width: 280px;
  max-height: 300px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  z-index: 50;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
  touch-action: pan-y;
}

.notif-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.notif-clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
}

.notif-drawer-list {
  overflow-y: auto;
  max-height: 260px;
  padding: 4px 0;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.notif-entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
}

.notif-entry:last-child {
  border-bottom: none;
}

.notif-entry-body {
  flex: 1;
  margin-right: 8px;
}

.notif-entry-time {
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
}

.notif-dismiss-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}

.notif-drawer-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* Copy and paste buttons in handle bar — shared layout (#55, #197) */
.handle-copy-btn,
.handle-paste-btn {
  border-radius: 8px;
  padding: 0 8px;
  height: calc(100% - 6px);
  margin: 3px 0;
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-ui);
  flex-shrink: 0;
  touch-action: manipulation;
}
.handle-copy-btn:active,
.handle-paste-btn:active { opacity: 0.7; }

/* Copy button — accent fill, appears when selection is active */
.handle-copy-btn {
  background: var(--accent);
  color: #000;
  border: none;
}

/* Paste button — outlined accent, appears when clipboard has content */
.handle-paste-btn {
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--accent);
}

/* Selection action chip — long-press popup (#55) */
.selection-chip {
  position: absolute;
  bottom: calc(var(--keybar-handle-height) + var(--keybar-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.selection-chip-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-family: var(--font-ui);
  touch-action: manipulation;
  white-space: nowrap;
}
.selection-chip-btn:active { background: var(--accent); color: #000; }
.selection-chip-dismiss { border-color: var(--danger); color: var(--danger); padding: 4px 8px; }
.selection-chip-dismiss:active { background: var(--danger); color: #fff; }

/* Long-press tooltip (#111) */
.toolbar-tooltip {
  position: fixed;
  left: var(--tooltip-left, 50%);
  top: var(--tooltip-top, 0);
  z-index: 200;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-ui);
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  pointer-events: none;
}

/* Key bar — depth-based two-row layout */
#key-bar {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  flex-shrink: 0;
  overflow: hidden;
  height: calc(var(--keybar-height) + env(safe-area-inset-bottom)); /* home indicator when tab bar hidden */
  padding-bottom: env(safe-area-inset-bottom);
  transition: height 0.2s ease;
}

#key-bar.depth-0 { height: 0; }
#key-bar.depth-1 { height: var(--keybar-row-height); }
#key-bar.depth-2,
#key-bar.depth-3 { height: calc(2 * var(--keybar-row-height) + env(safe-area-inset-bottom)); }

/* Editing row (depth 1): scrollable editing keys + right-anchored compose toggle */
#key-keys-row {
  display: flex;
  align-items: center;
  height: var(--keybar-row-height);
  flex-shrink: 0;
  padding: 0 4px;
}

/* Navigation row (depth 2): scrollable nav keys */
#key-nav-row {
  display: flex;
  align-items: center;
  height: var(--keybar-row-height);
  flex-shrink: 0;
  padding: 0 4px;
}

#key-scroll-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

#key-scroll-nav::-webkit-scrollbar { display: none; }

#key-scroll {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x; /* allow horizontal swipe to scroll key row (#45) */
}

#key-scroll::-webkit-scrollbar { display: none; }

/* Compose / direct-mode toggle button — system-function key, visually separated (#146, #149) */
.mode-btn {
  padding: 0 6px;
  height: var(--key-btn-height);
  color: var(--compose);
  border-color: var(--compose);
  flex-shrink: 0;
  margin-left: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mode-btn svg { display: block; }

/* Compose active: filled accent button */
.mode-btn.compose-active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Mode indicator line between terminal and key bar */
#key-bar {
  border-top: 2px solid transparent;
  transition: border-top-color 0.15s ease;
}

#key-bar.compose-active {
  border-top-color: var(--accent);
}

.key-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 12px;
  font-family: var(--font-condensed);
  letter-spacing: -0.2px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  height: var(--key-btn-height);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation; /* prevent 300ms tap delay on mobile */
  transition: background 0.08s, transform 0.08s, border-color 0.08s;
}

.key-btn:active {
  background: var(--bg-input);
  transform: scale(0.88);
  border-color: var(--accent-dim);
}

/* Arrow keys: wider tap target, less horizontal text to pad around */
#keyUp, #keyDown, #keyLeft, #keyRight,
#keyUpM, #keyDownM, #keyLeftM, #keyRightM {
  min-width: 36px;
  padding: 0 4px;
}

/* Tab key: wider tap target (frequently used for autocomplete/indent) */
#keyTab {
  min-width: 42px;
}

/* Named word keys: tighter padding, they don't need much room */
#keyEsc, #keyTab, #keyHome, #keyEnd, #keyPgUp, #keyPgDn,
#keyEscM {
  padding: 0 5px;
}

/* Merged nav key subset — shown inline at depth-1, hidden at depth-2 */
.key-nav-subset {
  display: none;
}

#key-bar.depth-1 .key-nav-subset {
  display: flex;
  gap: 4px;
}

/* At depth-1, single scrollable row -- no wrapping */
#key-bar.depth-1 #key-keys-row {
  height: var(--keybar-row-height);
  overflow: hidden;
  min-width: 0;
}

#key-bar.depth-1 #key-scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

/* Modifier keys (Ctrl, Shift) — narrower than action keys to save horizontal space */
.key-btn.modifier {
  padding: 0 4px;
  max-width: 32px;
}

.key-btn.modifier.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.key-btn.danger { color: var(--danger); border-color: var(--danger); }



/* xterm overrides */
.xterm-viewport::-webkit-scrollbar { width: 4px; }
.xterm-viewport::-webkit-scrollbar-thumb { background: var(--border); }

/* Connect form credential fields: type="text" at rest (avoids Chrome login-form
   detection), promoted to type="password" on focus via JS cloaking (#147/#150).
   CSS masking ensures dots are visible even while type="text". */
#remote_c,
#remote_pp {
  -webkit-text-security: disc;
}

/* Scrollable panels */
#panel-connect,
#panel-keys,
#panel-settings {
  padding: 16px;
  gap: 12px;
  overscroll-behavior: contain;
  background: var(--bg-panel);
}

h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 12px;
}

label:first-of-type {
  margin-top: 0;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="url"],
input[type="range"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px; /* prevents iOS zoom */
  font-family: inherit;
  transition: border-color 0.15s;
}

textarea {
  font-family: var(--font-mono);
  font-size: 12px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input[type="range"] {
  padding: 4px 0;
  background: transparent;
  border: none;
  accent-color: var(--accent);
}

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: background 0.15s;
}

.primary-btn:active { background: var(--accent-dim); }

.secondary-btn {
  width: 100%;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.danger-btn {
  width: 100%;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.version-info {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 24px;
  opacity: 0.6;
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

#themePreview {
  min-height: 120px;
  width: 100%;
  border-radius: 6px;
  padding: 10px 12px;
  box-sizing: border-box;
  font-family: monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow: auto;
  background: var(--preview-bg, #000);
  color: var(--preview-fg, #e0e0e0);
  margin-bottom: 4px;
}

#themePreview .tp-prompt { color: var(--preview-cursor, #00ff88); }
#themePreview .tp-path { color: var(--preview-cursor, #00ff88); }
#themePreview .tp-dim { opacity: 0.6; }
#themePreview .tp-accent { color: var(--preview-cursor, #00ff88); }
#themePreview .tp-cursor {
  display: inline-block;
  width: 8px;
  background: var(--preview-cursor, #00ff88);
  animation: tpCursorBlink 1s step-end infinite;
}

@keyframes tpCursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.warn {
  color: #ffaa00;
}

code {
  background: var(--bg-card);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 11px;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Profile and key list items */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.empty-hint {
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.profile-item, .key-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.profile-item.tapped { border-color: var(--accent); }
.profile-item.profile-connected { border-color: var(--accent); border-width: 2px; }

/* Active sessions section (#306) */
.section-label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin: 8px 0 4px;
}
.active-session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
}
.active-session-item .session-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.session-dot.dot-connected { background: var(--accent); }
.session-dot.dot-connecting { background: var(--warning); animation: pulse-dot 1s infinite; }
.session-dot.dot-dropped { background: var(--danger); }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.active-session-item .session-label {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.active-session-item .item-btn { flex: none; padding: 6px 12px; }
.reconnect-all-btn {
  width: 100%;
  margin: 8px 0;
  padding: 10px;
  font-weight: bold;
}

.profile-conn-badge {
  font-size: 10px;
  font-weight: 600;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.4);
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: middle;
}

.session-actions {
  display: flex;
  gap: 6px;
  margin: 6px 0 2px;
  padding-top: 6px;
  border-top: 1px solid var(--accent-dim);
}

.item-btn.accent {
  background: var(--accent);
  color: var(--bg-deep);
  font-weight: 600;
}

/* .vault-badge removed — "saved" badge was non-actionable (#311) */

.profile-name, .key-name {
  font-weight: 600;
  font-size: 14px;
}

.profile-host {
  font-size: 12px;
  color: var(--text-dim);
  font-family: monospace;
}

.key-created {
  font-size: 12px;
  color: var(--text-dim);
}

.key-dropdown {
  width: 100%;
  padding: 8px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

#manualKeyGroup {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.item-btn {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 6px;
  font-size: 13px;
  cursor: pointer;
}

.item-btn.danger { color: var(--danger); }

/* Connecting animation on profile Connect button (#318) */
.item-btn.connecting {
  background: linear-gradient(90deg, var(--bg-input) 0%, var(--accent) 50%, var(--bg-input) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  color: var(--bg);
  pointer-events: none;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.form-section {
  display: flex;
  flex-direction: column;
}

/* Connect panel: form hidden when profiles exist */
.connect-form-hidden {
  display: none;
}


#newConnBtn {
  margin-top: 12px;
  width: 100%;
  position: sticky;
  bottom: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
}

/* Compact form: labels to left of inputs */
.compact-form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
}

.compact-form label {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

.compact-form input,
.compact-form select {
  margin: 0;
}

.compact-form .compact-form-span {
  grid-column: 1 / -1;
}

.compact-form .primary-btn {
  margin-top: 8px;
}

#connectAdvanced {
  margin-top: 4px;
}

#connectAdvanced summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9em;
  padding: 4px 0;
  user-select: none;
}

.compact-form-advanced {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
  margin-top: 8px;
}

.compact-form-advanced label {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

.compact-form-advanced input {
  margin: 0;
}

/* Advanced section */
.advanced-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.advanced-section-title {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0;
  margin-bottom: 8px;
}

/* Danger Zone section */
.danger-zone {
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 14px 16px;
}

.danger-zone-title {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0;
  margin-bottom: 8px;
}

.danger-zone-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 12px;
}

.danger-zone-item-info {
  flex: 1;
}

.danger-zone-item-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

/* Toggle switch — used in Danger Zone settings */
.toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 0;
}

.toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-slider {
  width: 44px;
  height: 24px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: rgba(255, 68, 68, 0.2);
  border-color: var(--danger);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
  background: var(--danger);
}

/* Toast notifications */
#toast {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--keybar-height) + var(--keybar-handle-height) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 1000;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#toast.show { opacity: 1; }

/* SSH host key verification overlay (#5) */
.hostkey-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.hostkey-dialog {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: calc(var(--viewport-height, 100svh) - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hostkey-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.hostkey-title-warn {
  color: #ffaa00;
}

.hostkey-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hostkey-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hostkey-val {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  background: var(--bg-card);
  padding: 5px 8px;
  border-radius: 4px;
  display: block;
}

.hostkey-fp-old {
  color: var(--danger);
}

.hostkey-warn-text {
  font-size: 13px;
  color: #ffaa00;
  font-weight: 500;
  line-height: 1.4;
}

.hostkey-info-text {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.hostkey-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  flex-shrink: 0;
}

.hostkey-btn {
  flex: 1;
  padding: 12px;
  border-radius: 6px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.hostkey-reject {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.hostkey-reject:active { background: var(--bg-input); }

.hostkey-accept {
  background: var(--accent);
  color: #000;
}

.hostkey-accept:active { background: var(--accent-dim); }

/* Vault setup / change password modal overlay */
.vault-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}


.error-dialog-text {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  color: var(--text);
  font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  user-select: text;
  -webkit-user-select: text;
}

.vault-hidden-username {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.vault-dialog {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  max-height: calc(var(--viewport-height, 100svh) - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vault-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
}

.vault-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 4px;
}

.vault-label {
  font-size: 12px;
  color: var(--text-dim);
  margin: 4px 0 2px;
}

.vault-error {
  font-size: 12px;
  color: var(--danger);
  margin: 0;
}


/* Password strength meter */
.vault-strength {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-input);
  overflow: hidden;
  margin: 2px 0 4px;
}

.vault-strength::after {
  content: '';
  display: block;
  height: 100%;
  width: var(--strength, 0%);
  border-radius: 2px;
  background: var(--strength-color, var(--text-dim));
  transition: width 0.2s, background 0.2s;
}

/* Biometric toggle in setup modal */
.vault-bio-option {
  display: flex;
  align-items: center;
  margin: 8px 0 4px;
}


.vault-bio-toggle {
  width: 100%;
  justify-content: space-between;
}

.vault-bio-label {
  font-size: 14px;
  color: var(--text);
}

/* Accent-colored toggle (non-danger) */
.toggle-slider-accent {}

.toggle input:checked + .toggle-slider-accent {
  background: rgba(0, 255, 136, 0.2);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-slider-accent::after {
  transform: translateX(20px);
  background: var(--accent);
}

.vault-buttons {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-shrink: 0;
}

.vault-btn {
  flex: 1;
  padding: 12px;
  border-radius: 6px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.vault-btn-cancel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.vault-btn-cancel:active { background: var(--bg-input); }

.vault-btn-create {
  background: var(--accent);
  color: #000;
}

.vault-btn-create:active { background: var(--accent-dim); }

/* Inline vault unlock bar — slides into active panel when vault is locked */
.vault-unlock-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}


.vault-unlock-bar input[type="password"] {
  flex: 1;
  min-width: 120px;
  padding: 8px 10px;
  font-size: 14px;
}

.vault-unlock-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

.vault-unlock-btn:active { background: var(--accent-dim); }

.vault-unlock-error {
  width: 100%;
  font-size: 12px;
  color: var(--danger);
  margin: 0;
}


/* Vault settings section */
.vault-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vault-settings-title {
  margin-top: 0;
}

.vault-status {
  font-size: 13px;
  color: var(--text-dim);
}

.vault-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}


/* Settings row — toggle item layout (used outside danger zone) */
.setting-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 12px;
}

.setting-row-info { flex: 1; min-width: 0; }

.setting-row select,
.setting-row button {
  max-width: 120px;
  flex-shrink: 0;
}

.setting-row-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}


/* Debug FAB — floating bug icon, bottom-right above tab bar (#208) */
.debug-fab {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 4px);
  right: 6px;
  z-index: 10002;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.4);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* Debug panel — collapsible top panel, pushes content down (#208) */
.debug-panel {
  flex-shrink: 0;
  max-height: 25vh;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 10px;
  border-bottom: 1px solid var(--accent);
}

.debug-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: rgba(0, 255, 136, 0.1);
  color: var(--accent);
  font-weight: bold;
  flex-shrink: 0;
}

.debug-panel-btn {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10px;
  cursor: pointer;
  margin-left: auto;
}

.debug-panel-btn + .debug-panel-btn { margin-left: 4px; }

.debug-panel-close {
  font-weight: bold;
  font-size: 12px;
}

.debug-panel-log {
  overflow-y: auto;
  padding: 4px 8px;
  color: #ccc;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.debug-line-warn { color: #ffaa00; }
.debug-line-error { color: #ff4444; }

/* Connection status overlay (#172) */
.conn-status-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px 12px;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.conn-status-dialog {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  padding: 10px 14px;
  max-width: 440px;
  max-height: calc(var(--viewport-height, 100svh) - 32px);
  overflow-y: auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.conn-status-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: calc(var(--viewport-height, 65vh) * 0.65);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.conn-status-message {
  font-size: 13px;
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

.conn-status-message:not(:last-child) {
  color: var(--text-dim);
}

.conn-status-cancel {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
  flex-shrink: 0;
}

.conn-status-cancel:active {
  background: var(--bg-input);
}
.conn-status-error {
  color: #f44;
  font-weight: 600;
}
.conn-status-failed .conn-status-cancel {
  background: var(--bg-input);
  border-color: #f44;
  color: #f44;
}

/* Files panel (#174) */

.files-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.files-crumb {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 4px;
  touch-action: manipulation;
}

.files-crumb:active {
  background: var(--bg-input);
}

.files-crumb-sep {
  color: var(--text-dim);
  padding: 0 1px;
}

.files-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.files-list {
  display: flex;
  flex-direction: column;
}

.files-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.files-entry[data-dir="true"] {
  color: var(--accent);
}

.files-entry:active {
  background: var(--bg-card);
}

.files-entry.files-selected {
  background: rgba(0, 255, 136, 0.1);
  border-left: 3px solid var(--accent);
}

.files-download-btn {
  background: #44aaff;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.files-entry-icon {
  font-size: 12px;
  font-weight: 600;
  width: 16px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.files-entry[data-dir="true"] .files-entry-icon {
  color: var(--accent);
}

.files-entry-name {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-entry-size {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 32px;
  text-align: right;
}

.files-entry-date {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 48px;
  text-align: right;
}

.files-loading,
.files-empty,
.files-error {
  padding: 24px 16px;
  text-align: center;
  font-size: 14px;
}

.files-loading {
  color: var(--text-dim);
}

.files-empty {
  color: var(--text-dim);
  font-style: italic;
}

.files-error {
  color: var(--danger);
}

/* Files panel context menu */
.ctx-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.ctx-menu {
  position: fixed;
  left: var(--ctx-x);
  top: var(--ctx-y);
  z-index: 201;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  min-width: 160px;
  overflow: hidden;
}

.ctx-menu-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.ctx-menu-item:last-child {
  border-bottom: none;
}

.ctx-menu-item:active {
  background: var(--bg-hover);
}

/* Files panel details sheet */
.files-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
}

.files-detail-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 201;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.files-detail-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.files-detail-table td {
  padding: 6px 0;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

.files-detail-table tr:last-child td {
  border-bottom: none;
}

.files-detail-table td:first-child {
  color: var(--text-dim);
  width: 36%;
  padding-right: 8px;
  word-break: normal;
}

.files-detail-close {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.files-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.files-upload-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.files-upload-btn:active {
  opacity: 0.8;
}
.files-upload-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.files-upload-input {
  display: none;
}

.files-transfer-status {
  font-size: 13px;
  color: var(--text-dim);
}

.files-upload-cancel {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}

.files-upload-cancel:active {
  opacity: 0.8;
}


#panel-files {
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
}

#panel-files.active {
  display: flex;
}

.files-subview {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.files-subtabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.files-subtab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 0;
  cursor: pointer;
  touch-action: manipulation;
  border-top: 2px solid transparent;
  position: relative;
}

.files-subtab.active {
  color: var(--accent);
  border-top-color: var(--accent);
}

.files-subtab:active {
  background: var(--bg-input);
}

.files-subtab-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg-deep);
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.transfer-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.transfer-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.transfer-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.transfer-direction {
  font-size: 14px;
  font-weight: bold;
  margin-right: 6px;
  flex-shrink: 0;
}

.transfer-direction-upload {
  color: var(--accent);
}

.transfer-direction-download {
  color: #44aaff;
}

.transfer-item-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.transfer-item-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-left: 8px;
}

.transfer-item-detail {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.transfer-item[data-status="done"] .transfer-item-pct {
  color: var(--accent);
}

.transfer-item[data-status="failed"] .transfer-item-pct {
  color: var(--danger);
}

.transfer-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.transfer-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

#filesTransfer .files-upload-btn {
  margin: 12px;
  align-self: center;
}
