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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --surface3: #252525;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-dim: #888;
  --text-muted: #555;
  --accent: #8b5cf6;
  --accent-dim: #6d28d9;
  --green: #22c55e;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --red: #ef4444;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* Login */
.login-box {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100dvh; padding: 2rem; gap: 0.75rem;
}
.login-box h1 { font-size: 4rem; }
.login-box h2 { font-size: 1.5rem; font-weight: 600; color: var(--text); }
.login-box .subtitle { color: var(--text-dim); font-size: 0.875rem; }
.login-box input {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.875rem 1.25rem; color: var(--text); font-size: 1rem;
  width: 100%; max-width: 300px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 0.875rem 2rem; font-size: 1rem; font-weight: 600;
  cursor: pointer; width: 100%; max-width: 300px;
}
.login-box button:active { opacity: 0.8; }
.error { color: var(--red); font-size: 0.875rem; }

/* Header */
header {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(var(--safe-top) + 1rem) 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.5rem; font-weight: 700; }

/* Tabs */
#tabs {
  display: flex; gap: 0; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: calc(var(--safe-top) + 3.5rem); z-index: 9;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 0.75rem 1rem; color: var(--text-dim); font-size: 0.8125rem;
  cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Content */
#content { padding: 1rem 1rem calc(var(--safe-bottom) + 2rem); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem;
  cursor: pointer; transition: all 0.15s;
}
.card:active { transform: scale(0.98); background: var(--surface2); }
.card-title { font-weight: 600; font-size: 0.9375rem; margin-bottom: 0.25rem; }
.card-subtitle { color: var(--text-dim); font-size: 0.8125rem; }
.card-meta { color: var(--text-muted); font-size: 0.75rem; margin-top: 0.5rem; }

/* Stats grid */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }

/* Activity feed */
.activity-feed { margin-top: 1rem; }
.activity-item {
  padding: 0.625rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.8125rem; color: var(--text-dim); line-height: 1.5;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.activity-item:last-child { border-bottom: none; }

/* Section header */
.section-header {
  font-size: 0.875rem; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 1.5rem 0 0.75rem; padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-content {
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 700px; max-height: 90dvh; overflow-y: auto;
  padding: 0; position: relative; animation: slideUp 0.25s ease-out;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h2 { font-size: 1.125rem; font-weight: 700; }
.modal-close {
  background: var(--surface2); border: none; color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 50%; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#modal-body {
  padding: 1.25rem 1.25rem calc(var(--safe-bottom) + 1.5rem);
  line-height: 1.7; font-size: 0.9375rem;
}
#modal-body h1, #modal-body h2, #modal-body h3 { font-weight: 700; margin: 1.25rem 0 0.5rem; }
#modal-body h1 { font-size: 1.375rem; }
#modal-body h2 { font-size: 1.125rem; color: var(--accent); }
#modal-body h3 { font-size: 1rem; }
#modal-body p { margin-bottom: 0.75rem; }
#modal-body ul, #modal-body ol { padding-left: 1.25rem; margin-bottom: 0.75rem; }
#modal-body li { margin-bottom: 0.375rem; }
#modal-body code {
  background: var(--surface2); padding: 0.125rem 0.375rem;
  border-radius: 4px; font-size: 0.875rem;
}
#modal-body pre {
  background: var(--surface2); padding: 1rem; border-radius: 8px;
  overflow-x: auto; margin-bottom: 1rem;
}
#modal-body strong { color: var(--amber); }
#modal-body a { color: var(--blue); }

/* Log viewer */
.log-line {
  font-family: 'SF Mono', 'Menlo', monospace; font-size: 0.8125rem;
  padding: 0.375rem 0; border-bottom: 1px solid var(--border);
  line-height: 1.5; color: var(--text-dim);
}
.log-line .time { color: var(--text-muted); }
.log-line .channel { color: var(--blue); }
.log-line .name { color: var(--accent); font-weight: 500; }

/* Status indicator */
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); margin-right: 0.5rem;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Messages */
.msg-stats {
  display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.msg-type-badge {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 20px;
  padding: 0.375rem 0.75rem; font-size: 0.75rem; color: var(--text-dim);
}
.msg-type-badge.voice_transcription { border-color: var(--amber); color: var(--amber); }
.msg-type-badge.thinking { border-color: var(--accent); color: var(--accent); }
.msg-type-badge.text { border-color: var(--blue); color: var(--blue); }

.msg-filters {
  display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.msg-input, .msg-select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.75rem; color: var(--text); font-size: 0.8125rem;
  outline: none; flex: 1; min-width: 0;
}
.msg-input:focus, .msg-select:focus { border-color: var(--accent); }
.msg-select { flex: 0 0 auto; min-width: 120px; }
.msg-select option { background: var(--surface); }

.msg {
  padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  border-radius: 12px; max-width: 92%;
  line-height: 1.5; font-size: 0.875rem;
  word-break: break-word;
}
.msg-received {
  background: var(--surface); border: 1px solid var(--border);
  margin-right: auto; border-bottom-left-radius: 4px;
}
.msg-sent {
  background: var(--accent-dim); border: 1px solid rgba(139, 92, 246, 0.3);
  margin-left: auto; border-bottom-right-radius: 4px;
}
.msg-type-voice_transcription { border-left: 3px solid var(--amber); }
.msg-type-thinking { border-left: 3px solid var(--accent); opacity: 0.85; font-style: italic; }

.msg-header {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.25rem; font-size: 0.75rem;
}
.msg-sender { font-weight: 600; color: var(--text); }
.msg-sent .msg-sender { color: #ddd; }
.msg-time { color: var(--text-muted); margin-left: auto; font-size: 0.6875rem; }
.msg-badge {
  font-size: 0.625rem; padding: 0.125rem 0.5rem; border-radius: 10px;
  background: var(--surface3);
}
.msg-badge.voice_transcription { color: var(--amber); }
.msg-badge.thinking { color: var(--accent); }
.msg-content { color: var(--text-dim); }
.msg-sent .msg-content { color: #ccc; }
.msg-expand { color: var(--blue); cursor: pointer; font-weight: 500; }

.msg-pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 1rem; padding: 1rem 0; margin-top: 0.5rem;
}
.pag-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 1rem; color: var(--text); cursor: pointer; font-size: 0.8125rem;
}
.pag-btn:active { background: var(--surface2); }
.pag-info { color: var(--text-dim); font-size: 0.75rem; }

.empty { text-align: center; padding: 3rem; color: var(--text-dim); }
.empty .emoji { font-size: 3rem; margin-bottom: 0.75rem; }

@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-content { border-radius: var(--radius); max-height: 80vh; margin-bottom: 2rem; }
  .modal { align-items: center; }
}
