/* MeetLens — 1인용 음성회의록 PWA
   빌드 단계 없음. 순수 CSS. 다크모드 · 세이프에어리어 · 44px 터치타겟 기준. */

/* ------------------------------------------------------------------ 토큰 */
:root {
  color-scheme: light dark;

  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f1f1ed;
  --text: #16171b;
  --text-muted: #64656d;
  --border: #e3e3dd;
  --border-strong: #cdcdc5;

  --accent: #4b45c6;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfb;

  --ok: #15734a;
  --ok-soft: #e2f3e9;
  --run: #1a5da9;
  --run-soft: #e5eefa;
  --warn: #855400;
  --warn-soft: #fbf0d9;
  --danger: #ac2323;
  --danger-soft: #fce9e9;

  --spk-1: #5a53d6;
  --spk-2: #a25e0c;
  --spk-3: #0e6e62;
  --spk-4: #b53b76;
  --spk-5: #6c5aa8;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 8px 24px -16px rgb(0 0 0 / 22%);

  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e12;
    --surface: #16171d;
    --surface-2: #1e1f28;
    --text: #ecedf2;
    --text-muted: #989ba7;
    --border: #272a34;
    --border-strong: #3b3f4c;

    --accent: #9aa1ff;
    --accent-ink: #12132a;
    --accent-soft: #212338;

    --ok: #63d49c;
    --ok-soft: #14291f;
    --run: #7fb5f6;
    --run-soft: #152131;
    --warn: #e6b455;
    --warn-soft: #2a2415;
    --danger: #ff8b84;
    --danger-soft: #311a1b;

    --spk-1: #8e8bff;
    --spk-2: #eab355;
    --spk-3: #4ecbbb;
    --spk-4: #ef7fae;
    --spk-5: #b19ae8;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 10px 28px -18px rgb(0 0 0 / 70%);
  }
}

/* ------------------------------------------------------------------ 리셋 */
*,
*::before,
*::after { box-sizing: border-box; }

/* .banner/.card 등이 display 를 지정하므로 UA 의 [hidden] 이 밀린다. 명시적으로 이긴다. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    system-ui, "Segoe UI", Roboto, "Noto Sans KR", "Malgun Gothic",
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  line-height: 1.35;
  text-wrap: balance;
  margin: 0;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.25rem; font-weight: 700; }
h2 { font-size: 1.0625rem; font-weight: 650; }
h3 { font-size: 0.9375rem; font-weight: 600; }
p { margin: 0; }

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); color: var(--text); }

.num { font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 50;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: 0 0 var(--r-sm) 0;
  font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------------ 레이아웃 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--sa-t) + 10px) calc(var(--sa-r) + 16px) 10px calc(var(--sa-l) + 16px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.015em;
  text-decoration: none;
  color: inherit;
  min-height: 44px;
}
.topbar .brand svg { width: 26px; height: 26px; flex: none; }
.topbar .spacer { flex: 1 1 auto; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px calc(var(--sa-r) + 16px) calc(var(--sa-b) + 56px) calc(var(--sa-l) + 16px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card > * + * { margin-top: 14px; }

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.card-head .hint {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-left: auto;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.8125rem; }

/* ------------------------------------------------------------------ 폼 */
.field { display: block; }
.field + .field { margin-top: 14px; }

.field > .label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOS 포커스 확대 방지 */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 11px 13px;
  min-height: 44px;
  transition: border-color 140ms ease, background-color 140ms ease;
}
textarea {
  resize: vertical;
  line-height: 1.6;
}
input::placeholder,
textarea::placeholder { color: var(--text-muted); opacity: 0.85; }

input:focus,
textarea:focus { border-color: var(--accent); }

input[type="file"] {
  padding: 9px 12px;
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  margin-right: 12px;
  padding: 8px 14px;
  min-height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

/* ------------------------------------------------------------------ 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 140ms ease, border-color 140ms ease,
    color 140ms ease, opacity 140ms ease, transform 90ms ease;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 82%, var(--text)); }
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--text)); }

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-block { width: 100%; }
/* 글자만 작게 두고 터치 타겟은 44px 를 지킨다. */
.btn-sm { min-height: 44px; padding: 6px 14px; font-size: 0.8125rem; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.btn-row > .btn { flex: 1 1 160px; }

/* ------------------------------------------------------------------ 배지 · 진행률 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge-done { background: var(--ok-soft); color: var(--ok); }
.badge-run { background: var(--run-soft); color: var(--run); }
.badge-queued { background: var(--warn-soft); color: var(--warn); }
.badge-error { background: var(--danger-soft); color: var(--danger); }

.badge-run::before { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.progress {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 260ms ease;
}
.progress.indeterminate > span {
  width: 35% !important;
  animation: slide 1.5s ease-in-out infinite;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

/* ------------------------------------------------------------------ 알림 */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r);
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.banner-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.banner-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
}
.banner-ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}
.banner strong { font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sa-b) + 18px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / 45%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ------------------------------------------------------------------ job 목록 */
.joblist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.job-link {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 14px 4px 14px 16px;
  text-decoration: none;
  color: inherit;
  transition: background-color 140ms ease;
}
.job-link:hover { background: var(--surface-2); }

.job-title {
  font-weight: 650;
  font-size: 0.9375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.job-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.job-progress { margin-top: 9px; }

.job-del {
  flex: none;
  width: 52px;
  display: grid;
  place-items: center;
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.job-del:hover { background: var(--danger-soft); color: var(--danger); }
.job-del svg { width: 18px; height: 18px; }

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 0.875rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
}

/* ------------------------------------------------------------------ 통계 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--surface-2);
  border-radius: var(--r);
  padding: 11px 12px;
}
.stat .k {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}
.stat .v {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.stat .v small {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 2px;
}

/* 화자별 발화비율 막대 */
.ratio-rows { display: flex; flex-direction: column; gap: 12px; }
.ratio-row .ratio-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.875rem;
  margin-bottom: 5px;
}
.ratio-row .ratio-head .name { font-weight: 650; }
.ratio-row .ratio-head .pct {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.ratio-row .ratio-head .sec {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.ratio-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.ratio-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--spk-1);
  transition: width 400ms ease;
}

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  background: var(--spk-1);
}

/* 시간축 4분할 */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.timeline-row {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 10px;
}
.timeline-row .q {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.timeline-bar {
  display: flex;
  height: 22px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.timeline-bar > span {
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bg);
  min-width: 0;
  overflow: hidden;
  transition: flex-basis 400ms ease;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* 이벤트 목록 (침묵·끼어들기·회피·언급·반복어) */
.evlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.evlist li {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  font-size: 0.875rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.evlist li:last-child { border-bottom: 0; padding-bottom: 0; }
.evlist .at {
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  padding-top: 3px;
}
.evlist .who { font-weight: 650; }
.evlist .quote {
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 650;
  margin-right: 6px;
}

/* 접기/펼치기 */
details.fold {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
details.fold > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 18px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 650;
  list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after {
  content: "";
  margin-left: auto;
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 160ms ease;
}
details.fold[open] > summary::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}
details.fold > .fold-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 62vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.tline {
  content-visibility: auto;
  contain-intrinsic-size: auto 76px;
}
.tline .tline-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.tline .tline-head .name { font-weight: 700; color: var(--text); font-size: 0.8125rem; }
.tline p { font-size: 0.9375rem; margin-top: 2px; }

/* 화자 이름 지정 */
.spk-rows { display: flex; flex-direction: column; gap: 12px; }
.spk-row {
  display: grid;
  grid-template-columns: minmax(64px, 96px) 1fr;
  gap: 10px;
  align-items: center;
}
.spk-row .orig {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--text-muted);
  min-width: 0;
}

/* 용어사전 */
.gl-rows {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.gl-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.gl-row:last-child { border-bottom: 0; }
.gl-row.off .gl-terms { opacity: 0.45; }

.gl-terms {
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}
.gl-terms .wrong {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.gl-terms .arrow { color: var(--text-muted); margin: 0 6px; }
.gl-terms .right { font-weight: 650; }

/* 체크박스와 글자가 하나의 터치 타겟이 되게 label 로 감싼다 */
.gl-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.gl-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.gl-del {
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.gl-del:hover { background: var(--danger-soft); color: var(--danger); }
.gl-del svg { width: 17px; height: 17px; }

.gl-add {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.gl-add .field + .field { margin-top: 0; }

/* 복사 폴백 textarea */
.copy-fallback { display: none; }
.copy-fallback.show { display: block; }
.copy-fallback textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  min-height: 180px;
  line-height: 1.5;
  /* 마크다운 원문이라 긴 줄이 많다. 한글에 break-all 은 쓰지 않는다. */
  overflow-wrap: anywhere;
}

/* 파일 정보 줄 */
.filemeta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 8px;
  min-width: 0;
}
.filemeta .fname {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* 로딩 스켈레톤 */
.skeleton {
  height: 74px;
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ------------------------------------------------------------------ 모션 최소화 */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------------ 넓은 화면 */
@media (min-width: 560px) {
  h1 { font-size: 1.375rem; }
  main { padding-top: 24px; gap: 20px; }
  .card { padding: 22px; }
}
