/* ─── Design Tokens (matching Opensteer Cloud) ─── */

:root {
  color-scheme: dark;
  --background: #000000;
  --foreground: #ffffff;
  --surface: #141414;
  --surface-elevated: #1e1e1e;
  --surface-raised: #282828;
  --muted: rgba(255, 255, 255, 0.05);
  --muted-foreground: #a0a0a0;
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-strong: rgba(255, 255, 255, 0.12);
  --accent: #ffffff;
  --accent-foreground: #000000;
  --destructive: #ef4444;
  --ring: rgba(255, 255, 255, 0.4);
  --top-bar-height: 44px;
}

/* ─── Reset ─── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ─── Animations ─── */

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ─── App Shell ─── */

.app-shell {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Top Bar ─── */

.top-bar {
  height: var(--top-bar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  position: relative;
}

.drawer-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-foreground);
  padding: 0;
  flex-shrink: 0;
  transition:
    background 150ms ease,
    color 150ms ease;
}

.drawer-toggle:hover {
  background: var(--muted);
  color: var(--foreground);
}

.drawer-toggle:active {
  background: var(--border-strong);
}

.session-count-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-foreground);
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  pointer-events: none;
}

/* ─── Brand ─── */

.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-icon {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  object-fit: contain;
  object-position: center;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
  letter-spacing: -0.01em;
}

.brand-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted-foreground);
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.top-bar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-strong);
  flex-shrink: 0;
}

/* ─── Active Session Indicator ─── */

.active-session-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-elevated);
  color: var(--foreground);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  max-width: 300px;
  transition:
    background 150ms ease,
    border-color 150ms ease;
}

.active-session-indicator:hover {
  background: var(--surface-raised);
  border-color: var(--border-strong);
}

.active-session-indicator:active {
  background: rgba(255, 255, 255, 0.08);
}

.active-session-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-foreground);
  opacity: 0.4;
  transition: all 200ms ease;
}

.active-session-dot.is-active {
  background: #28c840;
  opacity: 1;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

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

.active-session-chevron {
  flex-shrink: 0;
  color: var(--muted-foreground);
  opacity: 0.5;
  transition: transform 200ms ease;
}

.top-bar-spacer {
  flex: 1;
  min-width: 0;
}

/* ─── View Toggle ─── */

.local-view-toggle {
  flex-shrink: 0;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--muted-foreground);
  padding: 0 9px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    opacity 150ms ease;
}

.local-view-toggle:hover:not(:disabled) {
  background: var(--muted);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--foreground);
}

.local-view-toggle:disabled {
  cursor: default;
  opacity: 0.6;
}

/* ─── Session Drawer ─── */

.drawer-backdrop {
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
  z-index: 90;
}

.drawer-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.session-drawer {
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  bottom: 0;
  width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition:
    transform 280ms cubic-bezier(0, 0, 0.2, 1),
    box-shadow 280ms ease;
  z-index: 100;
  overflow: hidden;
}

.session-drawer.is-open {
  transform: translateX(0);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  letter-spacing: 0.02em;
}

.drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-foreground);
  padding: 0;
  transition:
    background 150ms ease,
    color 150ms ease;
}

.drawer-close:hover {
  background: var(--muted);
  color: var(--foreground);
}

.drawer-close:active {
  background: var(--border-strong);
}

.drawer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ─── Session List ─── */

.session-list {
  display: flex;
  flex-direction: column;
}

.session-item {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-left: 3px solid transparent;
  padding: 12px 16px 12px 13px;
  text-align: left;
  background: transparent;
  color: inherit;
  transition:
    background 150ms ease,
    border-color 150ms ease;
}

.session-item:hover {
  background: var(--muted);
}

.session-item[data-active="true"] {
  background: rgba(255, 255, 255, 0.03);
  border-left-color: var(--accent);
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.session-item[data-active="true"] .session-title {
  color: var(--accent);
}

.session-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #28c840;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.session-engine {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 500;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
  border-radius: 9999px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.session-info {
  font-size: 11px;
  color: var(--muted-foreground);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", monospace;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-path {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted-foreground);
  opacity: 0.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 16px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-align: center;
}

/* ─── Main Shell ─── */

.main-shell {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
}

.viewer-area {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

/* ─── Browser Frame ─── */

.browser-frame {
  --browser-stream-aspect: 1.6;
  flex: 0 1 auto;
  width: var(--browser-frame-width, 100%);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* ─── Browser Chrome ─── */

.browser-chrome {
  background: var(--surface-raised);
  flex-shrink: 0;
}

.chrome-top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 6px;
}

.window-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.wdot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.wdot-close {
  background: #ff5f57;
}

.wdot-min {
  background: #febc2e;
}

.wdot-max {
  background: #28c840;
}

/* ─── Chrome Navigation ─── */

.chrome-nav {
  display: flex;
  gap: 2px;
  align-items: center;
  flex-shrink: 0;
}

.chrome-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  padding: 0;
  transition: all 150ms;
}

.chrome-nav-btn:hover {
  background: var(--muted);
  color: var(--foreground);
}

.chrome-nav-btn:active {
  background: var(--border-strong);
}

/* ─── Chrome Tabs ─── */

.chrome-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.chrome-tabs::-webkit-scrollbar {
  display: none;
}

.chrome-tab-chip {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  max-width: 208px;
  border-radius: 4px;
  overflow: hidden;
  color: var(--muted-foreground);
  background: transparent;
  transition:
    background 150ms ease,
    color 150ms ease;
}

.chrome-tab-chip:hover {
  color: rgba(255, 255, 255, 0.8);
}

.chrome-tab-chip[data-active="true"] {
  background: var(--border-strong);
  color: var(--foreground);
}

.chrome-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  border-radius: 0;
  padding: 3px 6px 3px 10px;
  font-size: 11px;
  color: inherit;
  background: transparent;
  white-space: nowrap;
}

.chrome-tab:hover {
  color: inherit;
}

.chrome-tab[data-active="true"] {
  color: inherit;
}

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

.chrome-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  margin-right: 2px;
  padding: 0;
  transition: all 150ms;
}

.chrome-tab-close:hover {
  background: var(--border-strong);
  color: var(--foreground);
}

/* ─── Chrome Status ─── */

.chrome-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
  padding-right: 4px;
}

.chrome-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-foreground);
  flex-shrink: 0;
}

.chrome-status-dot.is-live {
  background: #28c840;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.chrome-status-dot.is-connecting {
  background: #facc15;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.chrome-status-dot.is-error {
  background: var(--destructive);
}

.chrome-status-dot.is-idle {
  background: var(--muted-foreground);
  opacity: 0.4;
}

.chrome-status-label {
  font-size: 10px;
  color: var(--muted-foreground);
  text-transform: capitalize;
  font-weight: 500;
}

.chrome-browser-action {
  flex-shrink: 0;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.34);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    opacity 150ms ease;
}

.chrome-browser-action:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.5);
  color: #ffffff;
}

.chrome-browser-action:disabled {
  cursor: default;
  opacity: 0.45;
}

/* ─── Chrome URL Bar ─── */

.chrome-url-row {
  padding: 0 12px 8px;
}

.chrome-url-bar {
  display: flex;
  align-items: center;
  height: 28px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  padding: 0 10px;
  gap: 8px;
  transition: border-color 150ms;
}

.chrome-url-bar:focus-within {
  border-color: var(--ring);
}

.chrome-url-icon {
  flex-shrink: 0;
  color: var(--muted-foreground);
  opacity: 0.6;
}

.chrome-url-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", monospace;
  outline: none;
  padding: 0;
}

.chrome-url-input::placeholder {
  color: var(--muted-foreground);
  opacity: 0.5;
}

/* ─── Browser Viewport ─── */

.browser-viewport {
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: var(--browser-stream-aspect);
  min-height: 0;
  display: flex;
}

.viewer-surface {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: var(--surface-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  outline: none;
}

.viewer-surface:focus {
  outline: none;
}

.viewer-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  animation: fade-in 400ms ease-out;
}

.viewer-empty-icon {
  color: var(--muted-foreground);
  opacity: 0.2;
}

.viewer-empty-label {
  font-size: 12px;
  color: var(--muted-foreground);
  text-align: center;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .session-drawer {
    width: 100%;
  }

  .viewer-area {
    padding: 8px;
  }
}

@media (max-width: 640px) {
  .brand-name {
    display: none;
  }

  .top-bar-divider {
    display: none;
  }

  .active-session-indicator {
    max-width: 180px;
  }
}
