:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-soft: #eef2ee;
  --ink: #171b18;
  --ink-soft: #5f6962;
  --line: #dce2dc;
  --line-strong: #c9d1ca;
  --coral: #e84a5f;
  --coral-soft: #fdecef;
  --green: #16805e;
  --green-soft: #e8f4ef;
  --amber: #a66e12;
  --amber-soft: #fbf1dc;
  --charcoal: #171b18;
  --sidebar-ink: #f7faf7;
  --sidebar-muted: #aeb8b0;
  --shadow: 0 8px 28px rgba(23, 27, 24, 0.08);
  --sidebar-width: 232px;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(232, 74, 95, 0.24);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  flex: 0 0 auto;
}

.sr-only {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 24px 16px;
  background: var(--charcoal);
  color: var(--sidebar-ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 22px;
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand div {
  min-width: 0;
}

.brand strong,
.brand span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 16px;
  font-weight: 600;
}

.brand span {
  color: var(--sidebar-muted);
  font-size: 12px;
}

.primary-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--sidebar-muted);
  cursor: pointer;
  gap: 10px;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--sidebar-ink);
}

.nav-item.is-active {
  background: var(--sidebar-ink);
  color: var(--charcoal);
}

.nav-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 14px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-status strong,
.sidebar-status span {
  display: block;
}

.sidebar-status strong {
  font-size: 13px;
  font-weight: 500;
}

.sidebar-status span {
  color: var(--sidebar-muted);
  font-size: 11px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f0b44d;
  box-shadow: 0 0 0 4px rgba(240, 180, 77, 0.12);
}

.main-content {
  width: 100%;
  max-width: 1280px;
  min-width: 0;
  margin: 0 auto;
  padding: 28px 36px 56px;
}

.topbar,
.section-heading,
.preview-header,
.detail-modal > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar {
  min-height: 58px;
  margin-bottom: 24px;
}

.topbar h1,
.section-heading h2,
.detail-modal h2 {
  margin: 0;
  font-weight: 650;
  line-height: 1.25;
}

.topbar h1 {
  font-size: 24px;
}

.section-heading h2,
.detail-modal h2 {
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

.topbar-actions,
.topic-input-row,
.quick-topics,
.filter-row,
.card-actions,
.analysis-tags,
.platform-options,
.metric-summary,
.trend-meta,
.headline-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex: 0 0 auto;
}

.sync-time {
  color: var(--ink-soft);
  font-size: 12px;
}

.icon-button,
.primary-button,
.secondary-button,
.mode-button,
.filter-button,
.quick-topics button,
.inline-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  gap: 8px;
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}

.icon-button:hover,
.secondary-button:hover,
.filter-button:hover,
.quick-topics button:hover,
.inline-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 600;
}

.primary-button {
  background: var(--coral);
  color: #ffffff;
}

.primary-button:hover {
  background: #d94055;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 22px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.mode-button {
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
}

.mode-button:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.mode-button.is-active {
  background: var(--charcoal);
  color: #ffffff;
}

.count-badge,
.pending-badge,
.status-badge,
.source-badge,
.label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  line-height: 1;
}

.count-badge {
  min-width: 20px;
  min-height: 20px;
  justify-content: center;
  padding: 0 6px;
  background: var(--coral);
  color: #ffffff;
}

.mode-button.is-active .count-badge {
  background: #ffffff;
  color: var(--charcoal);
}

.topic-form {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.topic-form > label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
}

.topic-input-row input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

.topic-input-row .primary-button {
  min-height: 48px;
}

.quick-topics {
  flex-wrap: wrap;
  margin-top: 12px;
}

.quick-topics button,
.filter-button,
.inline-action {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
}

#analysis-result {
  margin-top: 24px;
}

.analysis-header {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 24px;
  align-items: stretch;
}

.analysis-title,
.decision-box {
  min-width: 0;
  padding: 22px;
  border-radius: 8px;
}

.analysis-title {
  border: 1px solid var(--line);
  background: var(--surface);
}

.analysis-title h2 {
  margin: 8px 0 6px;
  font-size: 24px;
  line-height: 1.25;
}

.analysis-title p {
  margin: 0;
  color: var(--ink-soft);
}

.decision-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--green-soft);
  color: #0b513c;
}

.decision-box.is-pending {
  background: var(--amber-soft);
  color: #754b08;
}

.decision-box strong {
  display: block;
  margin-bottom: 6px;
  font-size: 26px;
  line-height: 1.2;
}

.decision-box p {
  margin: 0;
}

.decision-box .inline-action {
  align-self: flex-start;
  margin-top: 18px;
  border-color: currentColor;
  color: inherit;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.metric-item {
  min-width: 0;
  min-height: 104px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metric-item:last-child {
  border-right: 0;
}

.metric-item span,
.metric-item small {
  display: block;
  color: var(--ink-soft);
}

.metric-item span {
  font-size: 12px;
}

.metric-item strong {
  display: block;
  margin: 4px 0 2px;
  font-size: 24px;
  line-height: 1.2;
}

.metric-item small {
  font-size: 11px;
}

.analysis-section {
  margin-top: 26px;
}

.analysis-section > header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.analysis-section h3,
.trend-card h3,
.breakout-card h3,
.transcript-preview h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.analysis-section > header span {
  color: var(--ink-soft);
  font-size: 12px;
}

.sparkline {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
  height: 116px;
  padding: 18px 14px 12px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}

.sparkline span {
  min-height: 6px;
  border-radius: 3px 3px 0 0;
  background: var(--coral);
  opacity: 0.82;
}

.sparkline span:last-child {
  background: var(--amber);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table th {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table td.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.author-cell {
  display: flex;
  align-items: center;
  min-width: 130px;
  gap: 10px;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}

.status-badge,
.source-badge,
.label,
.pending-badge {
  padding: 6px 8px;
}

.status-badge.verified,
.source-badge.verified {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.pending,
.source-badge.pending,
.pending-badge {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.hot {
  background: var(--coral-soft);
  color: var(--coral);
}

.status-badge.neutral,
.label {
  background: var(--surface-soft);
  color: var(--ink-soft);
}

.section-heading {
  margin-bottom: 18px;
}

.filter-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-button.is-active {
  border-color: var(--charcoal);
  background: var(--charcoal);
  color: #ffffff;
}

.trend-grid,
.breakout-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.trend-card,
.breakout-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.trend-visual,
.breakout-image {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-soft);
}

.trend-visual img,
.breakout-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.trend-visual.fallback-food {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f3eadf;
  color: #6f4b2e;
}

.trend-visual.fallback-food svg {
  width: 48px;
  height: 48px;
}

.trend-card-body,
.breakout-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 16px;
}

.headline-meta {
  justify-content: space-between;
  margin-bottom: 10px;
}

.trend-card h3,
.breakout-card h3 {
  min-height: 44px;
}

.trend-card p,
.breakout-card p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.trend-meta,
.metric-summary {
  flex-wrap: wrap;
  margin-top: 16px;
}

.trend-meta span,
.metric-summary span {
  display: inline-flex;
  flex-direction: column;
  min-width: 68px;
}

.trend-meta strong,
.metric-summary strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.trend-meta small,
.metric-summary small {
  color: var(--ink-soft);
  font-size: 10px;
}

.card-actions {
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 18px;
}

.card-actions .secondary-button,
.card-actions .primary-button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 12px;
}

.creator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  align-items: start;
  gap: 18px;
}

.transcript-preview {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.preview-header {
  align-items: flex-start;
}

.preview-header .label {
  margin-bottom: 8px;
}

.transcript-text {
  margin: 20px 0;
  padding-left: 14px;
  border-left: 3px solid var(--coral);
  font-size: 15px;
}

.analysis-tags {
  flex-wrap: wrap;
}

.analysis-tags span {
  padding: 6px 8px;
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 11px;
}

.data-note {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.breakout-image {
  aspect-ratio: 4 / 3;
}

.breakout-card h3 {
  min-height: auto;
}

.settings-form {
  display: grid;
  gap: 18px;
}

.settings-form fieldset {
  margin: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.settings-form legend {
  padding: 0 7px;
  font-weight: 650;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.settings-grid label,
.quality-notes {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
}

.settings-grid input,
.settings-grid select,
.quality-notes textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

.settings-grid input,
.settings-grid select {
  height: 42px;
  padding: 0 11px;
}

.quality-notes textarea {
  min-height: 108px;
  padding: 10px 12px;
  resize: vertical;
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 42px;
}

.input-with-unit em {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--ink-soft);
  font-size: 11px;
  font-style: normal;
  transform: translateY(-50%);
}

.platform-options {
  flex-wrap: wrap;
}

.platform-options label {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  gap: 8px;
}

.modal-form {
  display: grid;
  gap: 16px;
}

.modal-form label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
}

.modal-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

.modal-form .primary-button {
  justify-self: start;
}

.modal-open {
  overflow: hidden;
}

.is-spinning svg {
  animation: spin 650ms linear;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 20, 17, 0.55);
}

.detail-modal {
  width: min(680px, 100%);
  max-height: min(760px, 88vh);
  overflow-y: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-modal > header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

#modal-content {
  padding: 20px;
}

.modal-section + .modal-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.modal-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.modal-section p,
.modal-section ul {
  margin: 0;
}

.modal-section ul {
  padding-left: 20px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 15px;
  border-radius: 6px;
  background: var(--charcoal);
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.empty-state {
  padding: 34px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--ink-soft);
  text-align: center;
}

@media (max-width: 1080px) {
  .main-content {
    padding-right: 24px;
    padding-left: 24px;
  }

  .trend-grid,
  .breakout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: block;
    width: 100%;
    height: auto;
    padding: 6px 10px max(6px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(23, 27, 24, 0.12);
  }

  .brand {
    display: none;
  }

  .primary-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .nav-item {
    min-width: 0;
    min-height: 48px;
    flex-direction: column;
    justify-content: center;
    padding: 4px 3px;
    gap: 2px;
    text-align: center;
  }

  .nav-item span {
    width: 100%;
    font-size: 11px;
  }

  .sidebar-status {
    display: none;
  }

  .main-content {
    padding: max(20px, env(safe-area-inset-top)) 16px calc(98px + env(safe-area-inset-bottom));
  }

  .analysis-header,
  .creator-layout {
    grid-template-columns: 1fr;
  }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-item:nth-child(2) {
    border-right: 0;
  }

  .metric-item:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    margin-bottom: 18px;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .sync-time {
    display: none;
  }

  .mode-switch {
    gap: 5px;
    padding: 5px;
  }

  .mode-button {
    min-height: 58px;
    padding: 6px 8px;
    flex-wrap: wrap;
    gap: 5px;
    white-space: normal;
  }

  .topic-form {
    padding: 16px;
  }

  .topic-input-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topic-input-row .primary-button {
    width: 100%;
  }

  .analysis-title,
  .decision-box {
    padding: 18px;
  }

  .analysis-title h2 {
    font-size: 21px;
  }

  .decision-box strong {
    font-size: 23px;
  }

  .metric-item {
    min-height: 94px;
    padding: 14px;
  }

  .metric-item strong {
    font-size: 21px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-row {
    width: 100%;
    justify-content: flex-start;
  }

  .trend-grid,
  .breakout-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .trend-card h3 {
    min-height: auto;
  }

  .data-table th,
  .data-table td {
    padding: 11px 12px;
  }

  .settings-form fieldset {
    padding: 16px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .detail-modal {
    width: 100%;
    max-height: 88vh;
    border-radius: 8px 8px 0 0;
  }

  .toast {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 16px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
