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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #242424;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ─── Nav ──────────────────────────────────────────────────────────── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-links a {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.nav-links a.active {
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}

/* ─── Main ─────────────────────────────────────────────────────────── */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 20px;
}

.btn-record {
  background: var(--accent);
  color: white;
}

.btn-record:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-stop {
  background: var(--red);
  color: white;
}

.btn-stop:hover {
  background: #dc2626;
}

.btn-process {
  background: var(--green);
  color: white;
}

.btn-process:hover {
  background: #16a34a;
}

.btn-save {
  background: var(--accent);
  color: white;
}

.btn-view {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
}

.btn-view:hover {
  background: var(--surface);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface);
}

.hidden {
  display: none !important;
}

/* ─── Capture Page ─────────────────────────────────────────────────── */
.capture-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding-top: 48px;
}

.capture-card {
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
}

.capture-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 18px;
}

.status-icon {
  font-size: 28px;
}

.status-text {
  color: var(--text-muted);
}

.waveform {
  height: 48px;
  margin-bottom: 24px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  opacity: 0.3;
  transition: all 0.3s;
}

.waveform.active {
  opacity: 1;
  background: linear-gradient(90deg, var(--accent) 0%, var(--green) 50%, var(--accent) 100%);
  animation: pulse 1.5s ease-in-out infinite;
}

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

.capture-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* ─── Result Area ──────────────────────────────────────────────────── */
.result-area {
  width: 100%;
  text-align: left;
  margin-top: 24px;
}

.result-area h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.result-transcript pre {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text);
  border: 1px solid var(--border);
}

.result-knowledge {
  margin-top: 24px;
}

#knowledgeContent {
  background: var(--bg);
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 400px;
  overflow-y: auto;
}

#knowledgeContent h2 { font-size: 20px; margin: 16px 0 8px; }
#knowledgeContent h3 { font-size: 16px; margin: 12px 0 6px; color: var(--accent); }
#knowledgeContent h4 { font-size: 14px; margin: 10px 0 4px; }
#knowledgeContent p { margin-bottom: 8px; font-size: 14px; }
#knowledgeContent li { margin-left: 20px; font-size: 14px; }
#knowledgeContent hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
#knowledgeContent strong { color: var(--accent); }

.result-actions {
  margin-top: 16px;
  text-align: center;
}

.result-saved {
  text-align: center;
  margin-top: 24px;
}

.success-message {
  font-size: 18px;
  margin-bottom: 20px;
  color: var(--green);
}

.result-saved .btn {
  margin: 4px;
}

/* ─── Upload (reserved) ────────────────────────────────────────────── */
.upload-card {
  width: 100%;
  max-width: 600px;
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-area:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
}

.upload-icon {
  display: block;
  font-size: 32px;
  margin-bottom: 8px;
}

.upload-text {
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Knowledge Page ───────────────────────────────────────────────── */
.knowledge-page h2 {
  font-size: 22px;
  margin-bottom: 24px;
}

.knowledge-layout {
  display: flex;
  gap: 24px;
  height: calc(100vh - 160px);
  min-height: 400px;
}

.knowledge-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.note-count {
  background: var(--surface-hover);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.sidebar-list::-webkit-scrollbar {
  width: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.file-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 4px;
}

.file-item:hover {
  background: var(--surface-hover);
}

.file-item.active {
  background: rgba(99, 102, 241, 0.12);
  border-left: 3px solid var(--accent);
}

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

.file-date {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Knowledge Viewer ─────────────────────────────────────────────── */
.knowledge-viewer {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  position: relative;
}

.knowledge-viewer::-webkit-scrollbar {
  width: 6px;
}

.knowledge-viewer::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

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

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.viewer-content {
  padding: 32px;
}

.markdown-body h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.markdown-body h3 {
  font-size: 18px;
  margin: 24px 0 12px;
  color: var(--accent);
}

.markdown-body h4 {
  font-size: 15px;
  margin: 16px 0 8px;
  color: var(--text);
}

.markdown-body p {
  margin-bottom: 12px;
  font-size: 15px;
  line-height: 1.8;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.markdown-body ul {
  margin: 8px 0 16px;
  padding-left: 20px;
}

.markdown-body li {
  margin-bottom: 6px;
  font-size: 15px;
  line-height: 1.6;
}

.markdown-body strong {
  color: var(--accent);
}

.markdown-body a {
  color: var(--accent-hover);
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 15px;
  cursor: default;
}

.todo-item input[type="checkbox"] {
  accent-color: var(--accent);
}

.loading, .error, .empty {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.error {
  color: var(--red);
}

/* ─── Scrollbar global ─────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ─── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .knowledge-layout {
    flex-direction: column;
    height: auto;
  }

  .knowledge-sidebar {
    width: 100%;
    max-height: 200px;
  }

  .capture-card {
    padding: 20px;
  }
}
