:root {
  --bg: #1e1e1e;
  --fg: #cccccc;
  --toolbar-bg: #2d2d2d;
  --toolbar-fg: #cccccc;
  --accent: #007acc;
  --error: #f44747;
  --input-bg: #3c3c3c;
  --input-border: #555;
}

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

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.login-page { display: flex; align-items: center; justify-content: center; }

.login-container {
  background: var(--toolbar-bg);
  padding: 2rem;
  border-radius: 8px;
  width: 100%;
  max-width: 360px;
}

.login-container h1 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-weight: 300;
  font-size: 1.8rem;
}

.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--toolbar-fg);
}

.form-group input {
  width: 100%;
  padding: 0.5rem;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 1rem;
}

.form-group input:focus { outline: none; border-color: var(--accent); }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

button:hover { opacity: 0.9; }

.login-container button { width: 100%; padding: 0.6rem; margin-top: 0.5rem; }

.error { color: var(--error); font-size: 0.85rem; margin-bottom: 0.5rem; text-align: center; }

.qr-payload {
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 3.5rem;
}

.qr-display {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1rem 0;
  min-height: 200px;
  color: var(--fg);
  font-size: 0.85rem;
}

.qr-display .qr-svg {
  width: 200px;
  height: 200px;
  background: #fff;
  border-radius: 6px;
  padding: 8px;
}

.qr-confirm-code {
  text-align: center;
  margin: 0.5rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--fg);
  opacity: 0.85;
}

/* QR Scanner Modal */
.qr-scanner-modal[hidden] { display: none; }
.qr-scanner-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-scanner-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
}
.qr-scanner-panel {
  position: relative;
  background: var(--bg, #1e1e1e);
  border-radius: 8px;
  padding: 1rem;
  width: 90vw;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.qr-scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 1rem;
  color: var(--fg, #ccc);
}
.qr-scanner-header button {
  background: none;
  border: none;
  color: var(--fg, #ccc);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.3rem;
}
.qr-scanner-video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}
.qr-scanner-video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.qr-scanner-status {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
}
.qr-scanner-actions {
  margin-top: 0.75rem;
  text-align: center;
}

.terminal-page { display: flex; flex-direction: column; }

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.8rem;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--input-border);
  flex-shrink: 0;
}

.brand { font-weight: 600; font-size: 0.95rem; }

#client-count {
  font-size: 0.8rem;
  color: var(--toolbar-fg);
  opacity: 0.7;
  margin-left: 0.6rem;
  white-space: nowrap;
}

.toolbar-actions { display: flex; gap: 0.4rem; }

.mobile-only { display: none; }

#mobile-primary-actions {
  gap: 0.35rem;
}

#mobile-primary-actions button,
#mobile-quick-actions button,
.mobile-sheet-actions button {
  min-width: 44px;
  min-height: 44px;
}

.toolbar-actions button {
  background: transparent;
  color: var(--toolbar-fg);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  border: 1px solid var(--input-border);
}

.toolbar-actions button:hover { background: var(--input-bg); }

#terminal-container { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.tab-terminal-container { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.tab-terminal-container .xterm { height: 100%; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--toolbar-bg);
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--input-border);
}

.modal-title { font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 0.3rem;
}

.modal-path {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--accent);
  font-family: monospace;
}

.modal-list { overflow-y: auto; padding: 0 0.5rem 0.5rem; }

.file-entry {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  gap: 0.5rem;
  cursor: default;
}

.file-entry:hover { background: var(--input-bg); }
.file-entry.directory { cursor: pointer; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 0.8rem; color: #888; flex-shrink: 0; }
.file-dl-btn { font-size: 0.75rem; padding: 0.2rem 0.5rem; flex-shrink: 0; }
.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* Client selection modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-dialog {
  background: #1a1a2e;
  border: 1px solid #4488ff;
  border-radius: 8px;
  width: 90%;
  max-width: 460px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.modal-dialog h3 {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
  color: var(--fg);
}

.modal-dialog input[type="text"],
.modal-dialog input[type="password"] {
  width: 100%;
  padding: 0.5rem;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.9rem;
}

.modal-dialog input[type="text"]:focus,
.modal-dialog input[type="password"]:focus {
  outline: none;
  border-color: #4488ff;
}

/* Re-auth modal */
.reauth-dialog {
  max-width: 380px;
}

.reauth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.reauth-field label {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.8rem;
  color: #888;
}

.reauth-error {
  color: var(--error);
  font-size: 0.85rem;
  text-align: center;
}

.client-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-list-item {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}

.client-list-item:hover {
  background: var(--input-bg);
}

.client-list-item.selected {
  background: rgba(68, 136, 255, 0.15);
  border-color: #4488ff;
}

.client-list-name {
  font-size: 0.9rem;
  color: var(--fg);
}

.client-list-meta {
  font-size: 0.75rem;
  color: #888;
  margin-top: 2px;
}

.client-list-tag {
  display: inline-block;
  background: rgba(68, 136, 255, 0.2);
  color: #88aaff;
  border-radius: 3px;
  padding: 0 4px;
  font-size: 0.7rem;
  margin-right: 3px;
}

.client-list-empty {
  padding: 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: #888;
}

.fuzzy-highlight {
  color: #4488ff;
  font-weight: 600;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--input-border);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-secondary:hover {
  background: var(--input-bg);
}

.btn-primary {
  background: #4488ff;
  color: #fff;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: default;
}

/* TOFU trust dialogs */
.tofu-dialog {
  font-family: monospace;
}

.tofu-trust {
  border-color: #4488ff;
}

.tofu-mismatch {
  border-color: #ff4444;
}

.tofu-title {
  color: #4488ff;
}

.tofu-title-danger {
  color: #ff4444;
}

.tofu-message {
  font-size: 0.85rem;
  color: #ccc;
  line-height: 1.4;
}

.tofu-client-name {
  font-size: 0.85rem;
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
}

.tofu-label {
  color: #888;
  font-size: 0.8rem;
}

.tofu-label-received {
  margin-top: 0.5rem;
}

.tofu-value {
  color: var(--fg);
}

.tofu-fingerprint-box {
  background: #0d0d1a;
  padding: 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  word-break: break-all;
}

.tofu-fp {
  margin-top: 0.25rem;
  font-family: monospace;
}

.tofu-fp-new {
  color: #44ff44;
}

.tofu-fp-expected {
  color: #44ff44;
}

.tofu-fp-received {
  color: #ff4444;
}

.btn-danger {
  background: #ff4444;
  color: #fff;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-muted {
  color: #888;
  border-color: #444;
}

.theme-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.3rem;
  background: var(--toolbar-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  padding: 0.3rem;
  z-index: 50;
  min-width: 160px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.theme-option:hover { background: var(--input-bg); }
.theme-option.active { background: var(--accent); color: white; }

.theme-option-mobile {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: var(--toolbar-fg);
  border: 1px solid var(--input-border);
  margin-top: 0.35rem;
}

.theme-option-mobile:hover {
  background: var(--input-bg);
}

.theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid;
  flex-shrink: 0;
}

.upload-zone {
  margin: 0.5rem 1rem;
  padding: 1.2rem;
  border: 2px dashed var(--input-border);
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.drag-active {
  border-color: var(--accent);
  background: rgba(0, 122, 204, 0.08);
}

.upload-zone-text {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 0.6rem;
}

.upload-zone-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.upload-zone-buttons button {
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
}

.upload-modal-list {
  overflow-y: auto;
  padding: 0 0.5rem;
  max-height: 25vh;
  border-bottom: 1px solid var(--input-border);
}

#reauth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#reauth-overlay[hidden] { display: none; }

#reauth-overlay .login-container {
  background: var(--toolbar-bg);
}

#tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  margin: 0 0.6rem;
  scrollbar-width: none;
}

#tab-bar::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: transparent;
  color: var(--toolbar-fg);
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover { background: var(--input-bg); }

.tab.active {
  background: var(--bg);
  border-color: var(--input-border);
}

.tab-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-name[contenteditable="true"] {
  outline: 1px solid var(--accent);
  border-radius: 2px;
  padding: 0 2px;
  max-width: none;
}

.tab-close {
  background: none;
  border: none;
  color: var(--toolbar-fg);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.5;
  line-height: 1;
}

.tab-close:hover { opacity: 1; color: var(--error); }

.tab-new {
  background: transparent;
  color: var(--toolbar-fg);
  border: 1px dashed var(--input-border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.tab-new:hover { background: var(--input-bg); }

.mobile-sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
}

.mobile-sheet[hidden] {
  display: none;
}

.mobile-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.mobile-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--toolbar-bg);
  border-top: 1px solid var(--input-border);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  padding: 0.6rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
  max-height: calc(100dvh - 16px);
  display: flex;
  flex-direction: column;
}

.mobile-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.45rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.mobile-sheet-header button {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--toolbar-fg);
  min-width: 38px;
  min-height: 38px;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
}

.mobile-sheet-actions {
  display: grid;
  gap: 0.4rem;
  overflow-y: auto;
}

.mobile-sheet-actions button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--toolbar-fg);
  padding: 0.45rem 0.75rem;
  font-size: 0.92rem;
}

#mobile-theme-list {
  display: grid;
  gap: 0.2rem;
}

body.mobile-sheet-open {
  overflow: hidden;
}

.transfer-toast {
  position: fixed;
  bottom: 48px;
  right: 8px;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 40vh;
  overflow-y: auto;
  pointer-events: auto;
}

.transfer-entry {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.6rem;
  background: var(--toolbar-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--fg);
  min-width: 220px;
  max-width: 320px;
  opacity: 1;
  transition: opacity 0.4s;
}

.transfer-entry.fade-out {
  opacity: 0;
}

.transfer-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
}

.transfer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.transfer-bar {
  width: 70px;
  height: 6px;
  background: var(--input-bg);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.transfer-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.15s;
}

.transfer-fill.done { background: #4ec959; }
.transfer-fill.error { background: var(--error); }

.transfer-status {
  font-size: 0.72rem;
  color: #888;
  flex-shrink: 0;
  width: 40px;
  text-align: right;
}

.transfer-conflict-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.transfer-btn {
  border: none;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: inherit;
}

.transfer-btn-overwrite {
  background: var(--error);
  color: #fff;
}

.transfer-btn-overwrite:hover {
  filter: brightness(1.2);
}

.transfer-btn-rename {
  background: var(--accent);
  color: #fff;
}

.transfer-btn-rename:hover {
  filter: brightness(1.2);
}

@media (max-width: 768px) {
  #toolbar {
    padding: 0.35rem 0.5rem;
    gap: 0.4rem;
    justify-content: flex-start;
    overflow: hidden;
  }

  .brand {
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  #client-count {
    margin-left: 0.35rem;
    font-size: 0.75rem;
  }

  #tab-bar {
    margin: 0;
    min-width: 0;
    flex: 1;
    gap: 0.3rem;
  }

  .tab,
  .tab-new {
    min-height: 44px;
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
  }

  .tab-close {
    font-size: 0.9rem;
    padding: 0 4px;
  }

  .toolbar-actions {
    display: none;
  }

  .mobile-only {
    display: flex;
  }

  #mobile-primary-actions {
    margin-left: auto;
    flex-shrink: 0;
  }

  #mobile-primary-actions button {
    border: 1px solid var(--input-border);
    background: transparent;
    color: var(--toolbar-fg);
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
  }

  #btn-mobile-keyboard.is-active,
  #btn-mobile-menu.is-active {
    background: var(--input-bg);
  }

  #mobile-quick-actions {
    gap: 0.35rem;
    padding: 0.35rem 0.5rem;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--input-border);
  }

  #mobile-quick-actions button {
    flex: 1;
    border: 1px solid var(--input-border);
    background: transparent;
    color: var(--toolbar-fg);
    padding: 0.35rem 0.45rem;
    font-size: 0.8rem;
  }

  body.mobile-keyboard-open #mobile-quick-actions {
    display: none;
  }
}

@media (max-width: 420px) {
  .tab-name {
    max-width: 70px;
  }

  #client-count {
    display: none;
  }

  #mobile-primary-actions button {
    padding: 0.3rem 0.45rem;
    font-size: 0.74rem;
  }
}

@media (max-width: 768px) and (max-height: 500px) {
  #mobile-quick-actions {
    display: none;
  }
}

/* Relay tab loading dot */
.tab-loading-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4488ff;
  margin-left: 6px;
  animation: pulse-dot 1.2s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Relay retry button */
.relay-retry-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 6px 14px;
  background: #4488ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  z-index: 10;
  opacity: 0.9;
}

.relay-retry-btn:hover {
  opacity: 1;
}
