/* AIVideoSummary Web UI — polished */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f9f9fb;
  --border: #d2d2d7;
  --border-light: #e8e8ed;
  --primary: #0071e3;
  --primary-hover: #0077ed;
  --primary-bg: #e8f0fc;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --muted-light: #86868b;
  --error: #d70015;
  --error-bg: #fff0f0;
  --error-border: #fcc;
  --success: #1c7a3b;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 16px rgba(0,0,0,.07);
  --shadow-hover: 0 4px 24px rgba(0,0,0,.10);
  --transition: .15s ease;
  --max-w: 780px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --surface-2: #3a3a3c;
    --border: #3a3a3c;
    --border-light: #48484a;
    --primary: #3a86ff;
    --primary-hover: #5b9fff;
    --primary-bg: #1a2a44;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --muted-light: #8d8d92;
    --error: #ff6b6b;
    --error-bg: #2c1a1a;
    --error-border: #6b2020;
    --shadow: 0 2px 16px rgba(0,0,0,.35);
    --shadow-hover: 0 4px 24px rgba(0,0,0,.50);
  }
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--muted);
  font-size: .88rem;
  margin-top: 2px;
}

main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 28px 16px 80px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.input-card { margin-bottom: 24px; }

/* ── Input form ────────────────────────────────────────────────────────────── */
#input-form {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

#url-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: .97rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

#url-input::placeholder { color: var(--muted-light); }
#url-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

#submit-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 22px;
  font-size: .97rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}

#submit-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

#submit-btn:active:not(:disabled) { transform: translateY(0); }

#submit-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* ── Status / error ────────────────────────────────────────────────────────── */
#status-area { min-height: 0; }

.status-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: .95rem;
  padding: 20px 0;
}

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

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

.progress-dots::after {
  content: "";
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}

.error-msg {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  color: var(--error);
  padding: 12px 16px;
  font-size: .92rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.error-msg .error-icon { flex-shrink: 0; font-style: normal; }

/* ── Result — video meta header ────────────────────────────────────────────── */
.meta-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.result-title a {
  color: var(--text);
  text-decoration: none;
}

.result-title a:hover { text-decoration: underline; }

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: .85rem;
  color: var(--muted);
  align-items: center;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.meta-icon { font-style: normal; }

/* ── Section labels ────────────────────────────────────────────────────────── */
.section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── TL;DR ─────────────────────────────────────────────────────────────────── */
.tldr-text {
  font-size: .97rem;
  line-height: 1.7;
  color: var(--text);
}

/* ── Key points ────────────────────────────────────────────────────────────── */
.key-points {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.key-points li {
  display: flex;
  gap: 10px;
  font-size: .95rem;
  line-height: 1.55;
}

.key-points li::before {
  content: "▸";
  color: var(--primary);
  flex-shrink: 0;
  margin-top: .05em;
}

/* ── Chapters ──────────────────────────────────────────────────────────────── */
.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chapter-block {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
}

.chapter-block:first-child { padding-top: 4px; }
.chapter-block:last-child { border-bottom: none; padding-bottom: 0; }

.chapter-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.chapter-ts {
  display: inline-flex;
  align-items: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-bg);
  border-radius: 5px;
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
  transition: background var(--transition);
}

.chapter-ts:hover { background: color-mix(in srgb, var(--primary) 20%, transparent); }

.chapter-title {
  font-weight: 600;
  font-size: .97rem;
  flex: 1;
  min-width: 0;
}

.chapter-takeaway {
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-style: italic;
  line-height: 1.6;
}

.bullets {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 6px;
}

.bullets li {
  display: flex;
  gap: 8px;
  font-size: .9rem;
  color: var(--text);
  line-height: 1.5;
}

.bullets li::before {
  content: "–";
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Keywords ──────────────────────────────────────────────────────────────── */
.keywords-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
}

.keywords-list li {
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 4px 13px;
  font-size: .83rem;
  color: var(--muted);
  transition: background var(--transition);
}

.keywords-list li:hover {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: transparent;
}

/* ── Cost line ─────────────────────────────────────────────────────────────── */
.cost-line {
  font-size: .8rem;
  color: var(--muted-light);
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.cost-item { white-space: nowrap; }

/* ── Action buttons ────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--muted-light);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) { transform: translateY(0); }

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

.btn-icon { font-style: normal; font-size: .95em; }

.btn-success {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: color-mix(in srgb, var(--success) 8%, transparent);
}

/* ── Q&A section ───────────────────────────────────────────────────────────── */
.qa-card {}

.qa-form {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 16px;
}

#qa-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

#qa-input::placeholder { color: var(--muted-light); }
#qa-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

#qa-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

#qa-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
#qa-btn:active:not(:disabled) { transform: translateY(0); }
#qa-btn:disabled { opacity: .5; cursor: not-allowed; }

.qa-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.qa-pair { display: flex; flex-direction: column; gap: 6px; }

.qa-q {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.qa-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  flex-shrink: 0;
}

.qa-label-q { color: var(--primary); }
.qa-label-a { color: var(--muted); }

.qa-q-text { font-size: .95rem; font-weight: 500; }

.qa-a {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.qa-a-text {
  font-size: .93rem;
  line-height: 1.65;
  color: var(--text);
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
  flex: 1;
}

.qa-a-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .92rem;
  color: var(--muted);
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border);
  flex: 1;
}

.qa-error-text {
  font-size: .9rem;
  color: var(--error);
  padding: 8px 12px;
  background: var(--error-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--error);
  flex: 1;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  header { padding: 14px 16px; }
  header h1 { font-size: 1.15rem; }
  main { padding: 20px 12px 60px; }
  .card { padding: 18px 16px; }

  #input-form { flex-direction: column; }
  #submit-btn { width: 100%; }

  .qa-form { flex-direction: column; }
  #qa-btn { width: 100%; }

  .action-bar { flex-direction: column; }
  .btn { justify-content: center; }
}
