:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #252836;
  --bg-hover: #2d3148;
  --border: #2d3148;
  --text-primary: #e4e6f0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* Auth */
.auth-container {
  margin: auto;
  width: 100%;
  max-width: 380px;
  padding: 40px;
  background: var(--bg-secondary);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-logo { text-align: center; margin-bottom: 16px; }
.auth-container h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }

input, select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus { border-color: var(--accent); }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

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

.hidden { display: none !important; }

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: 60px;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h2 { font-size: 18px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Layout */
.layout {
  display: flex;
  height: calc(100vh - 60px);
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }

.search-input {
  margin-bottom: 8px;
}

.filter-select {
  width: 100%;
}

.stats-bar {
  display: flex;
  padding: 12px 16px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.stat { text-align: center; flex: 1; }
.stat-num { display: block; font-size: 20px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-tertiary); border-color: var(--accent); }

.session-item-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-item-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, monospace;
}

.session-item-date {
  font-size: 11px;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-completed { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-archived { background: rgba(107, 114, 128, 0.15); color: var(--text-muted); }

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 16px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.detail-header h3 { font-size: 20px; margin-bottom: 8px; }

.detail-meta {
  display: flex;
  gap: 12px;
  align-items: center;
}

.meta-item {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.detail-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.detail-tab:hover { color: var(--text-primary); }

.detail-content {
  min-height: 400px;
}

/* Messages */
.message {
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
}

.message-user {
  background: var(--bg-tertiary);
  border-left-color: var(--accent);
}

.message-assistant {
  background: var(--bg-secondary);
  border-left-color: var(--success);
}

.message-system {
  background: var(--bg-secondary);
  border-left-color: var(--warning);
  font-style: italic;
  color: var(--text-secondary);
}

.message-tool {
  background: var(--bg-tertiary);
  border-left-color: var(--info);
}

.message-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.message-content {
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Tool call */
.tool-call {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tool-call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.tool-call-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  font-family: 'SF Mono', Monaco, monospace;
}

.tool-call-status {
  font-size: 12px;
}

.tool-call-body {
  font-size: 13px;
  color: var(--text-secondary);
}

.tool-call-section {
  margin-bottom: 8px;
}

.tool-call-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.tool-call-data {
  background: var(--bg-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

/* Checkpoint / Task / Event items */
.list-item {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.list-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.list-item-title {
  font-weight: 600;
  font-size: 14px;
}

.list-item-body {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

/* Raw JSON */
.raw-json {
  background: var(--bg-primary);
  padding: 16px;
  border-radius: var(--radius);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow: auto;
  max-height: calc(100vh - 280px);
  border: 1px solid var(--border);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: auto; }
  .layout { flex-direction: column; }
  .content { padding: 16px; }
}
