/* DART 디자인 시스템 — DESIGN.md v1. Toss-inspired.
   토큰 변경 시 DESIGN.md Decisions Log 갱신 필수. */

:root {
  /* surface */
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --surface-2: #F2F4F6;
  --border: #F2F4F6;
  --border-strong: #E5E8EB;

  /* text */
  --text: #191F28;
  --text-secondary: #4E5968;
  --text-muted: #6B7684;
  --text-faint: #8B95A1;

  /* accent — CTA / focus / active filter only */
  --accent: #3182F6;
  --accent-fg: #FFFFFF;

  /* semantic labels (한국 증시 컨벤션: 빨강=호재, 파랑=악재) */
  --label-up-bg: #FEF1F1;
  --label-up-fg: #C2331F;
  --label-down-bg: #EDF3FF;
  --label-down-fg: #1B64DA;
  --label-neutral-bg: #F2F4F6;
  --label-neutral-fg: #4E5968;

  /* market chip accent — 선택 시에만 사용 (비선택은 중립 그레이) */
  --chip-kospi-fg: #B45309;
  --chip-kosdaq-fg: #15803D;

  /* spacing (8px scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* radius */
  --radius-label: 6px;
  --radius-button: 12px;
  --radius-card: 16px;
  --radius-chip: 999px;

  /* elevation */
  --shadow-card: 0 2px 8px rgba(17, 24, 39, 0.04);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171C;
    --surface: #1F1F24;
    --surface-2: #2A2A30;
    --border: #2A2A30;
    --border-strong: #3A3A40;

    --text: #F2F4F6;
    --text-secondary: #C9CDD2;
    --text-muted: #A5AAB0;
    --text-faint: #6B7684;

    --accent: #4592FF;
    --accent-fg: #17171C;

    --label-up-bg: #2A1414;
    --label-up-fg: #FF8A8A;
    --label-down-bg: #14142A;
    --label-down-fg: #8AB4FF;
    --label-neutral-bg: #2A2A30;
    --label-neutral-fg: #C9CDD2;

    --chip-kospi-fg: #FCB960;
    --chip-kosdaq-fg: #6EE7B7;

    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 스크린리더 전용 */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* 키보드 focus — accent ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

body {
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-feature-settings: "tnum" on;
  letter-spacing: -0.005em;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-1) var(--space-4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  letter-spacing: -0.02em;
  line-height: 1;
}

.brand-mark {
  display: block;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--text-secondary);
  border-radius: var(--radius-button);
  text-decoration: none;
  flex-shrink: 0;
  transition: background-color 0.15s ease-out, color 0.15s ease-out;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.96);
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-3);
}

.filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  min-width: 32px;
  flex-shrink: 0;
}

.chip {
  background: var(--surface-2);
  border: 0;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-chip);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.15s ease-out, color 0.15s ease-out, transform 0.1s ease-out;
}

.chip:hover {
  background: var(--border-strong);
}

.chip:active {
  transform: scale(0.97);
}

.chip.active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

/* market / label chips — 비선택은 초연한 tint(color-mix 8%), 선택은 saturated bg + 흰 텍스트.
   text는 기본 chip 규칙(--text-secondary) 유지 — 위계 뭉개지 않으면서 식별 힌트만. */
.chip.kospi:not(.active)  { background: color-mix(in srgb, var(--chip-kospi-fg)  5%, var(--surface)); }
.chip.kosdaq:not(.active) { background: color-mix(in srgb, var(--chip-kosdaq-fg) 5%, var(--surface)); }
.chip.up:not(.active)     { background: color-mix(in srgb, var(--label-up-fg)    5%, var(--surface)); }
.chip.down:not(.active)   { background: color-mix(in srgb, var(--label-down-fg)  5%, var(--surface)); }

.chip.kospi.active  { background: var(--chip-kospi-fg);  color: #fff; }
.chip.kosdaq.active { background: var(--chip-kosdaq-fg); color: #fff; }
.chip.up.active     { background: var(--label-up-fg);    color: #fff; }
.chip.down.active   { background: var(--label-down-fg);  color: #fff; }

.chip.clear {
  color: var(--text-muted);
}

.updated {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  margin-bottom: var(--space-2);
  padding: var(--space-3) var(--space-2) var(--space-3) 0;
  min-height: 44px;
  box-sizing: border-box;
}

.updated:hover { color: var(--text-muted); }
.updated:active { transform: scale(0.98); }

.updated.spinning svg { animation: updated-spin 0.4s linear; }
@keyframes updated-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  margin-bottom: var(--space-2);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s ease-out, transform 0.1s ease-out;
}

.card:hover { border-color: var(--border-strong); }
.card:active { transform: scale(0.99); }

/* share button — 피드 카드·디테일 섹션 우측 상단. 알약(pill) 모양 텍스트
   버튼. 기본 중립 그레이, hover/focus/copied에서 Toss Blue. */
.share-btn {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  background: var(--surface-2);
  color: var(--text-muted);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  z-index: 2;
  transition: background-color 0.15s ease-out, color 0.15s ease-out, transform 0.1s ease-out;
}

.share-btn:hover,
.share-btn:focus-visible,
.share-btn.copied {
  background: var(--accent);
  color: var(--accent-fg);
  outline: none;
}

.share-btn:active { transform: scale(0.94); }

.detail .share-btn {
  top: var(--space-4);
  right: var(--space-4);
}

.card a {
  display: block;
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
}

.label {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-label);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: var(--space-2);
  letter-spacing: 0.02em;
}

.label.호재 { background: var(--label-up-bg); color: var(--label-up-fg); }
.label.악재 { background: var(--label-down-bg); color: var(--label-down-fg); }
.label.중립 { background: var(--label-neutral-bg); color: var(--label-neutral-fg); }

/* feed card pills — 필터 chip과 동일한 곡선 + 5% tint + saturated text */
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-chip);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--text-secondary);
}

.pill.up      { background: color-mix(in srgb, var(--label-up-fg)    8%, var(--surface)); color: var(--label-up-fg); }
.pill.down    { background: color-mix(in srgb, var(--label-down-fg)  8%, var(--surface)); color: var(--label-down-fg); }
.pill.neutral { background: var(--label-neutral-bg);                                       color: var(--label-neutral-fg); }
.pill.kospi   { background: color-mix(in srgb, var(--chip-kospi-fg)  8%, var(--surface)); color: var(--chip-kospi-fg); }
.pill.kosdaq  { background: color-mix(in srgb, var(--chip-kosdaq-fg) 8%, var(--surface)); color: var(--chip-kosdaq-fg); }
/* 재평가 뱃지 — 본문 수신 후 라벨이 title 기반에서 body 기반으로 갱신된 케이스.
   accent 남용 피하고 neutral tone 안에서 border 로만 구분. */
.pill.reeval  { background: var(--border-strong);                                           color: var(--text-muted); }

.card h2.corp {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card .headline {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-secondary);
  letter-spacing: -0.005em;
  margin-top: 2px;
}

.meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: var(--space-2);
  font-variant-numeric: tabular-nums;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}

.empty {
  color: var(--text-muted);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  font-size: 14px;
  line-height: 1.7;
}

.empty .muted {
  color: var(--text-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.empty a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.empty a:hover { text-decoration: underline; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  padding: var(--space-3) var(--space-2) var(--space-3) 0;
  margin-bottom: var(--space-2);
  min-height: 44px;
  box-sizing: border-box;
  transition: color 0.15s ease-out, transform 0.1s ease-out;
}

.back-link:hover { color: var(--text); }
.back-link:active { transform: scale(0.98); }

/* detail page — 피드 카드와 동일한 프레임으로 "한 공시 = 한 카드" 일관 */
.detail {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

.detail h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

/* 헤더 블록: pills → h1 → headline → meta 를 8px 간격으로 타이트하게 묶고,
   summary와는 32px(--space-6)로 크게 떼어 식별/본문 경계를 공백만으로 표시. */
.detail .headline {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
  line-height: 1.45;
  margin-top: var(--space-2);
}

.detail .meta {
  margin-top: var(--space-2);
}

.detail .summary {
  margin-top: var(--space-6);
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-5);
  background: var(--surface-2);
  color: var(--accent);
  border-radius: var(--radius-button);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s ease-out, transform 0.1s ease-out;
}

.cta:hover { background: var(--border-strong); }
.cta:active { transform: scale(0.99); }

/* forms */
.search-form {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.search-form input {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  font-size: 16px;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-button);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease-out;
}

.search-form input:focus {
  border-color: var(--accent);
  outline: none;
}

.search-form button {
  padding: var(--space-3) var(--space-5);
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: var(--radius-button);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
  transition: background-color 0.15s ease-out, transform 0.1s ease-out, filter 0.15s ease-out;
}

.search-form button:hover { filter: brightness(1.05); }
.search-form button:active { transform: scale(0.98); }

.load-more {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-button);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease-out, color 0.15s ease-out, transform 0.1s ease-out;
}

.load-more:hover { background: var(--surface-2); color: var(--text); }
.load-more:active { transform: scale(0.99); }
.load-more:disabled { opacity: 0.5; cursor: progress; }
.load-more .count { color: var(--text-muted); font-weight: 500; margin-left: 4px; }

.scroll-top {
  position: fixed;
  right: var(--space-4);
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out, background-color 0.15s ease-out, color 0.15s ease-out;
  z-index: 20;
}

.scroll-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top:hover { background: var(--surface-2); color: var(--text); }
.scroll-top:active { transform: scale(0.94); }

footer {
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
}

footer .disclaimer { margin: 0 0 var(--space-2); }
footer p.copyright { margin: 0; }

/* responsive */
@media (max-width: 640px) {
  main { padding: var(--space-3); }
  .card h2 { font-size: 15px; }
  .detail h1 { font-size: 22px; }
}

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