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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Top bar ─────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 10px;
  background: var(--bg-secondary);
  backdrop-filter: blur(var(--blur-amount));
  -webkit-backdrop-filter: blur(var(--blur-amount));
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 8px;
  z-index: 10;
  position: relative;
}

/* Accent line at top */
.top-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--accent-gradient);
  opacity: 0.5;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.15rem;
  width: 34px;
  height: 34px;
  padding: 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.menu-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.app-title {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

.top-bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Connection status pill */
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 6px;
  border-radius: var(--radius-pill);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.15);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--red);
  transition: all var(--transition-normal);
  white-space: nowrap;
}

.connection-status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
  box-shadow: 0 0 5px var(--red);
}

.connection-status.connected {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.15);
  color: var(--green);
}

.connection-status.connected::before {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.connection-status:not(.connected) {
  animation: status-pulse 2.5s ease-in-out infinite;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  padding: 0;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ── Terminal container ──────────────────────────── */
.terminal-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--terminal-bg);
}

.terminal-container::-webkit-scrollbar {
  width: 4px;
}
.terminal-container::-webkit-scrollbar-track {
  background: transparent;
}
.terminal-container::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 2px;
}

/* ── QR button ───────────────────────────────────── */
.qr-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 0;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.qr-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ── QR modal ────────────────────────────────────── */
.qr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-modal-overlay[hidden] {
  display: none;
}

.qr-modal {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg, 12px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: min(360px, 90vw);
  width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.qr-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.qr-modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.qr-modal-image {
  width: min(260px, 80vw);
  height: min(260px, 80vw);
  display: block;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.qr-modal-url {
  font-size: 0.72rem;
  color: var(--text-secondary);
  word-break: break-all;
  text-align: center;
  max-width: 100%;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
}

/* ── Desktop layout ──────────────────────────────── */
@media (min-width: 1024px) {
  body {
    display: flex;
    flex-direction: row;
  }

  .sidebar-overlay {
    display: none;
  }

  .app-container {
    flex: 1;
    min-width: 0;
  }

  .top-bar {
    height: 50px;
    padding: 0 18px;
  }

  .menu-btn {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .connection-status:not(.connected) { animation: none; }
}

.connection-status.reconnecting {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
}
.connection-status.reconnecting::before {
  background: var(--yellow);
  box-shadow: 0 0 5px var(--yellow);
}

.terminal-container.stale { position: relative; }
.terminal-container.stale::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}
