/* ============================================================
   Agent Monitor — 全局样式
   暗色主题，专业级 UI
   ============================================================ */

:root {
  --bg-base:    #0f1117;
  --bg-surface: #161822;
  --bg-card:    #1c1f2e;
  --bg-hover:   #252839;
  --bg-input:   #1c1f2e;
  --border:     #2a2d3e;
  --border-lt:  #353849;
  --text:       #e2e4ea;
  --text-muted: #8b8fa3;
  --text-dim:   #5c6078;
  --accent:     #6366f1;
  --accent-h:   #818cf8;
  --green:      #22c55e;
  --yellow:     #f59e0b;
  --red:        #ef4444;
  --blue:       #3b82f6;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 2px 8px rgba(0,0,0,0.3);
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans:  -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
}

a { color: var(--accent-h); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==================== 通用组件 ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-lt); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border); }
.btn-block { width: 100%; justify-content: center; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: 13px; }
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }

.error-text { color: var(--red); font-size: 13px; margin-top: 12px; text-align: center; }
.text-muted { color: var(--text-muted); }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}
.status-dot.active { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.idle   { background: var(--yellow); }
.status-dot.stuck  { background: var(--red); box-shadow: 0 0 6px var(--red); animation: pulse 1.5s infinite; }

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

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.status-badge.active { background: rgba(34,197,94,0.15); color: var(--green); }
.status-badge.idle   { background: rgba(245,158,11,0.15); color: var(--yellow); }
.status-badge.stuck  { background: rgba(239,68,68,0.15); color: var(--red); }
.status-badge.reconnecting { background: rgba(59,130,246,0.15); color: var(--blue); }

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.toggle-label input[type="checkbox"] { accent-color: var(--accent); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text-muted);
}
.empty-state.small { padding: 30px 16px; }

/* ==================== 登录页 ==================== */

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1d2e 0%, var(--bg-base) 70%);
}
.login-card {
  width: 360px;
  padding: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.login-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

/* ==================== 导航栏 ==================== */

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.navbar-left { display: flex; align-items: center; gap: 24px; }
.navbar-right { display: flex; align-items: center; gap: 12px; }
.navbar-brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.3px;
}
.navbar-brand:hover { text-decoration: none; color: var(--accent-h); }
.navbar-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }

.session-count {
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 8px;
  background: var(--bg-card);
  border-radius: 20px;
}

/* ==================== 面板通用 ==================== */

#app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  flex-shrink: 0;
}
.panel-header h2 { font-size: 18px; font-weight: 600; }

/* ==================== 仪表盘 ==================== */

.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
  padding: 0 20px 20px;
  overflow-y: auto;
  flex: 1;
}

.session-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
}
.session-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(99,102,241,0.1);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.card-meta {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-dim);
}

.card-preview {
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-muted);
  max-height: 140px;
  overflow: hidden;
  position: relative;
  white-space: pre-wrap;
  word-break: break-all;
}
.card-preview::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--bg-card));
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

/* ==================== 终端查看 ==================== */

.terminal-header {
  border-bottom: 1px solid var(--border);
}
.terminal-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.terminal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.back-btn { font-size: 13px; }

.terminal-container {
  flex: 1;
  padding: 4px;
  overflow: hidden;
  background: #000;
  position: relative;
}
.terminal-container .xterm { height: 100%; }

.terminal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  z-index: 10;
}
.overlay-content {
  text-align: center;
}
.overlay-content p {
  margin-bottom: 16px;
  font-size: 16px;
  color: var(--text-muted);
}

/* ==================== 会话回放 ==================== */

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

.replay-sidebar {
  width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.recordings-list { padding: 8px; }

.recording-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.recording-item:hover { background: var(--bg-hover); }
.recording-item.active { background: var(--bg-hover); border-left: 3px solid var(--accent); }
.recording-item-name {
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 4px;
}
.recording-item-meta {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 12px;
}

.replay-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}
.player-placeholder {
  color: var(--text-dim);
  font-size: 15px;
}

.recording-info {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 20px;
}

/* ==================== asciinema-player 样式覆盖 ==================== */

#asciinema-player {
  width: 100%;
  max-width: 100%;
}
#asciinema-player .ap-wrapper {
  max-width: 100%;
}

/* ==================== 响应式 ==================== */

@media (max-width: 768px) {
  .sessions-grid {
    grid-template-columns: 1fr;
  }
  .replay-sidebar {
    width: 200px;
  }
  .navbar-nav {
    display: none;
  }
}

/* ==================== 滚动条 ==================== */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-lt); }

/* ==================== 动画 ==================== */

.fade-in {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
