/* ════════════════════════════════════════════════════════════════
   Stock News Dashboard — v2 Design System
   Finance-reader aesthetic · Mobile-first · No window.prompt
   ════════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  --serif: "Source Serif Pro", "Iowan Old Style", "Apple Garamond", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;

  --bg:          hsl(45 25% 97%);
  --surface:     hsl(0 0% 100%);
  --ink:         hsl(220 15% 13%);
  --ink-soft:    hsl(220 10% 38%);
  --rule:        hsl(220 15% 92%);
  --accent:      hsl(212 92% 45%);
  --accent-soft: hsl(212 90% 95%);
  --tag:         hsl(45 70% 35%);
  --tag-bg:      hsl(45 85% 93%);
  --danger:      hsl(0 70% 45%);
  --danger-bg:   hsl(0 90% 96%);

  --card-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 12px rgb(0 0 0 / .03);
  --header-h: 60px;
  --chips-h: 44px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Toast Banner ────────────────────────────────────────────── */
.banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: var(--ink);
  color: hsl(0 0% 100%);
  font-size: 13px;
  font-family: var(--sans);
  padding: 10px 20px 10px 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgb(0 0 0 / .18);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
}
.banner-close {
  background: none;
  border: none;
  color: hsl(0 0% 70%);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.banner-close:hover { color: white; }

/* ── Sticky Header ───────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 1px 4px rgb(0 0 0 / .05);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: var(--header-h);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.site-logo {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.site-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.date-input {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--bg);
  cursor: pointer;
  /* hide on mobile — space is precious */
  display: none;
}

/* Show date input on desktop */
@media (min-width: 481px) {
  .date-input { display: block; }
}

/* ── Icon Buttons ────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: hsl(0 0% 96%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: hsl(0 0% 92%); }
.icon-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.icon-btn--primary:hover { background: hsl(212 92% 38%); border-color: hsl(212 92% 38%); }

/* On mobile: icon only, no label text */
.btn-label { display: none; }
@media (min-width: 481px) {
  .btn-label { display: inline; }
}

/* On mobile, make icon buttons square 44x44 */
@media (max-width: 480px) {
  .icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    border-radius: 10px;
  }
}

/* ── Chip / Tag Filter Row ───────────────────────────────────── */
.chip-row {
  border-top: 1px solid var(--rule);
  height: var(--chips-h);
  overflow: hidden;
}

.chip-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }

.chip-tag {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: hsl(0 0% 95%);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.chip-tag:hover { background: hsl(0 0% 90%); color: var(--ink); text-decoration: none; }
.chip-tag.active { background: var(--ink); color: hsl(0 0% 100%); }

/* ── Main Feed ───────────────────────────────────────────────── */
.feed {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

@media (min-width: 769px) {
  .feed { padding: 24px 24px 80px; }
}

/* ── Stock Card ──────────────────────────────────────────────── */
.stock-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--card-shadow);
}

@media (min-width: 769px) {
  .stock-card {
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
  }
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0;
}

.card-head-left {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  min-width: 0;
}

.ticker-name {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
  line-height: 1.2;
}

@media (min-width: 769px) {
  .ticker-name { font-size: 22px; }
}

.company-name {
  font-size: 13px;
  color: var(--ink-soft);
  font-family: var(--sans);
}

.news-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1px 6px;
}

.tags-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.tag-chip {
  display: inline-block;
  padding: 1px 8px;
  background: var(--tag-bg);
  color: var(--tag);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.card-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: hsl(0 0% 97%);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.action-btn:hover { background: hsl(0 0% 92%); color: var(--ink); }
.action-btn--danger { color: var(--danger); }
.action-btn--danger:hover { background: var(--danger-bg); border-color: hsl(0 70% 85%); }

/* Hide text label on mobile, show icon only */
.action-label { display: none; }
@media (min-width: 481px) {
  .action-label { display: inline; }
  .action-btn { height: 34px; }
}

/* Ensure 44px tap area on mobile */
@media (max-width: 480px) {
  .action-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    border-radius: 8px;
  }
}

/* ── News List ───────────────────────────────────────────────── */
.news-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.news-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.news-item:last-child { border-bottom: none; padding-bottom: 0; }
.news-item:first-child { padding-top: 12px; }

.news-zh {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.5;
}

@media (min-width: 769px) {
  .news-zh { font-size: 16px; }
}

.news-en {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
  line-height: 1.45;
}

@media (min-width: 769px) {
  .news-en { font-size: 13px; }
}

.news-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: hsl(0 0% 55%);
}

.meta-dot { color: hsl(0 0% 75%); }
.meta-link { color: var(--accent); }
.meta-link:hover { text-decoration: underline; }

/* ── Empty States ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--ink-soft);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

.empty-card {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 12px 0 0;
  margin: 0;
}

/* ── Modals ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / .35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgb(0 0 0 / .16);
  overflow: hidden;
}

.modal-box--wide { max-width: 640px; }

@media (max-width: 480px) {
  .modal-box { border-radius: 12px; }
  .modal-box--wide { max-height: 85vh; overflow-y: auto; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 0;
}

.modal-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: hsl(0 0% 94%);
  border-radius: 50%;
  font-size: 18px;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.modal-close:hover { background: hsl(0 0% 88%); color: var(--ink); }

.modal-body {
  padding: 16px 24px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 24px 20px;
}

/* ── Form Fields ─────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}
.field-optional { color: var(--ink-soft); font-weight: 400; }

.field-input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 6px 0 0;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--ghost {
  background: hsl(0 0% 96%);
  border-color: var(--rule);
  color: var(--ink);
}
.btn--ghost:hover { background: hsl(0 0% 91%); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn--primary:hover { background: hsl(212 92% 38%); border-color: hsl(212 92% 38%); }

/* ── Deepdive Content ────────────────────────────────────────── */
.deepdive-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 14px;
  padding: 12px 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brief {
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink);
  margin: 4px 0;
}

.raw-details {
  margin-top: 16px;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
}
.raw-details summary {
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.raw-details summary:hover { color: var(--ink); }
.raw-details pre {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 11px;
  overflow-x: auto;
  margin-top: 8px;
  color: var(--ink-soft);
}

/* ── Error ───────────────────────────────────────────────────── */
.err {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

/* ── Modal Transitions (Alpine) ──────────────────────────────── */
.modal-enter { transition: opacity 0.18s ease, transform 0.18s ease; }
.modal-enter-start { opacity: 0; }
.modal-enter-end { opacity: 1; }
.modal-leave { transition: opacity 0.15s ease; }
.modal-leave-start { opacity: 1; }
.modal-leave-end { opacity: 0; }
