/* ═══════════════════════════════════════════════════════════
   Remote Control — Design System
   A ScreenConnect-inspired dark professional UI
   ═══════════════════════════════════════════════════════════ */

/* ── Design Tokens ───────────────────────────── */
:root {
  /* Surfaces */
  --bg-root: #0a0e17;
  --bg-elevated: #111827;
  --bg-surface: #182230;
  --bg-hover: #1f2a3a;
  --bg-active: #263348;
  --bg-input: #0d1321;

  /* Borders */
  --border-subtle: #1e293b;
  --border-default: #334155;
  --border-strong: #475569;
  --border-accent: #3b82f6;

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;

  /* Brand / Accent */
  --brand: #3b82f6;
  --brand-hover: #2563eb;
  --brand-ring: rgba(59, 130, 246, 0.35);

  /* Semantic */
  --success: #22c55e;
  --success-bg: #14532d;
  --warning: #f59e0b;
  --warning-bg: #78350f;
  --danger: #ef4444;
  --danger-bg: #7f1d1d;
  --info: #06b6d4;
  --info-bg: #164e63;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Typography */
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 28px;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 16px var(--brand-ring);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ── Reset & Base ────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-elevated); }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

::selection {
  background: var(--brand);
  color: white;
}

/* ── Typography ──────────────────────────────── */
h1 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--text-xl); font-weight: 600; }
h3 { font-size: var(--text-lg); font-weight: 600; }
h4 { font-size: var(--text-base); font-weight: 600; }

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--brand-hover); }

/* ── Layout ──────────────────────────────────── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.container-wide {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4);
}

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

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }

/* ── Cards ───────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover {
  border-color: var(--border-default);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.card-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}
.card-body { }

/* Stat card */
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.stat-card .stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}
.stat-card .stat-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
  outline: none;
  position: relative;
  user-select: none;
}
.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-primary {
  background: var(--brand);
  color: white;
}
.btn-primary:hover { background: var(--brand-hover); box-shadow: var(--shadow-sm); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #16a34a; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-icon {
  padding: var(--space-2);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
}
.btn-icon.sm { width: 28px; height: 28px; padding: var(--space-1); }

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); }

/* ── Status Dots ─────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.sm { width: 6px; height: 6px; }
.status-dot.lg { width: 10px; height: 10px; }
.status-dot.live { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.idle { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.status-dot.offline { background: var(--danger); }
.status-dot.pulse { animation: status-pulse 2s ease-in-out infinite; }

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

/* ── Inputs ──────────────────────────────────── */
input[type="text"],
input[type="file"],
input[type="search"],
textarea,
select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

input[type="file"] {
  padding: var(--space-1);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
  margin-right: var(--space-2);
  transition: background var(--transition-fast);
}
input[type="file"]::file-selector-button:hover { background: var(--bg-active); }

/* ── Code blocks / Tokens ────────────────────── */
.code-block {
  background: var(--bg-root);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--info);
  word-break: break-all;
  display: inline-block;
  max-width: 100%;
}
.token-secret {
  filter: blur(5px);
  cursor: pointer;
  transition: filter var(--transition-base);
  user-select: none;
}
.token-secret:hover, .token-secret.revealed {
  filter: none;
  user-select: all;
}

/* ── Tooltips ────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-active);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Spinner ─────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.sm { width: 12px; height: 12px; }
.spinner.lg { width: 24px; height: 24px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast Notifications ─────────────────────── */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 380px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toast-in var(--transition-base) ease forwards;
  font-size: var(--text-sm);
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }

.toast .toast-icon { flex-shrink: 0; font-size: 16px; }
.toast .toast-body { flex: 1; }
.toast .toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
}
.toast .toast-close:hover { color: var(--text-primary); }
.toast.toast-leaving { animation: toast-out var(--transition-fast) ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Toolbar (guest) ─────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
  min-height: 42px;
}
.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-default);
  margin: 0 var(--space-1);
}

/* ── Screen Container ────────────────────────── */
.screen-container {
  position: relative;
  overflow: auto;
  background: #000;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 200px;
  max-height: calc(100vh - 180px);
}
.screen-container canvas {
  display: block;
  cursor: crosshair;
  image-rendering: auto;
}
.screen-container .canvas-focused {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.screen-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10);
  color: var(--text-muted);
  text-align: center;
}
.screen-placeholder .placeholder-icon { font-size: 48px; opacity: 0.3; }
.screen-placeholder .placeholder-text { font-size: var(--text-lg); }

/* ── Side Panel (guest sub-panels) ───────────── */
.side-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
}
.side-panel.open { transform: translateX(0); }

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.side-panel-header h3 { font-size: var(--text-lg); }
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}
.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.side-panel-overlay.open { opacity: 1; pointer-events: all; }

/* ── Tabs ────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-4);
}
.tab-btn {
  padding: var(--space-2) var(--space-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* ── Session list ────────────────────────────── */
.session-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--transition-fast);
}
.session-row:hover { border-color: var(--border-default); }
.session-row .session-id {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--info);
  font-weight: 600;
}
.session-row .session-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── Connection quality meter ────────────────── */
.quality-meter {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.quality-bar {
  width: 3px;
  height: 10px;
  border-radius: 1px;
  background: var(--border-default);
  transition: background var(--transition-base);
}
.quality-bar.lit { background: var(--success); }
.quality-bar.lit.medium { background: var(--warning); }
.quality-bar.lit.poor { background: var(--danger); }

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: var(--space-4); }
.modal .kbd-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2) var(--space-4);
  align-items: center;
}
.modal .kbd-label { color: var(--text-secondary); font-size: var(--text-sm); }

/* ── Keyboard key ────────────────────────────── */
kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  line-height: 1.5;
  box-shadow: 0 1px 0 var(--border-default);
}

/* ── Shell output ────────────────────────────── */
.shell-output {
  background: #050a14;
  color: #22c55e;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  max-height: 400px;
  min-height: 100px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
.shell-output .prompt { color: var(--info); }

/* ── File log ────────────────────────────────── */
.file-log {
  max-height: 180px;
  overflow-y: auto;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-log .log-entry { padding: 2px 0; border-bottom: 1px solid var(--border-subtle); }
.file-log .log-entry:last-child { border-bottom: none; }

/* ── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 32px; margin-bottom: var(--space-2); opacity: 0.4; }

/* ── Utility ─────────────────────────────────── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-mono { font-family: var(--font-mono); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mr-2 { margin-right: var(--space-2); }

/* ── Animation ───────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fade-in var(--transition-base) ease forwards; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .container { padding: var(--space-4) var(--space-3); }
  .toolbar { gap: var(--space-1); padding: var(--space-2); }
  .toolbar .stats { display: none; }
  .side-panel { width: 100vw; max-width: 100vw; }
}

@media (max-width: 480px) {
  .toolbar button { padding: var(--space-1) var(--space-2); font-size: var(--text-xs); }
}
