:root {
  --xl-brand: #132C52;
  --xl-brand-dark: #0C1E3A;
  --xl-brand-deep: #1A3A6B;
  --xl-brand-light: #EEF3F9;
  --xl-brand-soft: #DBEAFE;
  --xl-brand-border: #93C5FD;
  --bg-canvas: #F4F5F7;
  --bg-surface: #FFFFFF;
  --border-color: #E5E7EB;
  --border-strong: #CBD5E1;
  --text-main: #0F172A;
  --text-body: #242424;
  --text-muted: #605E5C;
  --danger: #C42B1C;
  --danger-bg: #FDE7E9;
  --success: #0F7B0F;
  --success-bg: #DFF6DD;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --shadow-sm: 0 1px 3px rgba(12, 30, 58, 0.06);
  --shadow-md: 0 12px 32px rgba(12, 30, 58, 0.18);
  --radius: 10px;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text-body);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

svg {
  display: block;
  flex-shrink: 0;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
  touch-action: manipulation;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-muted);
  transition: background 0.14s, color 0.14s;
}

.icon-btn.sm {
  width: 30px;
  height: 30px;
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover {
    background: var(--xl-brand-light);
    color: var(--xl-brand);
  }
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-canvas);
}

/* Topbar */
.topbar {
  height: 56px;
  background: var(--bg-canvas);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-center {
  flex: 1;
  max-width: 660px;
  min-width: 0;
}

.brand-box {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--xl-brand);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-icon.lg {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  margin: 0 auto 10px;
}

.search-wrap {
  display: flex;
  align-items: center;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0 6px 0 14px;
  height: 38px;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.search-wrap:focus-within {
  border-color: var(--xl-brand-border);
  box-shadow: 0 0 0 3px var(--xl-brand-soft);
}

.search-icon {
  color: var(--text-muted);
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
}

.search-go-btn {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--xl-brand);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 12px;
}

.pc-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94A3B8;
}

.pc-status-pill.active .status-dot {
  background: var(--success);
}

.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--xl-brand);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Popovers */
.dc-launcher-wrap, .user-menu-wrap {
  position: relative;
}

.popover-menu {
  position: absolute;
  top: 44px;
  left: 0;
  width: 280px;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 12px;
  z-index: 90;
}

.user-popover {
  left: auto;
  right: 0;
  width: 230px;
}

.popover-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

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

.launcher-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border-radius: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
}

.launcher-item.current {
  background: var(--xl-brand-light);
  color: var(--xl-brand);
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .launcher-item:hover {
    background: var(--xl-brand-light);
  }
}

.launcher-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--xl-brand);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.user-info-head {
  padding-bottom: 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.user-name {
  font-weight: 700;
  color: var(--text-main);
}

.user-email {
  font-size: 12px;
  margin-top: 2px;
  word-break: break-all;
}

.popover-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 600;
}

.popover-item.danger {
  color: var(--danger);
}

@media (hover: hover) and (pointer: fine) {
  .popover-item:hover {
    background: var(--danger-bg);
  }
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 0 14px 14px;
  gap: 12px;
  position: relative;
}

.sidebar {
  width: 244px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.btn-primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--xl-brand);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background 0.14s;
}

.btn-primary-cta.inline {
  width: auto;
  padding: 0 22px;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary-cta:hover {
    background: var(--xl-brand-deep);
  }
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.count-badge {
  background: #E2E8F0;
  color: var(--text-main);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
}

.profile-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}

.profile-card.active {
  background: #FFFFFF;
  border-color: var(--xl-brand-border);
  box-shadow: var(--shadow-sm);
}

@media (hover: hover) and (pointer: fine) {
  .profile-card:not(.active):hover {
    background: rgba(255, 255, 255, 0.7);
  }
}

.profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.profile-avatar .run-indicator {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  background: #94A3B8;
}

.profile-avatar .run-indicator.on {
  background: var(--success);
}

.profile-card-info {
  flex: 1;
  min-width: 0;
}

.profile-card-name {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.mini-tag {
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 10px;
}

.mini-tag.auto {
  background: var(--xl-brand-light);
  color: var(--xl-brand);
}

.mini-tag.manual {
  background: var(--warn-bg);
  color: var(--warn);
}

.sidebar-footer {
  padding-top: 6px;
  border-top: 1px solid var(--border-color);
}

.btn-danger-outline {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #FCA5A5;
  color: var(--danger);
  background: #FFFFFF;
  font-weight: 600;
  font-size: 13px;
}

@media (hover: hover) and (pointer: fine) {
  .btn-danger-outline:hover {
    background: var(--danger-bg);
  }
}

/* Main Stage */
.main-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.tab-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px 0;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
  min-height: 38px;
}

.tab-list {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-list::-webkit-scrollbar {
  display: none;
}

.browser-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 210px;
  min-width: 96px;
  height: 32px;
  padding: 0 8px 0 11px;
  border-radius: 9px 9px 0 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
}

.browser-tab.active {
  background: #FFFFFF;
  color: var(--text-main);
  font-weight: 600;
  border-color: var(--border-color);
}

.browser-tab-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-close-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .tab-close-btn:hover {
    background: #E2E8F0;
    color: var(--danger);
  }
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  background: #FFFFFF;
  flex-wrap: wrap;
}

.toolbar-group, .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-profile-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.profile-dot-lg {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--xl-brand);
  flex-shrink: 0;
}

.stage-profile-name {
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-profile-slug {
  font-size: 12px;
  color: var(--text-muted);
  background: #F1F5F9;
  padding: 2px 7px;
  border-radius: 6px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}

.mode-pill.auto {
  background: var(--xl-brand-light);
  color: var(--xl-brand);
  border-color: var(--xl-brand-border);
}

.mode-pill.manual {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #FCD34D;
}

.btn-action-sm {
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.btn-action-sm.start {
  background: var(--xl-brand);
  color: #FFFFFF;
}

.btn-action-sm.stop {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-action-sm.neutral {
  background: #F1F5F9;
  color: var(--text-main);
}

.quick-type-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
}

.quick-type-bar input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #FFFFFF;
  outline: none;
}

/* Viewport Stage */
.viewport-stage {
  flex: 1;
  min-height: 0;
  background: #0F172A;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  outline: none;
}

.live-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  display: block;
}

.live-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
}

.stopped-overlay {
  position: absolute;
  inset: 0;
  background: #F8FAFC;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.stopped-card {
  text-align: center;
  max-width: 360px;
}

.stopped-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--xl-brand-light);
  color: var(--xl-brand);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stopped-card h3 {
  font-size: 17px;
  color: var(--text-main);
  margin-bottom: 6px;
}

.stopped-card p {
  margin-bottom: 18px;
  line-height: 1.5;
}

/* Log Panel */
.log-panel {
  width: 290px;
  flex-shrink: 0;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.log-panel-head {
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: var(--text-main);
}

.log-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.log-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-item {
  padding: 8px 10px;
  border-radius: 9px;
  background: #F8FAFC;
  border: 1px solid var(--border-color);
  font-size: 12px;
}

.log-item.fail {
  border-color: #FCA5A5;
  background: var(--danger-bg);
}

.log-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.log-actor {
  font-weight: 700;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--xl-brand-light);
  color: var(--xl-brand);
}

.log-actor.user {
  background: #E2E8F0;
  color: var(--text-main);
}

.log-time {
  font-size: 11px;
  color: var(--text-muted);
}

.log-detail {
  color: var(--text-body);
  word-break: break-word;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 30, 58, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #FFFFFF;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.login-card {
  max-width: 390px;
}

.login-head {
  text-align: center;
  padding: 24px 20px 8px;
}

.login-head h3 {
  font-size: 18px;
  color: var(--text-main);
  margin-bottom: 4px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.modal-head h3 {
  font-size: 16px;
  color: var(--text-main);
}

.modal-body {
  padding: 16px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.form-row input, .form-row select {
  height: 38px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: #FFFFFF;
  outline: none;
}

.form-row input:focus, .form-row select:focus {
  border-color: var(--xl-brand);
  box-shadow: 0 0 0 3px var(--xl-brand-soft);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.color-swatch.selected {
  border-color: #0F172A;
  transform: scale(1.1);
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
}

.modal-foot-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn-primary {
  height: 38px;
  padding: 0 16px;
  border-radius: 9px;
  background: var(--xl-brand);
  color: #FFFFFF;
  font-weight: 600;
}

.btn-primary.full {
  width: 100%;
  height: 42px;
}

.btn-neutral {
  height: 38px;
  padding: 0 14px;
  border-radius: 9px;
  background: #F1F5F9;
  color: var(--text-main);
  font-weight: 600;
}

.error-box {
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #0F172A;
  color: #FFFFFF;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 300;
}

.mobile-only {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 30, 58, 0.35);
  z-index: 70;
}

@media (max-width: 860px) {
  .mobile-only {
    display: inline-flex;
  }
  .brand-name, .stage-profile-slug, .pc-status-pill {
    display: none;
  }
  .workspace {
    padding: 0 8px 8px;
  }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 270px;
    background: var(--bg-canvas);
    padding: 12px;
    z-index: 80;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .log-panel {
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: 290px;
    z-index: 80;
    border-radius: 14px 0 0 0;
  }
}

/* Anti-zoom on iOS touch devices */
@media (hover: none) and (pointer: coarse), (max-width: 860px) {
  input, select, textarea, .search-wrap input, .quick-type-bar input {
    font-size: 16px !important;
  }
}
