body {
  margin: 0;
}

#web-app {
  height: 100vh;
  background: var(--sol-bg-base);
  color: var(--sol-text-primary);
  font-family: var(--sol-font);
}

.web-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
  grid-template-areas:
    'topbar topbar'
    'sidebar main';
  background: var(--sol-bg-base);
}

.web-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sol-space-4);
  padding: 0 var(--sol-space-5);
  border-bottom: 1px solid var(--sol-border-subtle);
  background: color-mix(in srgb, var(--sol-bg-surface) 92%, transparent);
  backdrop-filter: blur(16px);
}

.web-brand {
  display: flex;
  align-items: center;
  gap: var(--sol-space-3);
  min-width: 0;
}

.web-brand-mark {
  font-size: 1.4rem;
}

.web-brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.web-brand-title {
  font-size: var(--sol-text-lg);
  font-weight: var(--sol-weight-semibold);
}

.web-brand-subtitle {
  color: var(--sol-text-muted);
  font-size: var(--sol-text-sm);
}

.web-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sol-space-3);
}

.web-search-button,
.web-sidebar-toggle,
.web-user-chip {
  border: 1px solid var(--sol-border-subtle);
  background: var(--sol-bg-surface);
  color: var(--sol-text-primary);
  border-radius: var(--sol-radius-lg);
  min-height: 40px;
}

.web-search-button,
.web-sidebar-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sol-space-2);
  padding: 0 var(--sol-space-3);
  cursor: pointer;
}

.web-search-button kbd {
  font: inherit;
  font-size: var(--sol-text-xs);
  color: var(--sol-text-muted);
  background: var(--sol-bg-hover);
  border-radius: var(--sol-radius-sm);
  padding: 2px 6px;
}

.web-user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sol-space-2);
  padding: 0 var(--sol-space-3);
}

.web-sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--sol-border-subtle);
  background: linear-gradient(180deg, color-mix(in srgb, var(--sol-bg-surface) 94%, transparent), color-mix(in srgb, var(--sol-bg-base) 92%, transparent));
  overflow: auto;
  padding: var(--sol-space-4) var(--sol-space-3);
  transition: width var(--sol-transition-fast), transform var(--sol-transition-fast), opacity var(--sol-transition-fast);
  transform: translateZ(0);
}

.web-shell.sidebar-expanded {
  grid-template-columns: 260px minmax(0, 1fr);
}

.web-sidebar-group {
  display: grid;
  gap: var(--sol-space-2);
  margin-bottom: var(--sol-space-4);
}

.web-sidebar-group-header {
  display: flex;
  align-items: center;
  gap: var(--sol-space-2);
  padding: var(--sol-space-2) var(--sol-space-2);
  color: var(--sol-text-muted);
  font-size: var(--sol-text-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.web-sidebar-group-items {
  display: grid;
  gap: var(--sol-space-2);
}

.web-sidebar-group.collapsed .web-sidebar-group-items {
  display: none;
}

.web-app-button {
  width: 100%;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sol-space-3);
  padding: var(--sol-space-3);
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--sol-radius-xl);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform var(--sol-transition-fast), opacity var(--sol-transition-fast), background var(--sol-transition-fast), border-color var(--sol-transition-fast);
  transform: translateZ(0);
}

.web-app-button:hover {
  background: var(--sol-bg-hover);
  border-color: color-mix(in srgb, var(--sol-border-subtle) 70%, transparent);
}

.web-app-button.active {
  background: var(--sol-accent-surface);
  color: var(--sol-accent-text);
  border-color: color-mix(in srgb, var(--sol-accent) 50%, transparent);
}

.web-app-button.offline {
  opacity: 0.55;
}

.web-app-button.offline .app-name {
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--sol-text-muted) 60%, transparent);
  text-decoration-thickness: 1.5px;
}

.web-app-button .app-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--sol-weight-medium);
}

.web-app-button .app-status {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--sol-text-muted);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--sol-bg-surface) 90%, transparent);
}

.web-app-button .app-status.online {
  background: var(--sol-success);
}

.web-app-button .app-status.offline {
  background: var(--sol-danger);
}

.web-app-button .app-status.unknown {
  background: var(--sol-warning);
}

.web-main {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  background: radial-gradient(circle at top, color-mix(in srgb, var(--sol-accent) 8%, transparent), transparent 28%), var(--sol-bg-base);
}

.web-frame-stack {
  position: relative;
  min-height: 0;
  min-width: 0;
}

.web-frame,
.web-native-stage,
.web-empty-state,
.quick-switch-overlay {
  transform: translateZ(0);
}

.web-frame,
.web-native-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--sol-bg-base);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--sol-transition-fast), transform var(--sol-transition-fast);
}

.web-frame {
  border: 0;
}

.web-frame.active,
.web-native-stage.active {
  opacity: 1;
  pointer-events: auto;
}

.web-native-stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.web-native-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sol-space-3);
  padding: var(--sol-space-2) var(--sol-space-4);
  border-bottom: 1px solid var(--sol-border-subtle);
  background: color-mix(in srgb, var(--sol-bg-surface) 88%, transparent);
  backdrop-filter: blur(12px);
}

.web-native-toolbar-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.web-native-toolbar-title {
  font-size: var(--sol-text-sm);
  font-weight: var(--sol-weight-semibold);
}

.web-native-toolbar-hint {
  color: var(--sol-text-muted);
  font-size: var(--sol-text-xs);
}

.web-native-toolbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sol-space-2);
}

.web-native-capture-button {
  min-height: 34px;
  padding: 0 var(--sol-space-3);
  border-radius: var(--sol-radius-md);
  border: 1px solid color-mix(in srgb, var(--sol-border-subtle) 78%, transparent);
  background: var(--sol-bg-elevated);
  color: var(--sol-text-primary);
  font: inherit;
  cursor: pointer;
  transition: background var(--sol-transition-fast), border-color var(--sol-transition-fast), color var(--sol-transition-fast);
}

.web-native-capture-button:hover {
  background: var(--sol-bg-hover);
  border-color: color-mix(in srgb, var(--sol-accent) 45%, transparent);
}

.web-native-capture-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sol-accent) 22%, transparent);
}

.web-native-stage-browser {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--sol-bg-surface) 96%, transparent), color-mix(in srgb, var(--sol-bg-elevated) 92%, transparent)),
    var(--sol-bg-base);
}

.web-browser-chrome {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sol-space-3);
  padding: var(--sol-space-3) var(--sol-space-4);
  border-bottom: 1px solid var(--sol-border-subtle);
  background: color-mix(in srgb, var(--sol-bg-surface) 92%, transparent);
  backdrop-filter: blur(14px);
}

.web-browser-loading-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--sol-transition-base);
}

.web-browser-loading-bar.active {
  opacity: 1;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--sol-accent) 38%,
    var(--sol-accent) 62%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: web-browser-loading-slide 1.2s ease-in-out infinite;
}

.web-browser-loading-bar.complete {
  opacity: 1;
  background: var(--sol-success);
  animation: none;
}

@keyframes web-browser-loading-slide {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.web-browser-nav {
  display: flex;
  align-items: center;
  gap: var(--sol-space-2);
}

.web-browser-nav-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--sol-radius-md);
  border: 1px solid transparent;
  background: var(--sol-bg-elevated);
  color: var(--sol-text-secondary);
  cursor: pointer;
  transition: background var(--sol-transition-fast), color var(--sol-transition-fast), border-color var(--sol-transition-fast);
}

.web-browser-nav-btn:hover {
  background: var(--sol-bg-hover);
  color: var(--sol-text-primary);
  border-color: color-mix(in srgb, var(--sol-border-subtle) 72%, transparent);
}

.web-browser-url-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--sol-space-2);
  height: 40px;
  padding: 0 var(--sol-space-3);
  border-radius: var(--sol-radius-xl);
  border: 1px solid color-mix(in srgb, var(--sol-border-subtle) 82%, transparent);
  background: color-mix(in srgb, var(--sol-bg-elevated) 90%, transparent);
}

.web-browser-lock {
  color: var(--sol-text-muted);
  font-size: 0.95rem;
}

.web-browser-address {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--sol-text-primary);
  font: inherit;
}

.web-browser-status {
  min-width: 84px;
  display: flex;
  justify-content: flex-end;
}

.web-browser-status-text {
  color: var(--sol-text-muted);
  font-size: var(--sol-text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web-browser-tab-bar {
  position: relative;
  z-index: 2;
  background: var(--sol-bg-elevated);
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--sol-space-1);
  padding: 0 var(--sol-space-3);
  border-bottom: 1px solid var(--sol-border-subtle);
}

#web-tab-list {
  display: flex;
  gap: var(--sol-space-1);
  overflow: hidden;
  flex: 1;
  min-width: 0;
  position: relative;
}

#web-tab-list::-webkit-scrollbar {
  display: none;
}

#web-tab-overflow-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--sol-radius-sm);
  background: transparent;
  color: var(--sol-text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  padding: 0;
  margin-left: var(--sol-space-1);
  flex-shrink: 0;
  line-height: 1;
  transition: background var(--sol-transition-fast), color var(--sol-transition-fast);
}

#web-tab-overflow-btn:hover {
  background: var(--sol-bg-hover);
  color: var(--sol-text-secondary);
}

#web-tab-overflow-btn.hidden {
  display: none;
}

#web-tab-overflow-menu {
  position: absolute;
  right: var(--sol-space-2);
  top: 40px;
  background: var(--sol-bg-elevated);
  border: 1px solid var(--sol-border-subtle);
  border-radius: var(--sol-radius-md);
  z-index: var(--sol-z-popout);
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--sol-shadow-lg);
}

#web-tab-overflow-menu.hidden {
  display: none;
}

.tab-overflow-item {
  display: flex;
  align-items: center;
  gap: var(--sol-space-2);
  padding: var(--sol-space-2) var(--sol-space-3);
  cursor: pointer;
  color: var(--sol-text-secondary);
  font-size: var(--sol-text-sm);
  border-bottom: 1px solid var(--sol-border-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-overflow-item:last-child {
  border-bottom: none;
}

.tab-overflow-item:hover {
  background: var(--sol-bg-hover);
  color: var(--sol-text-primary);
}

.tab-overflow-item.active {
  color: var(--sol-accent-text);
}

.tab-overflow-item .tab-overflow-close {
  margin-left: auto;
  color: var(--sol-text-muted);
  font-size: 14px;
  padding: 0 4px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 4px;
}

.tab-overflow-item .tab-overflow-close:hover {
  background: var(--sol-danger-surface);
  color: var(--sol-danger);
}

.tab-item {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 var(--sol-space-3);
  gap: var(--sol-space-2);
  border-radius: var(--sol-radius-sm);
  font-size: var(--sol-text-xs);
  font-weight: var(--sol-weight-medium);
  cursor: pointer;
  white-space: nowrap;
  max-width: 180px;
  min-width: 64px;
  flex-shrink: 1;
  overflow: hidden;
  color: var(--sol-text-secondary);
  background: transparent;
  border: 1px solid transparent;
  transition: background var(--sol-transition-fast), color var(--sol-transition-fast);
}

.tab-item:hover {
  background: var(--sol-bg-hover);
  color: var(--sol-text-primary);
}

.tab-item.active {
  background: var(--sol-bg-active);
  color: var(--sol-text-primary);
}

.tab-item.dragging {
  opacity: 0.3;
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.tab-close {
  font-size: 10px;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--sol-transition-fast);
  flex-shrink: 0;
  padding: 2px;
  border-radius: 3px;
  color: var(--sol-text-muted);
}

.tab-item:hover .tab-close {
  opacity: 0.9;
}

.tab-close:hover {
  opacity: 1 !important;
  background: var(--sol-danger-surface);
  color: var(--sol-danger);
}

.tab-item.loading .tab-favicon,
.tab-item.loading .tab-default-icon {
  display: none;
}

.tab-item.loading .tab-label::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--sol-text-muted);
  border-top-color: var(--sol-accent);
  border-radius: 50%;
  animation: tab-spin 0.8s linear infinite;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

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

.tab-drop-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--sol-accent);
  border-radius: 2px;
  pointer-events: none;
  z-index: var(--sol-z-chrome);
  box-shadow: 0 0 6px color-mix(in srgb, var(--sol-accent) 70%, transparent);
}

.tab-favicon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 2px;
  vertical-align: middle;
}

.tab-default-icon {
  font-size: 12px;
  flex-shrink: 0;
}

.tab-new {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--sol-radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--sol-text-muted);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--sol-transition-fast), color var(--sol-transition-fast);
}

.tab-new:hover {
  background: var(--sol-bg-hover);
  color: var(--sol-text-secondary);
}

.tab-preview {
  position: fixed;
  z-index: var(--sol-z-settings);
  background: var(--sol-bg-base);
  border: 1px solid var(--sol-border-subtle);
  border-radius: var(--sol-radius-md);
  padding: 4px;
  box-shadow: var(--sol-shadow-lg);
  pointer-events: none;
  transition: opacity var(--sol-transition-fast);
}

.tab-preview.hidden {
  opacity: 0;
  pointer-events: none;
}

.tab-preview img {
  display: block;
  width: 280px;
  height: auto;
  border-radius: var(--sol-radius-sm);
}

.web-native-stream-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.web-native-canvas {
  position: absolute;
  cursor: default;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* Virtual cursor overlay for pointer-lock (capture cursor) mode */
.portal-virtual-cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: 10;
  transform: translate(-2px, -2px);
}

/* Default arrow cursor shape via CSS borders */
.portal-virtual-cursor::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 6px solid white;
  border-right: 6px solid transparent;
  border-bottom: 10px solid transparent;
  border-top: 10px solid white;
  filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.6));
}

.portal-virtual-cursor::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 0;
  height: 0;
  border-left: 5px solid black;
  border-right: 5px solid transparent;
  border-bottom: 8px solid transparent;
  border-top: 8px solid black;
}

.web-empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sol-space-8);
}

.web-empty-card {
  width: min(520px, 100%);
  background: color-mix(in srgb, var(--sol-bg-surface) 94%, transparent);
  border: 1px solid var(--sol-border-subtle);
  border-radius: var(--sol-radius-xl);
  padding: var(--sol-space-8);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.web-empty-card h1 {
  margin: 0 0 var(--sol-space-3);
  font-size: 1.5rem;
}

.web-empty-card p {
  margin: 0;
  color: var(--sol-text-muted);
}

.quick-switch-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--sol-z-modal);
  display: grid;
  place-items: start center;
  padding: max(12vh, var(--sol-space-8)) var(--sol-space-4) var(--sol-space-4);
  background: rgba(4, 6, 14, 0.72);
  backdrop-filter: blur(16px);
}

.quick-switch-modal {
  width: min(720px, 100%);
  display: grid;
  gap: var(--sol-space-3);
  padding: var(--sol-space-4);
  border-radius: var(--sol-radius-xl);
  border: 1px solid color-mix(in srgb, var(--sol-border-subtle) 78%, transparent);
  background: color-mix(in srgb, var(--sol-bg-surface) 96%, transparent);
  box-shadow: var(--sol-shadow-lg);
}

.quick-switch-input {
  width: 100%;
  height: 48px;
  border-radius: var(--sol-radius-lg);
  border: 1px solid color-mix(in srgb, var(--sol-border-subtle) 78%, transparent);
  background: var(--sol-bg-elevated);
  color: var(--sol-text-primary);
  padding: 0 var(--sol-space-4);
  font: inherit;
  outline: none;
}

.quick-switch-input:focus {
  border-color: color-mix(in srgb, var(--sol-accent) 62%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sol-accent) 18%, transparent);
}

.quick-switch-list {
  display: grid;
  gap: var(--sol-space-2);
  max-height: min(60vh, 560px);
  overflow: auto;
}

.web-hidden {
  display: none !important;
}

/* Collapsed sidebar: icon-only rail */
.web-shell:not(.sidebar-expanded) .web-sidebar {
  padding: var(--sol-space-4) var(--sol-space-1);
  overflow-x: hidden;
}

.web-shell:not(.sidebar-expanded) .web-sidebar-group-header {
  display: none;
}

.web-shell:not(.sidebar-expanded) .web-app-button {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: var(--sol-space-2);
  gap: 2px;
}

.web-shell:not(.sidebar-expanded) .web-app-button .app-name {
  font-size: var(--sol-text-xs);
  text-align: center;
}

.web-shell:not(.sidebar-expanded) .web-app-button .app-status {
  display: none;
}

/* ── Mobile: bottom tab bar ── */
@media (max-width: 767px) {
  .web-native-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .web-native-toolbar-actions {
    justify-content: stretch;
  }

  .web-native-capture-button {
    width: 100%;
  }

  .web-shell,
  .web-shell.sidebar-expanded {
    grid-template-columns: 1fr;
    grid-template-rows: 56px minmax(0, 1fr) auto;
    grid-template-areas:
      'topbar'
      'main'
      'sidebar';
  }

  .web-sidebar {
    border-right: 0;
    border-top: 1px solid var(--sol-border-subtle);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(64px, 1fr);
    align-items: stretch;
    padding: var(--sol-space-2);
    padding-bottom: calc(var(--sol-space-2) + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
    overflow-y: hidden;
  }

  .web-sidebar-group {
    display: contents;
  }

  .web-sidebar-group-header {
    display: none;
  }

  .web-sidebar-group-items {
    display: contents;
  }

  .web-app-button {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    padding: var(--sol-space-2);
    min-height: 56px;
  }

  .web-app-button .app-name {
    font-size: var(--sol-text-xs);
  }

  .web-app-button .app-status {
    display: none;
  }

  .web-topbar {
    padding: 0 var(--sol-space-3);
  }

  .web-sidebar-toggle {
    display: none;
  }

  .web-brand-subtitle,
  .web-search-button kbd,
  .web-browser-status {
    display: none;
  }

  .web-browser-chrome {
    grid-template-columns: 1fr;
  }

  .web-browser-nav {
    justify-content: center;
    flex-wrap: wrap;
  }
}
