:root {
  /* Elite Pastel & Cashmere Palette */
  --bg-main: #111116;
  --bg-card: rgba(255, 255, 255, 0.035);
  --bg-card-hover: rgba(255, 255, 255, 0.065);
  --bg-input: rgba(255, 255, 255, 0.04);
  
  --border-color: rgba(255, 255, 255, 0.07);
  --border-subtle: rgba(255, 255, 255, 0.035);
  --border-focus: rgba(196, 181, 253, 0.55);
  
  --text-main: #fbfbf9;
  --text-muted: #b8b5ad;
  --text-dim: #78756e;
  
  --accent: #c4b5fd;
  --accent-secondary: #fbcfe8;
  --accent-gradient: linear-gradient(135deg, #c4b5fd 0%, #fbcfe8 100%);
  
  --success: #6ee7b7;
  --warning: #fcd34d;
  --danger: #f87171;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  
  --font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  background-image: 
    radial-gradient(at 15% 15%, rgba(196, 181, 253, 0.04) 0px, transparent 55%),
    radial-gradient(at 85% 85%, rgba(251, 207, 232, 0.03) 0px, transparent 55%);
}

/* Header */
.app-header {
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: rgba(17, 17, 22, 0.7);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-badge-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a1625;
}
.brand-info {
  display: flex;
  flex-direction: column;
}
.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px rgba(110, 231, 183, 0.8);
}
.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.6);
}
.status-label {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

/* Navigation Tabs */
.nav-tabs {
  height: 48px;
  display: flex;
  background: rgba(12, 12, 16, 0.8);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.nav-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}
.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(196, 181, 253, 0.05);
}

/* Main Body Area */
.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}
.tab-content.active {
  display: flex;
}

/* TAB 1: Screen Viewport */
.screen-controls {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-pill:hover, .btn-pill:active {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}
.btn-pill.streaming .live-dot {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
  animation: pulse 1s infinite alternate;
}
@keyframes pulse { from { opacity: 0.4; } to { opacity: 1; } }

.click-mode-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-pill);
  padding: 2px;
  border: 1px solid var(--border-color);
}
.mode-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.mode-btn.active {
  background: var(--accent-gradient);
  color: #1a1625;
}

.screen-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #08080c;
  overflow: hidden;
  position: relative;
  touch-action: none;
  user-select: none;
}
.screen-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 100%;
}
#screenImage {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 170px);
  max-height: calc(100dvh - 170px);
  object-fit: contain;
  pointer-events: auto;
  border-radius: 4px;
}
.touch-ripple {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(196, 181, 253, 0.7);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}
.touch-ripple.active {
  transform: translate(-50%, -50%) scale(1.5);
  opacity: 1;
}

.screen-hint {
  padding: 6px 12px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(12, 12, 16, 0.85);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* TAB 2: Virtual Trackpad */
.trackpad-surface {
  flex: 1;
  margin: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  position: relative;
  box-shadow: inset 0 2px 20px rgba(0, 0, 0, 0.5);
}
.trackpad-surface:active {
  border-color: rgba(196, 181, 253, 0.35);
  background: rgba(255, 255, 255, 0.035);
}
.trackpad-center-mark {
  text-align: center;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.trackpad-center-mark span {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}
.trackpad-center-mark small {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.trackpad-buttons {
  height: 64px;
  padding: 0 14px 14px;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.trackpad-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: var(--transition);
}
.trackpad-btn:active {
  background: var(--accent-gradient);
  color: #1a1625;
  border-color: transparent;
  transform: scale(0.98);
}

/* TAB 3: Remote Scroll */
.remote-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.control-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 12px;
}
.text-input-row {
  display: flex;
  gap: 8px;
}
#typeTextInput {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: white;
  padding: 10px 12px;
  font-size: 0.88rem;
  outline: none;
}
#typeTextInput:focus {
  border-color: var(--border-focus);
}
.btn-action {
  background: var(--accent-gradient);
  color: #1a1625;
  font-weight: 600;
  border: none;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.button-grid {
  display: grid;
  gap: 8px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.btn-cmd {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 10px 8px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 44px;
}
.btn-cmd:active {
  background: rgba(196, 181, 253, 0.2);
  border-color: var(--accent);
  transform: scale(0.96);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 12, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-card {
  background: rgba(22, 22, 28, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
}
.modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(196, 181, 253, 0.12);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 22px;
  line-height: 1.45;
}
.modal-desc small {
  color: var(--text-dim);
  display: block;
  margin-top: 4px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-form input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.95rem;
  outline: none;
}
.login-form input:focus {
  border-color: var(--border-focus);
}
.login-error {
  color: var(--danger);
  font-size: 0.8rem;
  background: rgba(248, 113, 113, 0.1);
  padding: 8px;
  border-radius: var(--radius-sm);
}
.btn-primary {
  background: var(--accent-gradient);
  color: #1a1625;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
}
.hidden { display: none !important; }
