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

:root {
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-input: #0f3460;
  --text: #e8e8e8;
  --text-dim: #8888a0;
  --accent: #e94560;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --gray: #9ca3af;
  --border: #2a2a4a;
  --radius: 8px;
}

[data-theme="light"] {
  --bg: #f0f0f5;
  --bg-surface: #ffffff;
  --bg-input: #e8e8f0;
  --text: #1a1a2e;
  --text-dim: #555570;
  --accent: #e94560;
  --border: #d0d0e0;
}

html, body {
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.screen {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Status bar */
#status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
  flex-shrink: 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.connected { background: var(--green); }
.dot.connecting { background: var(--yellow); animation: pulse 1.5s ease-in-out infinite; }
.dot.disconnected { background: var(--gray); }

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

#status-text {
  font-size: 14px;
  color: var(--text-dim);
  flex: 1;
}

.theme-toggle {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pairing screen */
.pairing-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}

.pairing-container h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.pairing-container p {
  color: var(--text-dim);
  text-align: center;
  font-size: 16px;
}

#pairing-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  margin: 16px 0;
}

.pairing-word {
  font-size: 16px;
  padding: 14px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.pairing-word:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  max-width: 320px;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error {
  color: var(--red);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

/* Main screen */
#main-screen {
  display: flex;
  flex-direction: column;
}

#terminal-container {
  flex: 1;
  overflow: hidden;
  padding: 4px;
  background: var(--terminal-bg, #000);
  min-height: 0;
}


[data-theme="light"] #terminal-container {
  --terminal-bg: #ffffff;
}

/* Terminal grid layouts */
.terminal-grid {
  display: grid;
  gap: 4px;
  height: 100%;
}

.terminal-grid.layout-single {
  grid-template: 1fr / 1fr;
}

.terminal-grid.layout-side-by-side {
  grid-template: 1fr / 1fr 1fr;
}

.terminal-grid.layout-stacked {
  grid-template: 1fr 1fr / 1fr;
}

.terminal-grid.layout-quad {
  grid-template: 1fr 1fr / 1fr 1fr;
}

.terminal-slot {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}

[data-theme="light"] .terminal-slot {
  background: #fff;
}

.terminal-slot.focused {
  border-color: var(--accent);
}

.terminal-titlebar {
  display: flex;
  align-items: center;
  padding: 0 8px;
  height: 28px;
  min-height: 28px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
}

.terminal-slot.focused .terminal-titlebar {
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-surface));
}

.terminal-title {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.terminal-slot.focused .terminal-title {
  color: var(--text);
}

.terminal-close {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  opacity: 0;
  transition: opacity 0.15s;
}

.terminal-slot:hover .terminal-close,
.terminal-slot.focused .terminal-close {
  opacity: 1;
}

.terminal-close:hover {
  background: var(--red);
  color: white;
}

.terminal-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.terminal-content .xterm {
  height: 100%;
}

/* Layout controls */
#layout-controls {
  display: flex;
  gap: 2px;
  margin-left: 8px;
  flex-shrink: 0;
}

.layout-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.layout-btn.active {
  background: #3b82f6;
  color: white;
}

/* Paging controls */
#paging-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  flex-shrink: 0;
}

.paging-btn {
  width: 24px;
  height: 24px;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  touch-action: manipulation;
}

#page-indicator {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 24px;
  text-align: center;
}

/* (xterm sizing handled by .terminal-content .xterm above) */

/* Approval overlay */
#approval-overlay {
  position: absolute;
  bottom: 110px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px;
  z-index: 10;
}

#approval-overlay button {
  padding: 16px 40px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-width: 140px;
  touch-action: manipulation;
}

.btn-approve {
  background: var(--green);
  color: #000;
}

.btn-deny {
  background: var(--red);
  color: white;
}

/* Input bar */
#input-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input-field {
  flex: 1;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
}

#input-field:focus {
  border-color: var(--accent);
}

#send-btn {
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

/* Session bar */
#session-bar {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  flex-shrink: 0;
  min-height: 44px;
}

#session-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#session-tabs::-webkit-scrollbar {
  display: none;
}

.session-tab {
  position: relative;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: manipulation;
}

.session-tab.active {
  /* background and color set inline via hue */
}

.attention-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: attention-pulse 1s ease-in-out infinite;
}

@keyframes attention-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

#new-session-btn {
  width: 36px;
  height: 36px;
  font-size: 20px;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 6px;
  touch-action: manipulation;
}

/* Folder browser modal */
#folder-browser {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

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

.fb-modal {
  position: relative;
  width: 90%;
  max-width: 480px;
  max-height: 80dvh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.fb-nav-btn {
  width: 36px;
  height: 36px;
  font-size: 18px;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: opacity 0.15s;
}

.fb-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.fb-path-display {
  flex: 1;
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
}

.fb-list {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  max-height: 50dvh;
  padding: 4px;
}

.fb-item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  text-align: left;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.fb-item:hover,
.fb-item:active {
  background: var(--bg-input);
}

.fb-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.fb-newfolder-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.fb-newfolder-row input {
  flex: 1;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
}

.fb-newfolder-row input:focus {
  border-color: var(--accent);
}

.fb-newfolder-row button {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

#fb-error {
  padding: 0 12px;
  flex-shrink: 0;
}

.fb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-top: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

.fb-actions button {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}

#fb-newfolder-btn {
  background: var(--bg-input);
  color: var(--text);
}

.fb-actions-right {
  display: flex;
  gap: 8px;
}

#fb-cancel-btn {
  background: var(--bg-input);
  color: var(--text-dim);
}

#fb-select-btn {
  background: var(--accent);
  color: white;
}

/* Virtual keyboard accessory bar */
#virtual-keybar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.vk-modifiers {
  display: flex;
  gap: 6px;
  flex: 1;
}

.vk-btn {
  min-width: 44px;
  height: 34px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.vk-btn:active {
  background: var(--accent);
  color: white;
}

.vk-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Arrow keys in inverted-T layout */
.vk-arrows {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(2, 34px);
  gap: 2px;
  flex-shrink: 0;
}

.vk-arrow {
  min-width: 0;
  width: 34px;
  height: 34px;
  font-size: 14px;
  padding: 0;
}

.vk-arrow[data-key="up"]   { grid-column: 2; grid-row: 1; }
.vk-arrow[data-key="left"]  { grid-column: 1; grid-row: 2; }
.vk-arrow[data-key="down"]  { grid-column: 2; grid-row: 2; }
.vk-arrow[data-key="right"] { grid-column: 3; grid-row: 2; }

/* Share button */
.share-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Share modal overlay */
.share-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.share-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.share-modal {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  width: 90%;
}

.share-modal h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.share-modal p {
  font-size: 14px;
  color: var(--text-dim);
}

.share-modal-qr {
  border-radius: 8px;
  max-width: 240px;
  max-height: 240px;
}

.share-modal-url {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  text-align: center;
  width: 100%;
}

.share-modal-copy {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: opacity 0.2s;
}

.share-modal-copy:active { opacity: 0.7; }
.share-modal-copy.copied { background: var(--green); }

.share-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.share-modal-close:hover {
  background: var(--bg-input);
}
