:root {
  --bg: #0b0f17;
  --bg-elev: #121826;
  --bg-card: #161e2e;
  --bg-input: #0e1420;
  --border: rgba(255, 255, 255, 0.1);
  --text: #edf2f7;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); line-height: 1.5; margin: 6px 0; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-ghost { background: rgba(255, 255, 255, 0.04); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-ghost.active { background: rgba(59, 130, 246, 0.22); border-color: rgba(59, 130, 246, 0.55); color: #93c5fd; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

input[type="text"], input[type="password"], select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}
.select-sm {
  width: auto;
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.pill.ok { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.pill.warn { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.pill.err { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

/* Login Screen */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #172554 0%, #0b0f17 65%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: rgba(22, 30, 46, 0.88);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.brand-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--text-muted); margin: 0 0 22px; font-size: 13px; }
.form-group { text-align: left; margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--text-muted); }
.error-banner {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 9px 12px;
  border-radius: 9px;
  margin-bottom: 14px;
  font-size: 13px;
}
.login-footer { margin-top: 18px; font-size: 11px; color: var(--text-muted); }

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.topbar {
  height: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.node-select {
  width: auto;
  max-width: 170px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
}
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 8px rgba(34, 197, 94, 0.7); }

.nav-tabs {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.04);
  padding: 3px;
  border-radius: 10px;
}
.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.nav-tab.active {
  background: var(--primary);
  color: #fff;
}
.quick-metrics {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Tab Panels */
.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}
.tab-panel.active {
  display: flex;
}
.scroll-panel {
  overflow-y: auto;
  padding: 16px;
}

/* Desktop Toolbar & Stage */
.desktop-toolbar, .sub-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 12px;
  background: #101622;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.segmented {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

.desktop-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #05070c;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.vnc-viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.vnc-screen {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  will-change: transform;
}
.vnc-screen canvas {
  display: block;
}

.virtual-cursor {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  background: rgba(59, 130, 246, 0.65);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
  z-index: 25;
}

.sr-only-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  left: -9999px;
  top: 0;
}

/* Pre-connect Overlay */
.vnc-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 12, 20, 0.86);
  backdrop-filter: blur(8px);
}
.vnc-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.vnc-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.vnc-card-header h2 { margin: 0; font-size: 18px; }
.vnc-pw-form { margin-top: 14px; }
.vnc-pw-form label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.inline-row { display: flex; gap: 8px; }
.checkbox-row {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.checkbox-row input { width: auto; }
.checkbox-row.compact { margin-top: 0; }
.vnc-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.touch-guide {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  font-size: 12px;
  color: #bfdbfe;
  line-height: 1.5;
}

/* Floating macOS Virtual Keybar */
.mac-keybar {
  flex-shrink: 0;
  background: #121927;
  border-top: 1px solid var(--border);
  padding: 6px 8px;
}
.keybar-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.keybar-scroll::-webkit-scrollbar { display: none; }
.key-btn {
  flex-shrink: 0;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.key-btn:active { background: rgba(59, 130, 246, 0.35); }
.key-btn.latched {
  background: var(--primary);
  border-color: #60a5fa;
  color: #fff;
}
.key-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* Terminal */
.terminal-container {
  flex: 1;
  min-height: 0;
  background: #0a0e14;
  padding: 8px;
}
.term-quick-keys {
  overflow-x: auto;
  flex-wrap: nowrap;
}

/* Files */
.fs-path-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.fs-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}
.fs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.fs-row:hover { background: rgba(255, 255, 255, 0.04); }
.fs-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}
.fs-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.fs-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.fs-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* System Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 1200px;
  margin: 0 auto;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card.span-2 { grid-column: span 2; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-header h3 { margin: 0; font-size: 15px; }

.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.node-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.node-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.4);
}
.node-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.metric-bars { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.bar-row { font-size: 12px; color: var(--text-muted); }
.bar-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 3px;
}
.bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }

.native-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.native-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #080c14;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  overflow-x: auto;
}
.code-box code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: #93c5fd;
  word-break: break-all;
}
.security-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.security-grid h4 { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); }

/* Modals & Toast */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 18px;
}
.modal-card.modal-lg { max-width: 820px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
#editor-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: #1e293b;
  border: 1px solid rgba(59, 130, 246, 0.5);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Mobile Responsive Overrides */
@media (max-width: 768px) {
  .quick-metrics { display: none; }
  .nav-tab span { display: none; }
  .nav-tab { padding: 6px 10px; font-size: 15px; }
  .node-select { max-width: 120px; font-size: 12px; }
  .dashboard-grid, .security-grid { grid-template-columns: 1fr; }
  .card.span-2 { grid-column: span 1; }
  .desktop-toolbar { padding: 6px 8px; gap: 6px; }
}

/* ==================== SENIOR CARE MODE (長輩大字極簡模式) ==================== */
body.senior-mode {
  font-size: 18px;
}
body.senior-mode .topbar {
  height: 58px;
  padding: 0 14px;
}
body.senior-mode .node-select {
  max-width: 190px;
  font-size: 17px;
  padding: 7px 12px;
}
body.senior-mode #nav-tabs,
body.senior-mode .quick-metrics,
body.senior-mode .desktop-toolbar,
body.senior-mode #mac-keybar {
  display: none !important;
}
body.senior-mode #btn-ui-mode {
  font-size: 15px;
  padding: 8px 14px;
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(96, 165, 250, 0.6);
  color: #dbeafe;
}

.senior-home {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: radial-gradient(circle at top, #172554 0%, #0b0f17 70%);
}
.senior-card {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.senior-greeting {
  font-size: 26px;
  font-weight: 800;
  text-align: center;
  color: #f8fafc;
}
.senior-node-pill {
  align-self: center;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  border: 1.5px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
  font-size: 16px;
  font-weight: 700;
}
.senior-big-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px 22px;
  border-radius: 18px;
  border: 2px solid transparent;
  color: #fff;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s;
}
.senior-big-btn:active { transform: scale(0.98); }
.senior-big-btn .big-ico { font-size: 38px; line-height: 1; flex-shrink: 0; }
.senior-big-btn strong { display: block; font-size: 23px; font-weight: 800; line-height: 1.25; }
.senior-big-btn small { display: block; font-size: 14.5px; opacity: 0.9; margin-top: 3px; }
.senior-big-btn.primary { background: linear-gradient(135deg, #2563eb, #3b82f6); border-color: #60a5fa; }
.senior-big-btn.green { background: linear-gradient(135deg, #059669, #10b981); border-color: #34d399; }
.senior-big-btn.amber { background: linear-gradient(135deg, #d97706, #f59e0b); border-color: #fbbf24; }

.senior-tip-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15.5px;
  color: #cbd5e1;
  line-height: 1.6;
}

/* Giant 5-Button Senior Dock */
.senior-dock {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: #111827;
  border-top: 2px solid rgba(255, 255, 255, 0.12);
}
.sd-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 58px;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  background: #1e293b;
  color: #f8fafc;
  cursor: pointer;
  padding: 6px 4px;
}
.sd-btn span { font-size: 22px; line-height: 1.1; }
.sd-btn b { font-size: 13.5px; font-weight: 700; }
.sd-btn.primary { background: #2563eb; border-color: #60a5fa; }
.sd-btn.danger { background: #7f1d1d; border-color: #ef4444; color: #fecaca; }
.sd-btn:active { transform: scale(0.95); }

/* Senior Mode Large File Rows & Clipboard Modal */
body.senior-mode .fs-row { padding: 15px 14px; font-size: 18px; }
body.senior-mode .btn-sm { padding: 10px 14px; font-size: 16px; }
body.senior-mode #clipboard-textarea { font-size: 20px; line-height: 1.5; }
body.senior-mode .modal-actions .btn { padding: 14px 18px; font-size: 18px; }

/* Visual tap ripple for clear feedback */
.tap-ripple {
  position: fixed;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #60a5fa;
  background: rgba(59, 130, 246, 0.35);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.4);
  animation: tapPop 0.38s ease-out forwards;
  z-index: 80;
}
@keyframes tapPop {
  to { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}
