/* ═══════════════════════════════════════════════════
   消息小票 — Notion DESIGN.md
   Warm canvas, hairline dividers, document flow, zero cards
   ═══════════════════════════════════════════════════ */

:root {
  /* Notion tokens */
  --primary:           #0075de;
  --primary-active:    #005bab;
  --on-primary:        #ffffff;
  --canvas:            #f6f5f4;
  --surface:           #ffffff;
  --ink:               #000000;
  --ink-secondary:     #31302e;
  --ink-muted:         #615d59;
  --ink-faint:         #a39e98;
  --hairline:          #e6e6e6;
  --hover-bg:          rgba(0,0,0,0.05);
  --code-bg:           rgba(0,0,0,0.06);

  /* Typography */
  --font: "Inter", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;

  /* Spacing (8px base) */
  --xxs: 4px; --xs: 8px; --sm: 12px; --md: 16px;
  --lg: 24px; --xl: 28px; --xxl: 32px;

  /* Radii */
  --r-xs: 4px; --r-sm: 5px; --r-md: 8px; --r-lg: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary:        #3b9eff;
    --primary-active: #2b8ae0;
    --canvas:         #191919;
    --surface:        #202020;
    --ink:            #ffffff;
    --ink-secondary:  #d0d0ce;
    --ink-muted:      #9b9a97;
    --ink-faint:      #6b6a67;
    --hairline:       #2e2e2e;
    --hover-bg:       rgba(255,255,255,0.08);
    --code-bg:        rgba(255,255,255,0.09);
  }
}

*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ─── Top Bar ─── */

#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--xs) var(--md);
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  min-height: 48px;
  padding-top: max(var(--xs), env(safe-area-inset-top));
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: var(--xs);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: color 150ms ease-out, background 150ms ease-out;
}

.icon-btn-sm { min-width: 36px; min-height: 36px; padding: var(--xxs); }

@media (hover: hover) {
  .icon-btn:hover { color: var(--ink); background: var(--hover-bg); }
}

/* ─── Focus Visible ─── */

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ─── Search Bar ─── */

.search-bar {
  display: grid;
  grid-template-rows: 1fr;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  transition: grid-template-rows 200ms ease-out;
}

.search-bar.collapsed { grid-template-rows: 0fr; }

.search-inner {
  display: flex;
  align-items: center;
  gap: var(--xxs);
  padding: var(--xs) var(--md);
  min-height: 0;
  overflow: hidden;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: var(--xxs) var(--xs);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xs);
  font-size: 15px;
  background: var(--canvas);
  color: var(--ink);
  outline: none;
  font-family: var(--font);
}

.search-bar input:focus { border-color: var(--primary); }
.search-bar input::placeholder { color: var(--ink-faint); }

/* ─── Topic Chips ─── */

.topic-chips {
  display: flex;
  gap: var(--xxs);
  padding: var(--xs) var(--md) var(--xxs);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  -webkit-overflow-scrolling: touch;
}

.topic-chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: var(--xxs) var(--sm);
  border-radius: var(--r-md);
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: background 150ms ease-out, color 150ms ease-out;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.topic-chips {
  mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent);
}

.chip-active {
  background: var(--ink);
  color: var(--surface);
}

@media (hover: hover) {
  .chip:not(.chip-active):hover {
    background: var(--hover-bg);
    color: var(--ink);
  }
}

/* ─── Stream (document flow, no cards) ─── */

.stream {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--lg) var(--md) calc(var(--xxl) + env(safe-area-inset-bottom));
}

/* Date headers */
.date-header {
  position: sticky;
  top: 48px;
  z-index: 50;
  background: var(--canvas);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  margin: var(--xl) 0 var(--sm);
  padding: var(--xxs) 0;
  border-bottom: 1px solid var(--hairline);
  letter-spacing: 0;
}

.date-header:first-child { margin-top: 0; }

/* Messages — document entries, not cards */
.msg {
  padding: var(--sm) 0;
  border-bottom: 1px solid var(--hairline);
  content-visibility: auto;
  contain-intrinsic-size: auto 100px;
}

.msg:last-child { border-bottom: none; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: var(--xxs);
  margin-bottom: var(--xxs);
  font-size: 13px;
  line-height: 1.33;
  flex-wrap: wrap;
}

.msg-channel {
  font-weight: 600;
  color: var(--ink-secondary);
}

.msg-dot {
  color: var(--ink-faint);
}

.msg-time {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.msg-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
}

@media (hover: hover) {
  .msg-link:hover { color: var(--primary-active); }
}

.msg-content {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink);
  word-break: break-word;
  text-wrap: pretty;
}

.msg-content a {
  color: var(--primary);
  text-decoration: none;
}

@media (hover: hover) {
  .msg-content a:hover { color: var(--primary-active); }
}

.msg-content b, .msg-content strong { font-weight: 700; }
.msg-content i, .msg-content em { font-style: italic; }

.msg-content blockquote {
  border-left: 3px solid var(--hairline);
  padding: var(--xxs) 0 var(--xxs) var(--sm);
  margin: var(--xs) 0;
  color: var(--ink-muted);
  font-size: 14px;
}

.msg-content br + br { margin-top: var(--xxs); }

/* ─── Filter Button ─── */

.msg-filter-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--r-xs);
  color: var(--ink-faint);
  transition: color 150ms ease-out, background 150ms ease-out;
  line-height: 1;
  margin-left: auto;
  display: flex;
  align-items: center;
}

@media (hover: hover) {
  .msg-filter-btn:hover { color: var(--ink); background: var(--hover-bg); }
}

.msg-filter-btn.filter-added {
  color: var(--primary);
  cursor: default;
}

.msg-filter-btn:disabled {
  cursor: default;
}

/* ─── Expand Toggle ─── */

.msg-expand-btn {
  display: inline-block;
  margin-top: var(--xxs);
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-family: var(--font);
}

@media (hover: hover) {
  .msg-expand-btn:hover { color: var(--primary-active); }
}

.msg-content.truncated {
  max-height: 8em;
  overflow: hidden;
  position: relative;
}

.msg-content.truncated::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3em;
  background: linear-gradient(transparent, var(--canvas));
  pointer-events: none;
}

/* ─── Sentinel ─── */

.sentinel {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sentinel-text {
  color: var(--ink-faint);
  font-size: 13px;
}

/* ─── Empty State ─── */

.empty-state {
  text-align: center;
  padding: var(--xxl) var(--md);
  color: var(--ink-muted);
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-bottom: var(--xxs);
}

.empty-sub {
  font-size: 14px;
  color: var(--ink-faint);
}

/* ─── Utilities ─── */

.hidden { display: none !important; }

/* ─── Digest Banner ─── */

.digest-banner {
  max-width: 680px;
  margin: 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  overflow: hidden;
  transition: max-height 300ms ease-out;
  max-height: 500px;
}

.digest-banner.collapsed {
  max-height: 44px;
}

.digest-banner-toggle {
  display: flex;
  align-items: center;
  gap: var(--xs);
  padding: var(--xs) var(--md);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-secondary);
  transition: background 150ms ease-out;
}

@media (hover: hover) {
  .digest-banner-toggle:hover {
    background: var(--hover-bg);
  }
}

.digest-banner-icon {
  font-size: 16px;
}

.digest-banner-text {
  flex: 1;
}

.digest-banner-arrow {
  font-size: 10px;
  color: var(--ink-faint);
  transition: transform 200ms ease-out;
}

.digest-banner:not(.collapsed) .digest-banner-arrow {
  transform: rotate(180deg);
}

.digest-content {
  padding: 0 var(--md) var(--md);
  max-height: 400px;
  overflow-y: auto;
}

.digest-content:empty {
  display: none;
}

.digest-item {
  margin-bottom: var(--md);
  padding-bottom: var(--md);
  border-bottom: 1px solid var(--hairline);
}

.digest-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.digest-item-header {
  display: flex;
  align-items: center;
  gap: var(--xs);
  margin-bottom: var(--xs);
  font-size: 13px;
  color: var(--ink-muted);
}

.digest-item-label {
  font-weight: 600;
  color: var(--ink-secondary);
}

.digest-item-date {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.digest-item-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  word-break: break-word;
}

.digest-item-body b, .digest-item-body strong { font-weight: 700; }
.digest-item-body i, .digest-item-body em { font-style: italic; }
.digest-item-body h2 { font-size: 17px; font-weight: 700; margin: 12px 0 6px; }
.digest-item-body h3 { font-size: 15px; font-weight: 600; margin: 10px 0 4px; }
.digest-item-body h4 { font-size: 14px; font-weight: 600; margin: 8px 0 4px; color: var(--ink-secondary); }
.digest-item-body code { font-family: monospace; font-size: 13px; background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }

.digest-loading {
  text-align: center;
  padding: var(--md);
  color: var(--ink-faint);
  font-size: 13px;
}

.digest-empty {
  text-align: center;
  padding: var(--md);
  color: var(--ink-faint);
  font-size: 13px;
}


/* ─── Skeleton Loading ─── */

.skeleton-msg {
  padding: var(--sm) 0;
  border-bottom: 1px solid var(--hairline);
}

.skeleton-line {
  height: 14px;
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--hairline) 25%, var(--canvas) 50%, var(--hairline) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: var(--xs);
}

.skeleton-line:last-child { margin-bottom: 0; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Reduced Motion ─── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Mobile ─── */

@media (max-width: 600px) {
  .stream {
    padding: var(--md) var(--sm) var(--xxl);
  }
}
