:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-muted: rgba(0, 0, 0, 0.04);
  --glass: rgba(255, 255, 255, 0.8);
  --border: rgba(0, 0, 0, 0.08);
  --text: #1D1D1F;
  --text-sub: #6E6E73;
  --primary: #0071E3;
  --primary-hover: #0077ED;
  --danger: #FF3B30;
  --green: #30D158;
  --amber: #FF9F0A;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  --bg: #09090B;
  --surface: #121215;
  --surface-muted: rgba(255, 255, 255, 0.06);
  --glass: rgba(18, 18, 21, 0.8);
  --border: rgba(255, 255, 255, 0.08);
  --text: #EDEDEF;
  --text-sub: #A1A1AA;
  --danger: #FF453A;
  --shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.break-words {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.tabular-nums { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.row-end { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.16s var(--ease), background-color 0.18s var(--ease), border-color 0.18s var(--ease), opacity 0.18s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-icon { width: 32px; padding: 0; }
.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-surface {
  background: var(--surface);
  border-color: var(--border);
}
.btn-surface:hover:not(:disabled) { background: var(--surface-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-muted); }
.btn-danger {
  color: var(--danger);
  background: rgba(255, 59, 48, 0.08);
  border-color: rgba(255, 59, 48, 0.18);
}
.btn-danger:hover:not(:disabled) { background: rgba(255, 59, 48, 0.14); }

/* Inputs */
.input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.16);
}
.input-lg { height: 42px; padding-right: 34px; font-size: 14px; }
.textarea { height: auto; padding: 10px 12px; resize: vertical; font-family: inherit; }
.textarea-parse {
  height: auto;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 34px 10px 12px;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  font-family: inherit;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label, .section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sub);
}

/* Badges & Dots */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  background: rgba(0, 113, 227, 0.1);
  color: var(--primary);
}
.badge-muted { background: var(--surface-muted); color: var(--text-sub); }
.badge-green { background: rgba(48, 209, 88, 0.12); color: #1F9E42; }
:root[data-theme="dark"] .badge-green { color: var(--green); }
.badge-amber { background: rgba(255, 159, 10, 0.14); color: #C27400; }
:root[data-theme="dark"] .badge-amber { color: var(--amber); }

.dot { width: 6px; height: 6px; border-radius: 999px; flex-shrink: 0; }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-pulse { box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.22); }

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
}
.auth-topbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 6px;
}
.auth-card {
  width: 100%;
  max-width: 390px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.auth-card.shake { animation: shake 0.36s var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark-sm { width: 28px; height: 28px; border-radius: 8px; }
.auth-title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.auth-sub { margin: 3px 0 0; font-size: 13px; color: var(--text-sub); }
.form-error {
  font-size: 12px;
  color: var(--danger);
  background: rgba(255, 59, 48, 0.08);
  padding: 8px 10px;
  border-radius: 8px;
}

/* Topbar & Workspace */
.app-shell {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.status-pill { max-width: 170px; }

.workspace {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.workbench-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.page-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.015em; }
.page-hint { margin: 4px 0 0; font-size: 13px; color: var(--text-sub); }

.parse-row { display: flex; gap: 10px; align-items: flex-end; }
.parse-input-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.input-clear {
  position: absolute;
  top: 9px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.input-clear:hover { background: var(--surface-muted); color: var(--text); }
.parse-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.parse-btns .btn { height: 42px; }
.header-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Results */
.result-area { display: flex; flex-direction: column; gap: 14px; }
.notice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 159, 10, 0.1);
  border: 1px solid rgba(255, 159, 10, 0.22);
  font-size: 12px;
}
.notice-left { display: flex; align-items: center; gap: 8px; }

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.media-card { overflow: hidden; }
.video-stage, .cover-stage {
  background: #000000;
  width: 100%;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.video-stage video, .cover-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.media-meta { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.meta-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.media-title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.45; }
.meta-author { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-sub); }
.avatar { width: 22px; height: 22px; border-radius: 999px; object-fit: cover; flex-shrink: 0; }

.pages-wrap { padding-top: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.pages-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 160px; overflow-y: auto; }
.pages-list::-webkit-scrollbar { display: none; }
.page-chip {
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
}

.streams-card { overflow: hidden; }
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-title { font-size: 14px; font-weight: 600; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  white-space: nowrap;
  padding: 10px 14px;
  font-size: 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--text-sub); font-weight: 500; }
.data-table tr:last-child td { border-bottom: none; }
.data-table th.text-right, .data-table td.text-right { text-align: right; }
.action-group { display: inline-flex; align-items: center; gap: 6px; }

/* Note Images */
.note-gallery-wrap { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.note-audio-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.note-item {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.note-item img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.note-item-foot { padding: 6px 8px; display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--text-sub); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { max-width: 560px; }
.modal-sm { max-width: 360px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-title-row { display: flex; align-items: center; gap: 8px; }
.modal-title { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sec-status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}
.sec-status-left { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.sessions-list { display: flex; flex-direction: column; gap: 8px; }
.session-row {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.session-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.session-name { font-size: 13px; font-weight: 500; }
.session-sub { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-sub); cursor: pointer; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-muted);
  align-self: flex-start;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  height: 28px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.info-box {
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.info-box-accent { border-color: rgba(0, 113, 227, 0.35); background: rgba(0, 113, 227, 0.06); }
.info-title { font-size: 13px; font-weight: 600; }
.info-sub { margin-top: 3px; font-size: 12px; color: var(--text-sub); }
.qr-box { align-items: center; padding: 10px 0; }
.qr-img-wrap { padding: 10px; background: #FFFFFF; border-radius: 12px; border: 1px solid var(--border); }
.qr-img-wrap img { width: 176px; height: 176px; display: block; }

.key-create-row { display: flex; gap: 8px; align-items: center; }
.key-reveal-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.code-line { font-size: 12px; background: var(--surface); padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); flex: 1; }
.code-block {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Toast */
.toast-root {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  padding: 9px 14px;
  border-radius: 999px;
  background: #1D1D1F;
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  animation: toastIn 0.22s var(--ease);
}
:root[data-theme="dark"] .toast { background: #27272A; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .result-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .parse-row { flex-direction: column; }
  .parse-btns { justify-content: flex-end; }
  .status-pill { max-width: 118px; }
  .topbar-inner { padding: 0 12px; }
  .workspace { padding: 14px 12px 32px; }
}
