*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0f0f0f;
  --card: #1a1a1a;
  --card-border: #2a2a2a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Header */
header {
  padding: 1.5rem 1rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* User area */
.user-area { display: flex; align-items: center; gap: 0.75rem; }
.user-info { display: flex; align-items: center; gap: 0.5rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; }
.user-info span { font-size: 0.875rem; color: var(--text-muted); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: var(--accent-hover); }

/* Auth gate */
.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 2rem;
}
.auth-card {
  text-align: center;
  max-width: 400px;
  padding: 3rem 2rem;
}
.auth-icon { margin-bottom: 1.5rem; }
.auth-title {
  font-size: 1.25rem !important;
  color: var(--text) !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  margin-bottom: 0.75rem;
}
.auth-desc {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

/* Layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h2 { margin-bottom: 0; }
.card-actions { display: flex; gap: 0.5rem; }

/* Record button */
.record-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.btn-record {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
}
.btn-record:hover { border-color: var(--accent-hover); background: rgba(99,102,241,0.1); }
.btn-record:active { transform: scale(0.95); }
.record-icon {
  width: 32px;
  height: 32px;
  background: var(--danger);
  border-radius: 50%;
  transition: all 0.2s;
}
.btn-record.recording .record-icon {
  border-radius: 4px;
  width: 24px;
  height: 24px;
}
.btn-record.recording {
  border-color: var(--danger);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
}

/* Record actions */
.record-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.record-actions[hidden] { display: none !important; }
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
}
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-record.paused { border-color: #f59e0b; animation: none; }
.btn-record.paused .record-icon {
  background: #f59e0b;
  border-radius: 50%;
  width: 32px;
  height: 32px;
}

.timer {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.hint {
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-align: center;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(99,102,241,0.05);
}
.drop-zone p { color: var(--text-muted); }
.file-name {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(99,102,241,0.1);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--accent-hover);
}

/* Inputs */
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color 0.2s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
}
.input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
  background: var(--accent);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.97); }
.btn-secondary {
  background: var(--card-border);
  cursor: pointer;
}
.btn-secondary:hover { background: #3a3a3a; }
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--card-border);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.2s;
}
.btn-icon:hover { background: #3a3a3a; color: var(--text); }

/* Reports list */
.search-bar { margin-bottom: 0.75rem; }
.input-sm { padding: 0.5rem 0.75rem; font-size: 0.8125rem; }
.reports-list { display: flex; flex-direction: column; gap: 0.25rem; max-height: 300px; overflow-y: auto; }
.report-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.report-item:hover { border-color: var(--accent); background: rgba(99,102,241,0.05); }
.report-item.active { border-color: var(--accent); background: rgba(99,102,241,0.1); }
.report-item-info { flex: 1; min-width: 0; }
.report-item-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.report-item-date { font-size: 0.6875rem; color: var(--text-muted); margin-top: 0.125rem; }
.report-item-delete {
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.report-item-delete:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

/* Steps */
.steps {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: color 0.3s;
}
.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--card-border);
  transition: all 0.3s;
  flex-shrink: 0;
}
.step.active { color: var(--accent-hover); font-weight: 500; }
.step.active .step-dot { background: var(--accent); box-shadow: 0 0 8px rgba(99,102,241,0.5); }
.step.done { color: var(--success); }
.step.done .step-dot { background: var(--success); }

/* Output */
.output {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 500px;
  overflow-y: auto;
}
.output::-webkit-scrollbar { width: 6px; }
.output::-webkit-scrollbar-track { background: transparent; }
.output::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 3px; }

/* Markdown styling in report */
.markdown h1, .markdown h2, .markdown h3 { color: var(--text); margin: 1rem 0 0.5rem; }
.markdown h1 { font-size: 1.25rem; }
.markdown h2 { font-size: 1.1rem; }
.markdown h3 { font-size: 1rem; }
.markdown strong { color: var(--accent-hover); }
.markdown table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.markdown th, .markdown td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--card-border);
  text-align: left;
  font-size: 0.8125rem;
}
.markdown th { background: var(--card); color: var(--accent-hover); }
.markdown ul, .markdown ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.markdown li { margin: 0.25rem 0; }
.markdown p { margin: 0.5rem 0; }

/* ── Archive page ── */
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.header-actions a { text-decoration: none; }

.archive-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.archive-sidebar { display: flex; flex-direction: column; gap: 1rem; }
.archive-detail { flex: 1; min-width: 0; }

.archive-search { margin-bottom: 0.75rem; }
.archive-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filter-row { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 140px; }
.filter-label { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; min-width: 40px; }
.archive-list-card { flex: 1; }
.archive-list-header { margin-bottom: 0.5rem; }
.results-count { font-size: 0.75rem; color: var(--text-muted); }
.archive-list { display: flex; flex-direction: column; gap: 0.25rem; max-height: 60vh; overflow-y: auto; }

.archive-item {
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.archive-item:hover { border-color: var(--accent); background: rgba(99,102,241,0.05); }
.archive-item.active { border-color: var(--accent); background: rgba(99,102,241,0.1); }
.archive-item-title { font-size: 0.875rem; font-weight: 500; color: var(--text); }
.archive-item-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.125rem; }

/* Detail panel */
.detail-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; min-height: 400px; color: var(--text-muted); text-align: center;
}
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.detail-title { font-size: 1.25rem; font-weight: 600; color: var(--text); }
.detail-date { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }
.detail-output { max-height: 65vh; }
.btn-icon-danger:hover { background: rgba(239,68,68,0.15); color: var(--danger); }
.btn-back { display: none; margin-top: 1rem; }

/* Tabs */
.detail-tabs { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 1px solid var(--card-border); }
.tab {
  padding: 0.5rem 1rem; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: 0.875rem; cursor: pointer; transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-hover); border-bottom-color: var(--accent); }

/* Profile page */
.profile-layout { max-width: 640px; margin: 0 auto; padding: 1rem; }
.profile-card { padding: 2rem; }
.profile-intro { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem; line-height: 1.6; }
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--text); margin-bottom: 0.375rem; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; }
.save-status { font-size: 0.8125rem; color: var(--success); }

/* Edit mode */
.edit-field { margin-bottom: 1rem; }
.edit-label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.375rem; }
.edit-textarea {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  padding: 0.75rem;
}
.edit-actions { display: flex; gap: 0.5rem; }

/* Desktop archive */
@media (min-width: 1025px) {
  .archive-layout { flex-direction: row; align-items: flex-start; }
  .archive-sidebar { flex: 0 0 400px; }
  .archive-detail {
    background: var(--card); border: 1px solid var(--card-border);
    border-radius: var(--radius); padding: 1.5rem;
  }
}

/* Mobile archive */
@media (max-width: 767px) {
  .archive-layout.show-detail .archive-sidebar { display: none; }
  .archive-layout.show-detail .archive-detail { display: block; }
  .archive-layout:not(.show-detail) .archive-detail { display: none; }
  .btn-back { display: inline-flex; }
  .archive-filters { flex-direction: column; }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Desktop layout */
@media (min-width: 1025px) {
  main {
    flex-direction: row;
    align-items: flex-start;
  }
  .col-left { flex: 0 0 380px; display: flex; flex-direction: column; gap: 1rem; }
  .col-right { flex: 1; display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

  .btn-record { width: 48px; height: 48px; }
  .record-icon { width: 20px; height: 20px; }
  .btn-record.recording .record-icon { width: 16px; height: 16px; }
  .record-controls { flex-direction: row; }
  .timer { font-size: 1.25rem; }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1024px) {
  .btn-record { width: 64px; height: 64px; }
  .record-icon { width: 26px; height: 26px; }
}

/* Mobile */
@media (max-width: 767px) {
  header { padding: 1.5rem 1rem 0.75rem; }
  header h1 { font-size: 1.5rem; }
  .card { padding: 1.25rem; }
  .output { max-height: 350px; }
}
