/* Light Theme (Default - AnyDesk / TeamViewer Clean Style) */
:root {
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-header: #ffffff;
  --bg-input: #ffffff;
  --bg-input-hover: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --overlay-bg: rgba(241, 245, 249, 0.88);
  --card-shadow: 0 20px 35px -10px rgba(15, 23, 42, 0.12), 0 8px 16px -6px rgba(15, 23, 42, 0.06);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-card: #151c2c;
  --bg-header: #151c2c;
  --bg-input: #1e293b;
  --bg-input-hover: #26334a;
  --border-color: #334155;
  --border-focus: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --overlay-bg: rgba(11, 15, 25, 0.88);
  --card-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-family);
  user-select: none;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Header */
.app-header {
  height: 54px;
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
  position: relative;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* Session Info */
.session-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-badge {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-main);
  font-weight: 500;
}

/* Session Toolbar */
.session-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.tool-btn svg {
  width: 14px;
  height: 14px;
}

.tool-btn:hover {
  background: var(--bg-card);
  border-color: var(--border-focus);
}

.tool-btn.danger {
  color: var(--accent-red);
  border-color: rgba(239, 68, 68, 0.3);
}

.tool-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--accent-red);
}

/* Header Right Area */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle-btn:hover {
  border-color: var(--border-focus);
}

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
}

/* Toggle icon display based on current theme */
[data-theme="dark"] .theme-toggle-btn .sun-icon {
  display: block;
}
[data-theme="dark"] .theme-toggle-btn .moon-icon {
  display: none;
}
:root:not([data-theme="dark"]) .theme-toggle-btn .sun-icon {
  display: none;
}
:root:not([data-theme="dark"]) .theme-toggle-btn .moon-icon {
  display: block;
}

/* Status Indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.disconnected {
  background: var(--accent-red);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.status-dot.ready {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.status-dot.connecting {
  background: var(--accent-yellow);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: pulse 1.5s infinite;
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* Main View Area */
.main-container {
  width: 100%;
  height: calc(100% - 54px);
  position: relative;
  overflow: hidden;
  background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Viewport Wrapper & Canvas */
.viewport-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

#remoteCanvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: crosshair;
  outline: none;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.mobile-virtual-input {
  position: absolute;
  top: -9999px;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Connect Dialog */
.connect-dialog-overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: background-color 0.25s ease;
}

.connect-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 32px 28px;
  animation: fadeIn 0.25s ease-out;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.connect-header {
  text-align: center;
  margin-bottom: 24px;
}

.connect-logo {
  width: 68px;
  height: 68px;
  object-fit: contain;
  margin: 0 auto 16px auto;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.1));
}

.connect-icon {
  width: 56px;
  height: 56px;
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.2);
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
}

.connect-icon svg {
  width: 28px;
  height: 28px;
}

.connect-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.connect-header p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Form */
.connect-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.input-wrapper input,
.settings-content input,
.settings-content select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
}

.input-wrapper input:focus,
.settings-content input:focus,
.settings-content select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#hostIdInput {
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 1px;
}

/* Advanced Server Settings */
.server-settings {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.server-settings summary {
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
  color: var(--primary);
  font-weight: 500;
}

.settings-content {
  margin-top: 10px;
  padding: 12px;
  background: var(--bg-main);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Error Banner */
.error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--accent-red);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 500;
}

/* Connect Button */
.btn-connect {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  transition: all 0.2s;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.btn-connect:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.btn-connect:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Divider & QR Scan Button */
.connect-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  margin: -2px 0;
}

.connect-divider::before,
.connect-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.btn-scan-qr {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-scan-qr svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.btn-scan-qr:hover {
  background: var(--bg-input-hover);
  border-color: var(--border-focus);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

/* Camera QR Scanner Modal */
.qr-scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 300;
}

.qr-scanner-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.2s ease-out;
}

.qr-scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.qr-scanner-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.qr-scanner-title svg {
  width: 20px;
  height: 20px;
  color: var(--primary);
}

.qr-scanner-close-icon {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.qr-scanner-close-icon:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.scanner-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

#qrScannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-focus-box {
  position: absolute;
  width: 56px;
  height: 56px;
  border: 2px solid #38bdf8;
  border-radius: 10px;
  transform: translate(-50%, -50%) scale(1.2);
  pointer-events: none;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
  animation: focusPulse 0.65s ease-out forwards;
  z-index: 10;
}

@keyframes focusPulse {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(0.95); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

.qr-scanner-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.45;
}

.btn-scanner-cancel {
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-scanner-cancel:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ==========================================================================
   Responsive Mobile & Tablet Rules
   ========================================================================== */
@media (max-width: 840px) {
  #hostBadge,
  #resBadge {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .app-header {
    height: 48px;
    padding: 0 8px;
    gap: 6px;
  }

  .main-container {
    height: calc(100% - 48px);
  }

  .brand {
    gap: 6px;
  }

  .brand-subtitle {
    display: none;
  }

  .brand-title {
    font-size: 14px;
  }

  .brand-logo {
    width: 26px;
    height: 26px;
  }

  .session-info {
    gap: 4px;
  }

  .info-badge {
    padding: 2px 6px;
    font-size: 10px;
  }

  .session-toolbar {
    gap: 4px;
  }

  .tool-btn {
    padding: 6px 8px;
  }

  .tool-btn .btn-label {
    display: none;
  }

  .header-right {
    gap: 6px;
  }

  .status-text {
    display: none;
  }

  .theme-toggle-btn {
    width: 28px;
    height: 28px;
  }

  .connect-card {
    margin: 12px;
    padding: 20px 16px;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    overflow-y: auto;
    border-radius: 12px;
  }

  .connect-logo {
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
  }

  .connect-header h2 {
    font-size: 18px;
  }

  .connect-header p {
    font-size: 12px;
  }

  .input-wrapper input {
    font-size: 15px;
    padding: 10px 12px;
  }
}
