/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  width: 360px;
}
.login-card h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
.login-card p { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  margin-bottom: 1rem;
  outline: none;
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
  width: 100%;
  padding: 0.65rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
}
.login-card button:hover { background: var(--primary-hover); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; }

/* ── App Layout ── */
.app-layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand { padding: 1.25rem 1.25rem 0.75rem; }
.sidebar-brand h2 { font-size: 1.2rem; }
.nav-links { list-style: none; flex: 1; padding: 0.5rem 0; }
.nav-link {
  display: block;
  padding: 0.55rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active {
  color: var(--primary);
  border-left-color: var(--primary);
  background: #eef2ff;
  font-weight: 500;
}
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-text:hover { color: var(--danger); }

/* Main content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

/* ── Section headings ── */
.section-title {
  font-size: 1.35rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }

/* ── Cards / Lists ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.card p { font-size: 0.9rem; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn + .btn { margin-left: 0.5rem; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab-btn {
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Search bar ── */
.search-bar {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
  outline: none;
}
.search-bar:focus { border-color: var(--primary); }

/* ── Event draft card ── */
.draft-card { border-left: 3px solid var(--warning); }
.draft-card .score { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.draft-card .meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.draft-card .notes {
  background: var(--bg);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin: 0.75rem 0;
  white-space: pre-wrap;
}
.draft-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

/* ── Member card ── */
.member-card { display: flex; align-items: flex-start; gap: 1rem; }
.member-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.member-info { flex: 1; }
.member-info h3 { font-size: 0.95rem; }
.member-info .profile-summary {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin-top: 0.25rem;
}
.member-status {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
}
.member-status.active { background: #dcfce7; color: #166534; }
.member-status.inactive { background: #fef3c7; color: #92400e; }

/* ── Agent editor ── */
.agent-editor { margin-bottom: 1.5rem; }
.agent-editor label { display: block; font-weight: 600; margin-bottom: 0.5rem; font-size: 0.95rem; }
.agent-editor textarea {
  width: 100%;
  min-height: 220px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.agent-editor textarea:focus { border-color: var(--primary); }
.agent-editor .save-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
.save-msg { font-size: 0.85rem; color: var(--success); }

/* ── Import / drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 1.5rem;
}
.drop-zone.dragover { border-color: var(--primary); background: #eef2ff; }
.drop-zone p { font-size: 0.95rem; }
.drop-zone input[type=file] { display: none; }

.import-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.import-table th, .import-table td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.import-table th { font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.04em; }

/* ── Settings / Health ── */
.health-grid { display: grid; gap: 0.75rem; }
.health-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.health-dot.connected { background: var(--success); }
.health-dot.disconnected { background: var(--text-muted); }
.health-dot.error { background: var(--danger); }
.health-name { font-weight: 500; flex: 1; }
.health-since { font-size: 0.8rem; color: var(--text-muted); }

/* ── Reasoning Terminal (dark theme) ── */
.reasoning-section {
  background: #0d1117;
  color: #c9d1d9;
  border-radius: var(--radius);
  min-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
}
.reasoning-section .section-title { color: #e6edf3; }

.terminal-output {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.7;
  max-height: calc(100vh - 14rem);
  background: #010409;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.terminal-line { padding: 0.1rem 0; }
.terminal-line .ts { color: #484f58; margin-right: 0.75rem; }
.terminal-line .job { color: #58a6ff; margin-right: 0.5rem; }
.terminal-line .lvl-step { color: #f0883e; }
.terminal-line .lvl-detail { color: #8b949e; }
.terminal-line .lvl-correlation { color: #d2a8ff; }
.terminal-line .lvl-score { color: #7ee787; }
.terminal-line .lvl-decision { color: #ff7b72; }
.terminal-line .lvl-research { color: #79c0ff; }
.terminal-line .msg { color: #c9d1d9; }

.reasoning-input {
  display: flex;
  gap: 0.5rem;
  padding: 0 0 0.5rem;
}
.reasoning-input input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  background: #161b22;
  border: 1px solid #30363d;
  color: #c9d1d9;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  outline: none;
}
.reasoning-input input:focus { border-color: #58a6ff; }
.reasoning-input input::placeholder { color: #484f58; }
.reasoning-input button {
  padding: 0.6rem 1rem;
  background: #238636;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.reasoning-input button:hover { background: #2ea043; }
.reasoning-input button:disabled { opacity: 0.5; cursor: default; }

.reasoning-answer {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  white-space: pre-wrap;
  color: #e6edf3;
}
.reasoning-answer .answer-label { color: #7ee787; font-weight: 600; margin-bottom: 0.35rem; }

/* ── Empty states ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { font-size: 0.95rem; }

/* ── Loading spinner ── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar-brand { display: none; }
  .nav-links { display: flex; padding: 0; }
  .nav-link {
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 0.75rem 1rem;
    white-space: nowrap;
  }
  .nav-link.active { border-left-color: transparent; border-bottom-color: var(--primary); }
  .sidebar-footer { display: none; }
  .main-content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
