:root {
  color-scheme: light;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-soft: #f0f3f1;
  --text: #15201c;
  --muted: #6c7670;
  --line: #e4e8e6;
  --accent: #11b886;
  --accent-strong: #0c9a71;
  --accent-soft: #e3f7ef;
  --danger: #e03131;
  --danger-soft: #fdecec;
  --amber: #b1740a;
  --amber-soft: #fdf0d8;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 10px 30px rgba(20, 32, 28, 0.07);
  --shadow-soft: 0 2px 10px rgba(20, 32, 28, 0.05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ===== 상단바 ===== */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px clamp(16px, 4vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { font-size: 20px; }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; }
.server-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
}
.server-pill.ok { color: var(--accent-strong); background: var(--accent-soft); border-color: transparent; }
.server-pill.error { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

/* ===== 레이아웃 ===== */
.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px clamp(16px, 4vw, 28px) 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== 녹음 히어로 ===== */
.recorder-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px 20px;
  text-align: center;
}
.recorder-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.mic-button {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: radial-gradient(circle at 30% 25%, #1ad29c, var(--accent));
  box-shadow: 0 12px 28px rgba(17, 184, 134, 0.38);
  color: #fff;
  font-size: 40px;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.mic-button:hover { transform: translateY(-2px); }
.mic-button:active { transform: scale(0.96); }
.mic-button:disabled {
  cursor: default;
  background: #cfd8d4;
  box-shadow: none;
}
.recorder-meta { display: flex; flex-direction: column; gap: 2px; }
.recorder-meta strong { font-size: 15px; font-weight: 700; }
.timer { font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 800; letter-spacing: 0.5px; }
.record-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 70px);
  width: 11px; height: 11px;
  border-radius: 50%;
  background: transparent;
}
.record-dot.active {
  background: var(--danger);
  box-shadow: 0 0 0 0 rgba(224, 49, 49, 0.5);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 49, 49, 0.5); }
  70% { box-shadow: 0 0 0 10px rgba(224, 49, 49, 0); }
  100% { box-shadow: 0 0 0 0 rgba(224, 49, 49, 0); }
}

.waveform {
  width: 100%;
  height: 0;
  display: block;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  opacity: 0;
  transition: height 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}
.waveform.active { height: 76px; opacity: 1; margin: 16px 0 8px; }
.level-meter {
  width: 100%;
  height: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
  opacity: 0;
  transition: height 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}
.level-meter.active { height: 8px; opacity: 1; margin: 0 0 10px; }
.level-meter-fill { height: 100%; width: 0%; border-radius: 999px; background: var(--accent); transition: width 0.08s linear, background 0.15s ease; }
.level-meter-fill[data-level="mid"] { background: var(--amber); }
.level-meter-fill[data-level="peak"] { background: var(--danger); }

.recorder-controls { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.recorder-hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* ===== 버튼 ===== */
.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.solid { background: var(--accent); color: #fff; }
.btn.solid:hover:not(:disabled) { background: var(--accent-strong); }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-soft); }
.btn.tiny { padding: 7px 13px; font-size: 12.5px; font-weight: 600; background: var(--surface-soft); color: var(--text); }
.btn.tiny:hover:not(:disabled) { background: #e6ebe8; }
.icon-button {
  width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 16px; color: var(--muted);
  display: grid; place-items: center; transition: background 0.15s ease;
}
.icon-button:hover { background: var(--surface-soft); }
.icon-button.danger { color: var(--danger); }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row .btn { flex: 1; min-width: 130px; }

/* ===== 업로드 fold ===== */
.upload-fold { margin-top: 16px; text-align: left; }
.upload-fold > summary {
  cursor: pointer; list-style: none; text-align: center;
  font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 8px; border-radius: var(--radius-sm);
}
.upload-fold > summary::-webkit-details-marker { display: none; }
.upload-fold[open] > summary { color: var(--text); }
.upload-body { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.drop-zone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 2px dashed var(--line); border-radius: var(--radius-sm);
  padding: 20px; cursor: pointer; text-align: center; transition: border-color 0.15s ease, background 0.15s ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone strong { font-size: 14px; }
.drop-zone small { color: var(--muted); font-size: 11.5px; }
.drop-zone input[type="file"] { display: none; }
.wave-mark { display: inline-flex; gap: 3px; align-items: flex-end; height: 22px; margin-bottom: 4px; }
.wave-mark span { width: 3px; background: var(--accent); border-radius: 2px; animation: wave 1s ease-in-out infinite; }
.wave-mark span:nth-child(1) { height: 8px; animation-delay: 0s; }
.wave-mark span:nth-child(2) { height: 16px; animation-delay: .1s; }
.wave-mark span:nth-child(3) { height: 22px; animation-delay: .2s; }
.wave-mark span:nth-child(4) { height: 16px; animation-delay: .3s; }
.wave-mark span:nth-child(5) { height: 8px; animation-delay: .4s; }
@keyframes wave { 0%,100% { transform: scaleY(0.6); } 50% { transform: scaleY(1); } }
.option-row { display: flex; gap: 10px; }
.option { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.option select, .compact-select {
  font: inherit; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}

/* ===== 진행/메시지 ===== */
.progress-wrap { margin-top: 14px; text-align: left; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.progress-track { height: 8px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.message { margin: 12px 0 0; font-size: 13px; color: var(--muted); min-height: 18px; }
.message.error { color: var(--danger); font-weight: 600; }

/* ===== 카드 공통 ===== */
.result-card, .list-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 800; margin: 0; }
.card-head.compact { margin: 14px 0 8px; }
.card-head.compact h3 { font-size: 14px; margin: 0; }
.card-actions, .result-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.result-card.result-flash { animation: flash 1.1s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow-soft); } }

/* ===== 탭/결과 ===== */
.tabs { display: inline-flex; background: var(--surface-soft); border-radius: 999px; padding: 4px; gap: 2px; margin-bottom: 14px; }
.tab { font: inherit; font-weight: 700; font-size: 13px; border: none; background: transparent; color: var(--muted); padding: 8px 18px; border-radius: 999px; cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.result-panel { display: none; }
.result-panel.active { display: block; }
.summary-layout { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .summary-layout { grid-template-columns: 1.6fr 1fr; } }
.editable-result {
  width: 100%; min-height: 240px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  padding: 14px; font: inherit; font-size: 15px; line-height: 1.75;
}
#transcriptEditor, #normalizedEditor { min-height: 320px; }
.side-stack { display: flex; flex-direction: column; gap: 12px; }
.side-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-soft); }
.side-box h3 { margin: 0 0 8px; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.keyword-list, .action-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; }
.empty-result { color: var(--muted); text-align: center; padding: 40px 16px; font-size: 14px; }

.result-extra { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.result-extra > summary { cursor: pointer; list-style: none; font-size: 13px; font-weight: 600; color: var(--muted); }
.result-extra > summary::-webkit-details-marker { display: none; }
.result-metadata { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-top: 12px; }
.metadata-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; min-width: 130px; }
.metadata-field input { font: inherit; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.feedback-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ===== 기록 목록 ===== */
.history-search {
  width: 100%; margin-bottom: 12px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-soft); color: var(--text); font: inherit; font-size: 14px;
}
.history-search:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; transition: border-color 0.15s ease, background 0.15s ease;
}
.history-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.history-open { flex: 1; min-width: 0; text-align: left; background: none; border: none; cursor: pointer; display: flex; flex-direction: column; gap: 3px; padding: 0; font: inherit; }
.history-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-preview { color: var(--text); opacity: 0.78; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { color: var(--muted); font-size: 12px; }
.history-tags { color: var(--accent-strong); font-size: 12px; }
.history-tags:empty { display: none; }
.history-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.status-chip { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); white-space: nowrap; }
.status-chip.completed { background: var(--accent-soft); color: var(--accent-strong); }
.status-chip.failed { background: var(--danger-soft); color: var(--danger); }
.status-chip.processing, .status-chip.queued, .status-chip.uploading, .status-chip.pending { background: var(--amber-soft); color: var(--amber); }
.retry-button, .delete-button { font: inherit; font-size: 11.5px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 4px 9px; cursor: pointer; color: var(--muted); }
.retry-button:hover, .delete-button:hover { background: var(--surface-soft); }
.delete-button { color: var(--danger); }
.empty-list { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 13.5px; }
.empty-list.compact-empty { padding: 16px; }

/* ===== 접이식 (설정/고급) ===== */
.fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-soft); }
.fold > .fold-summary { cursor: pointer; list-style: none; padding: 14px 18px; font-size: 13.5px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.fold > .fold-summary::-webkit-details-marker { display: none; }
.fold > .fold-summary::after { content: "▾"; margin-left: auto; }
.fold[open] > .fold-summary { border-bottom: 1px solid var(--line); color: var(--text); }
.fold[open] > .fold-summary::after { content: "▴"; }
.fold-body { padding: 16px 18px; }
.settings-block { margin-bottom: 16px; }
.settings-block h3 { font-size: 13px; margin: 0 0 10px; color: var(--muted); }
.auth-controls, .account-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.auth-controls label, .account-controls label { font-size: 12px; color: var(--muted); width: 100%; }
.auth-controls input, .account-controls input { font: inherit; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text); flex: 1; min-width: 140px; }
.system-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 0; }
.system-grid > div { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface-soft); }
.system-grid dt { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.system-grid dd { margin: 0; font-size: 13px; font-weight: 700; }
.audit-list { display: flex; flex-direction: column; gap: 6px; }
.audit-item { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; display: flex; flex-direction: column; gap: 2px; background: var(--surface-soft); }
.audit-item strong { font-size: 13px; }
.audit-item span { font-size: 12px; color: var(--muted); }
.audit-item small { font-size: 11.5px; color: var(--muted); }
