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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
}

.screen { display: none; }
.screen.active { display: flex; }

/* --- Login --- */
.login-container {
  margin: auto;
  max-width: 360px;
  width: 100%;
  padding: 40px 24px;
  text-align: center;
}

#screen-login {
  height: 100vh;
  align-items: center;
  justify-content: center;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  color: #818cf8;
}

.login-container h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #cbd5e1;
}

.login-container input {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #e2e8f0;
  outline: none;
  margin-bottom: 12px;
}

.login-container input:focus {
  border-color: #818cf8;
}

.error-text {
  color: #f87171;
  font-size: 13px;
  margin-top: 8px;
}

.success-text {
  color: #4ade80;
  font-size: 13px;
  margin-top: 4px;
  min-height: 18px;
}

/* --- Buttons --- */
.btn-primary {
  width: 100%;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #4F46E5;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-primary:hover { background: #4338CA; }

.btn-primary-sm {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #4F46E5;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.btn-primary-sm:hover { background: #4338CA; }

.btn-danger-sm {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #dc2626;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.btn-danger-sm:hover { background: #b91c1c; }

.btn-ghost {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8;
  background: none;
  border: 1px solid #334155;
  border-radius: 6px;
  cursor: pointer;
}

.btn-ghost:hover { background: #1e293b; }

/* --- Dashboard Layout --- */
#screen-dashboard {
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: #818cf8;
}

.header-right {
  display: flex;
  gap: 8px;
}

.dashboard-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Sidebar --- */
#sessions-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #1e293b;
  border-right: 1px solid #334155;
  padding: 16px;
  overflow-y: auto;
}

#sessions-sidebar h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 12px;
}

.muted {
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.session-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.session-card:hover {
  border-color: #4F46E5;
}

.session-card.selected {
  border-color: #818cf8;
  background: #1a1f3a;
}

.session-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.green { background: #22c55e; }
.status-dot.yellow { background: #eab308; }
.status-dot.blue { background: #3b82f6; }
.status-dot.gray { background: #64748b; }

.session-card-status {
  font-size: 12px;
  font-weight: 600;
}

.session-card-time {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

.session-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* --- Viewer Area --- */
#viewer-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.viewer-state { display: none; flex: 1; min-height: 0; }
.viewer-state.active { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

#viewer-empty {
  align-items: center;
  justify-content: center;
  padding: 40px;
}

#viewer-waiting {
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 32px;
}

.link-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 20px;
  max-width: 500px;
  width: 100%;
  text-align: center;
}

.link-box p {
  font-size: 14px;
  color: #94a3b8;
  margin-bottom: 12px;
}

.link-copy-row {
  display: flex;
  gap: 8px;
}

.link-copy-row input {
  flex: 1;
  padding: 10px 12px;
  font-size: 13px;
  font-family: monospace;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #e2e8f0;
  outline: none;
}

.waiting-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #94a3b8;
  font-size: 14px;
}

.pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #818cf8;
  animation: pulse-anim 1.5s ease-in-out infinite;
}

@keyframes pulse-anim {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* --- Cobrowse Viewport --- */
#viewer-active {
  flex: 1;
  min-height: 0;
}

.viewer-split {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.cobrowse-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.cobrowse-viewport {
  flex: 1;
  background: #1a1a2e;
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.cobrowse-scale-wrapper {
  position: relative;
  transform-origin: top center;
  background: #fff;
  box-shadow: 0 0 20px rgba(0,0,0,0.4);
}

.cobrowse-scale-wrapper iframe {
  border: none;
  display: block;
  background: #fff;
  overflow: hidden;
}

.click-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.click-dot {
  position: absolute;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.5);
  border: 2px solid #ef4444;
  animation: click-fade 1s ease-out forwards;
  pointer-events: none;
}

@keyframes click-fade {
  0% { transform: scale(0.5); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.6; }
  100% { transform: scale(2); opacity: 0; }
}

.cobrowse-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 6px;
  font-size: 13px;
  color: #94a3b8;
  z-index: 20;
}

.cobrowse-info-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
  font-size: 12px;
}

.agent-url {
  flex: 1;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: monospace;
}

.agent-viewport {
  color: #475569;
  flex-shrink: 0;
}

/* --- Devtools Side Panel (resizable) --- */
.devtools-panel {
  width: 380px;
  min-width: 200px;
  max-width: 80vw;
  flex-shrink: 0;
  background: #0f172a;
  border-left: 1px solid #334155;
  display: flex;
  flex-direction: column;
  position: relative;
}

.devtools-resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 10;
}

.devtools-resize-handle:hover,
.devtools-resize-handle.active {
  background: #818cf8;
  opacity: 0.5;
}

.devtools-panel.collapsed {
  width: 36px;
}

.devtools-panel.collapsed .devtools-body {
  display: none;
}

.devtools-header {
  flex-shrink: 0;
  border-bottom: 1px solid #334155;
}

.btn-toggle-devtools {
  width: 100%;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  background: #1e293b;
  border: none;
  cursor: pointer;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-toggle-devtools:hover { color: #e2e8f0; }

.devtools-panel.collapsed .btn-toggle-devtools {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 10px 8px;
  text-align: center;
  height: 100%;
}

.devtools-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Events Panel --- */
.event-entry {
  padding: 3px 12px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  gap: 8px;
  line-height: 1.4;
  color: #94a3b8;
}

.event-time {
  color: #475569;
  flex-shrink: 0;
  width: 70px;
}

.event-kind {
  flex-shrink: 0;
  width: 50px;
  color: #818cf8;
  font-weight: 600;
}

.event-detail {
  flex: 1;
  color: #94a3b8;
}

/* --- Session Controls Bar --- */
.session-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #1e293b;
  border-top: 1px solid #334155;
  flex-shrink: 0;
}

#session-status-text {
  font-size: 13px;
  color: #94a3b8;
}

/* --- Dev Tools Tabs & Content --- */
.devtools-tabs {
  display: flex;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.tab-btn {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: #818cf8;
  border-bottom-color: #818cf8;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.devtools-toolbar {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.filter-btn {
  padding: 3px 10px;
  font-size: 11px;
  color: #94a3b8;
  background: none;
  border: 1px solid #334155;
  border-radius: 4px;
  cursor: pointer;
}

.filter-btn.active {
  background: #334155;
  color: #e2e8f0;
}

/* Console entries */
.entries-list {
  flex: 1;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  padding: 4px 0;
}

.console-entry {
  padding: 3px 12px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  gap: 8px;
  line-height: 1.4;
}

.console-entry.error {
  background: rgba(239, 68, 68, 0.08);
  color: #f87171;
}

.console-entry.warn {
  background: rgba(234, 179, 8, 0.08);
  color: #fbbf24;
}

.console-entry.log,
.console-entry.info,
.console-entry.debug {
  color: #94a3b8;
}

.console-time {
  color: #475569;
  flex-shrink: 0;
  width: 70px;
}

.console-level {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.console-msg {
  flex: 1;
  word-break: break-all;
  white-space: pre-wrap;
}

.console-stack {
  color: #64748b;
  font-size: 11px;
  padding: 2px 0 2px 92px;
  cursor: pointer;
  white-space: pre-wrap;
}

/* Network table — wrapped in scrollable container */
#tab-network {
  overflow: auto;
}

#network-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
}

#network-table thead th {
  text-align: left;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  position: sticky;
  top: 0;
}

#network-table tbody tr {
  border-bottom: 1px solid #1e293b;
}

#network-table tbody td {
  padding: 4px 10px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.network-row:hover td {
  background: #1e293b;
}

.status-2xx { color: #4ade80; }
.status-4xx { color: #f87171; }
.status-5xx { color: #f87171; font-weight: 600; }
.status-err { color: #f87171; font-style: italic; }

/* Network detail panel (expanded row) */
.network-detail-row td {
  padding: 0 !important;
  background: #0c1222;
  white-space: normal !important;
  max-width: none !important;
  overflow: visible !important;
}

.network-detail {
  padding: 8px 12px;
  font-size: 11px;
  color: #94a3b8;
  border-left: 3px solid #818cf8;
}

.network-detail-section {
  margin-bottom: 6px;
}

.network-detail-url {
  word-break: break-all;
  color: #e2e8f0;
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.network-detail-body {
  margin-top: 8px;
}

.btn-load-body {
  padding: 4px 10px;
  font-size: 11px;
  color: #e2e8f0;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 4px;
  cursor: pointer;
}

.btn-load-body:hover { background: #475569; }
.btn-load-body:disabled { opacity: 0.5; cursor: default; }

.network-body-pre {
  background: #1e293b;
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
  font-size: 11px;
  color: #e2e8f0;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

details summary {
  cursor: pointer;
  color: #818cf8;
  margin: 4px 0;
  font-size: 11px;
}

details summary:hover { color: #a5b4fc; }
