/* ===== Design Tokens ===== */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --bg-card: #1e2230;
  --bg-card-hover: #252a3a;
  --surface-glass: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(99, 179, 237, 0.3);

  --text-primary: #e8eaf0;
  --text-secondary: #9ca3b4;
  --text-tertiary: #6b7280;
  --text-accent: #63b3ed;

  --accent: #63b3ed;
  --accent-hover: #4da1db;
  --accent-glow: rgba(99, 179, 237, 0.15);
  --accent-2: #9f7aea;
  --accent-3: #48bb78;

  --danger: #fc8181;
  --danger-bg: rgba(252, 129, 129, 0.1);
  --warning: #f6ad55;
  --success: #68d391;

  /* Category Colors */
  --cat-chief: #f6ad55;
  --cat-symptom: #fc8181;
  --cat-physical: #63b3ed;
  --cat-blood: #f687b3;
  --cat-imaging: #9f7aea;
  --cat-treatment: #68d391;
  --cat-other: #a0aec0;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
  white-space: nowrap;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-sub {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 0.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: var(--accent);
  color: #0f1117;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-glow);
}

.btn-danger {
  background: rgba(252, 129, 129, 0.15);
  color: var(--danger);
  border-color: rgba(252, 129, 129, 0.3);
}

.btn-danger:hover {
  background: rgba(252, 129, 129, 0.25);
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-content: start;
}

/* ===== Panels ===== */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-title .icon {
  font-size: 1.2rem;
}

.panel-body {
  padding: 1.5rem;
}

/* ===== Recorder Panel ===== */
.recorder-panel {
  grid-column: 1 / -1;
}

.recorder-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.5rem;
  gap: 2rem;
}

.record-btn-container {
  position: relative;
}

.record-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 2rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.record-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
  transform: scale(1.05);
}

.record-btn.recording {
  border-color: var(--danger);
  color: #fff;
  background: var(--danger);
  animation: none;
}

.record-btn.recording:hover {
  background: #e66a6a;
  transform: scale(1.05);
}

/* Pulse ring animation */
.pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  opacity: 0;
  pointer-events: none;
}

.recording .pulse-ring {
  animation: pulse-ring 1.5s ease-out infinite;
}

@keyframes pulse-ring {
  0% {
    width: 100px;
    height: 100px;
    opacity: 0.6;
  }

  100% {
    width: 160px;
    height: 160px;
    opacity: 0;
  }
}

.recorder-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.timer {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.05em;
  min-width: 120px;
  text-align: center;
}

.timer.active {
  color: var(--danger);
}

.recorder-status {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status-dot.recording {
  background: var(--danger);
  animation: blink 1s ease-in-out infinite;
}

.status-dot.paused {
  background: var(--warning);
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

.pause-btn,
.stop-btn {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
}

/* ===== Waveform ===== */
.waveform-container {
  width: 100%;
  max-width: 500px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.waveform-bar {
  width: 3px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
  transition: height 0.1s ease;
  opacity: 0.4;
}

.waveform-bar.active {
  opacity: 1;
  animation: wave var(--delay, 0.5s) ease-in-out infinite alternate;
}

@keyframes wave {
  0% {
    height: 8px;
  }

  100% {
    height: var(--max-h, 40px);
  }
}

/* ===== Transcript Panel ===== */
.transcript-content {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
}

.transcript-text {
  font-size: 0.9375rem;
  line-height: 1.8;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-tertiary);
  gap: 0.75rem;
}

.transcript-placeholder .icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

/* ===== Analysis Panel ===== */
.analysis-content {
  min-height: 200px;
  max-height: 600px;
  overflow-y: auto;
}

.category-section {
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition);
}

.category-section:last-child {
  margin-bottom: 0;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  background: var(--surface-glass);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.category-header:hover {
  background: rgba(255, 255, 255, 0.06);
}

.category-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.category-name {
  flex: 1;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.category-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
}

.category-body {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
}

.category-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.375rem 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.category-item::before {
  content: '•';
  color: var(--text-tertiary);
  flex-shrink: 0;
  margin-top: 0.05em;
}

.category-item.not-mentioned {
  color: var(--text-tertiary);
  font-style: italic;
}

/* Category color coding */
.cat-chief .category-badge {
  background: rgba(246, 173, 85, 0.15);
  color: var(--cat-chief);
}

.cat-chief .category-header {
  border-left: 3px solid var(--cat-chief);
}

.cat-symptom .category-badge {
  background: rgba(252, 129, 129, 0.15);
  color: var(--cat-symptom);
}

.cat-symptom .category-header {
  border-left: 3px solid var(--cat-symptom);
}

.cat-physical .category-badge {
  background: rgba(99, 179, 237, 0.15);
  color: var(--cat-physical);
}

.cat-physical .category-header {
  border-left: 3px solid var(--cat-physical);
}

.cat-blood .category-badge {
  background: rgba(246, 135, 179, 0.15);
  color: var(--cat-blood);
}

.cat-blood .category-header {
  border-left: 3px solid var(--cat-blood);
}

.cat-imaging .category-badge {
  background: rgba(159, 122, 234, 0.15);
  color: var(--cat-imaging);
}

.cat-imaging .category-header {
  border-left: 3px solid var(--cat-imaging);
}

.cat-treatment .category-badge {
  background: rgba(104, 211, 145, 0.15);
  color: var(--cat-treatment);
}

.cat-treatment .category-header {
  border-left: 3px solid var(--cat-treatment);
}

.cat-other .category-badge {
  background: rgba(160, 174, 192, 0.15);
  color: var(--cat-other);
}

.cat-other .category-header {
  border-left: 3px solid var(--cat-other);
}

/* ===== Loading States ===== */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 1rem;
  color: var(--text-tertiary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 0.875rem;
  animation: fade-pulse 1.5s ease-in-out infinite;
}

@keyframes fade-pulse {

  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }
}

/* ===== Progress Bar ===== */
.progress-bar {
  width: 100%;
  max-width: 300px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px;
  transition: width 0.3s ease;
  animation: progress-shimmer 1.5s ease-in-out infinite;
}

@keyframes progress-shimmer {
  0% {
    opacity: 0.7;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0.7;
  }
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition);
}

.modal-backdrop.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: color var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ===== Form Elements ===== */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-mono);
  transition: border-color var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.375rem;
  line-height: 1.4;
}

.form-select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3b4' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  animation: toast-in 0.3s ease;
  max-width: 400px;
}

.toast.success {
  border-color: rgba(104, 211, 145, 0.3);
}

.toast.error {
  border-color: rgba(252, 129, 129, 0.3);
}

.toast.info {
  border-color: rgba(99, 179, 237, 0.3);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast-exit {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ===== History Panel ===== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-accent);
}

.history-item-info {
  flex: 1;
  min-width: 0;
}

.history-item-date {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

.history-item-preview {
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-actions {
  display: flex;
  gap: 0.375rem;
}

.history-delete-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 0.875rem;
  transition: color var(--transition);
}

.history-delete-btn:hover {
  color: var(--danger);
}

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1rem;
  }

  .recorder-panel {
    grid-column: 1;
  }

  .header-inner {
    padding: 0 1rem;
  }

  .logo-sub {
    display: none;
  }

  .app-header {
    padding: 0 0.5rem;
  }

  .header-actions .btn {
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
  }

  .api-status {
    display: none;
  }
}

/* ===== Export Button ===== */
.export-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ===== API Status indicator ===== */
.api-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.api-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.api-status-dot.connected {
  background: var(--success);
}

/* ===== Upload area ===== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 1rem;
}

.upload-area:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-area .icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.upload-area p {
  font-size: 0.875rem;
  color: var(--text-tertiary);
}

/* ===== Summary copy button ===== */
.copy-summary-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* ===== audio playback ===== */
.audio-player {
  width: 100%;
  margin-top: 1rem;
  border-radius: var(--radius-sm);
}

audio {
  width: 100%;
  height: 40px;
  border-radius: var(--radius-sm);
}

audio::-webkit-media-controls-panel {
  background: var(--bg-tertiary);
}

/* ===== URL Input ===== */
.url-input-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0.5rem;
}

/* ===== Audio Download ===== */
.audio-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  width: 100%;
}

.audio-actions audio {
  flex: 1;
}