@layer reset, tokens, base, header, home, archive, analyst, viz, dialog, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { min-height: 100%; }
  body, h1, h2, h3, p, ol, fieldset { margin: 0; }
  ol { padding: 0; }
  button, textarea { font: inherit; }
  button { border: 0; cursor: pointer; }
  img, svg { display: block; }
}

@layer tokens {
  :root {
    --font-brand: "Space Grotesk", "Noto Sans KR", sans-serif;
    --font: "Noto Sans KR", system-ui, sans-serif;
    --signal: #0b6e6a;
    --signal-deep: #085652;
    --signal-soft: #d9efed;
    --ember: #e8a317;
    --ink: #12161c;
    --radius: 20px;
    --shadow: 0 16px 40px rgba(18, 22, 28, .07);
  }
  html[data-theme="light"] {
    color-scheme: light;
    --bg: #eef1f4;
    --surface: #fbfcfd;
    --surface-alt: #f3f6f8;
    --text: #12161c;
    --subtext: #66707c;
    --border: #d5dde6;
    --header-bg: rgba(251, 252, 253, .82);
    --dim: rgba(18, 22, 28, .48);
    --blue: var(--signal);
    --blue-strong: var(--signal-deep);
    --blue-soft: var(--signal-soft);
    --blue-line: #b7ddd9;
    --gray-50: #f6f8fa;
    --gray-100: #eef1f4;
    --gray-200: #d5dde6;
    --gray-300: #c0cad6;
    --gray-500: #7a8490;
    --gray-700: #3d4754;
    --gray-900: #12161c;
    --mint: var(--signal-soft);
    --purple: #e7edf4;
  }
  html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101418;
    --surface: #1a2027;
    --surface-alt: #222a33;
    --text: #f2f5f7;
    --subtext: #a7b1bc;
    --border: #2f3a46;
    --header-bg: rgba(16, 20, 24, .88);
    --dim: rgba(0, 0, 0, .62);
    --blue: #2bb5ad;
    --blue-strong: #1f938d;
    --blue-soft: #1b3d3b;
    --blue-line: #2f5f5b;
    --gray-50: #1a2027;
    --gray-100: #222a33;
    --gray-200: #2f3a46;
    --gray-300: #3d4a58;
    --gray-500: #8b97a4;
    --gray-700: #d5dde6;
    --gray-900: #f2f5f7;
    --mint: #1b3d3b;
    --purple: #2a3440;
    --shadow: 0 16px 40px rgba(0, 0, 0, .28);
    --signal: #2bb5ad;
    --signal-deep: #1f938d;
    --signal-soft: #1b3d3b;
    --ink: #f2f5f7;
  }
}

@layer base {
  html { background: var(--bg); }
  @view-transition { navigation: auto; }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: .28s;
    animation-timing-function: cubic-bezier(.22, 1, .36, 1);
  }
  body {
    color: var(--text);
    font-family: var(--font);
    font-size: clamp(.875rem, .82rem + .2vw, .9375rem);
    line-height: 1.5;
    letter-spacing: -.015em;
    background:
      radial-gradient(900px 420px at 90% -8%, color-mix(in srgb, var(--signal-soft) 80%, transparent) 0%, transparent 52%),
      radial-gradient(700px 380px at -5% 30%, #d7e0ea 0%, transparent 48%),
      linear-gradient(180deg, #f3f5f7, var(--bg));
    background-attachment: fixed;
    transition: background .2s, color .2s;
  }
  html[data-theme="dark"] body {
    background:
      radial-gradient(900px 420px at 90% -8%, rgba(43, 181, 173, .12) 0%, transparent 52%),
      radial-gradient(700px 380px at -5% 30%, rgba(80, 110, 140, .12) 0%, transparent 48%),
      var(--bg);
  }
  button { color: inherit; }
  :focus-visible { outline: 3px solid color-mix(in srgb, var(--signal) 45%, transparent); outline-offset: 2px; }
  .skip-link { position: fixed; z-index: 100; top: -4rem; left: 1rem; padding: .7rem 1rem; border-radius: 10px; background: var(--signal); color: #fff; font-weight: 700; }
  .skip-link:focus { top: 1rem; }
  .sr-only { position: absolute; overflow: hidden; width: 1px; height: 1px; padding: 0; margin: -1px; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  .view[hidden] { display: none; }
  .view-active { animation: rise .45s cubic-bezier(.22, 1, .36, 1) both; }
  #overviewView { view-transition-name: view-home; }
  #archiveView { view-transition-name: view-archive; }
  #analystView { view-transition-name: view-analyst; }
  #vizView { view-transition-name: view-viz; }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  @keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
  @keyframes title-in {
    from { opacity: 0; transform: translateY(18px); filter: blur(4px); }
    to { opacity: 1; transform: none; filter: none; }
  }
  @keyframes kicker-in {
    from { opacity: 0; transform: translateY(8px) scale(.96); }
    to { opacity: 1; transform: none; }
  }
  @keyframes signal-pulse {
    0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ember) 25%, transparent); }
    50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ember) 12%, transparent); }
  }
  @keyframes press {
    from { transform: scale(.985); }
    to { transform: none; }
  }
  svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
}

@layer header {
  .app-header { position: sticky; z-index: 20; top: 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); background: var(--header-bg); backdrop-filter: blur(14px); }
  .header-inner { display: flex; align-items: center; justify-content: space-between; width: min(980px, calc(100% - 36px)); height: 72px; margin: 0 auto; gap: 12px; }
  .brand { display: inline-flex; align-items: center; gap: 12px; min-width: 0; color: var(--text); text-decoration: none; }
  .brand-avatar {
    width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
    outline: 2px solid var(--surface); outline-offset: 2px;
    box-shadow: 0 10px 24px rgba(18, 22, 28, .14);
    animation: float 4.5s ease-in-out infinite;
  }
  .brand-text { display: grid; gap: 2px; }
  .brand-text strong { font-family: var(--font-brand); font-size: 1.08rem; font-weight: 700; letter-spacing: -.045em; line-height: 1; }
  .brand-text small { color: var(--subtext); font-size: .68rem; font-weight: 500; }
  .desktop-nav {
    display: flex; align-items: center; gap: 4px; padding: 5px;
    border: 1px solid var(--border); border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 80%, transparent);
  }
  .nav-link {
    min-height: 34px; padding: 0 14px; border-radius: 999px; background: transparent;
    color: var(--subtext); font-size: .78rem; font-weight: 600; transition: color .18s, background .18s;
  }
  .nav-link:hover { color: var(--text); }
  .nav-link.is-active { background: var(--ink); color: #fff; }
  html[data-theme="dark"] .nav-link.is-active { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
  .nav-link b {
    display: inline-grid; place-items: center; min-width: 17px; height: 17px; margin-left: 4px;
    border-radius: 9px; background: color-mix(in srgb, currentColor 18%, transparent); font-size: .58rem;
  }
  .header-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
  .theme-toggle { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: transparent; color: var(--subtext); }
  .theme-toggle:hover { background: var(--gray-100); color: var(--text); }
  .theme-toggle svg { width: 17px; height: 17px; }
  .moon-icon { display: none; }
  html[data-theme="dark"] .sun-icon { display: none; }
  html[data-theme="dark"] .moon-icon { display: block; }
  .mobile-nav { display: none; }
}

@layer home {
  .app-main { width: min(980px, calc(100% - 36px)); min-height: calc(100vh - 72px); margin: 0 auto; padding: 22px 0 72px; }
  .page-heading { margin-bottom: 22px; }
  .page-heading.compact { margin-bottom: 18px; }
  .page-heading h1, .stage h1 {
    font-family: var(--font-brand); font-weight: 700; letter-spacing: -.055em; line-height: 1.08; color: var(--text);
  }
  .page-heading h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem); }
  .lede { margin-top: 12px; max-width: 34rem; color: var(--subtext); font-size: clamp(.88rem, .82rem + .25vw, .95rem); line-height: 1.65; }
  .kicker {
    display: inline-flex; align-items: center; gap: 8px; width: fit-content;
    padding: 6px 11px; border-radius: 999px; background: var(--signal-soft); color: var(--signal-deep);
    font-size: .72rem; font-weight: 700;
    animation: kicker-in .55s cubic-bezier(.22, 1, .36, 1) both;
  }
  .kicker::before {
    content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ember);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ember) 25%, transparent);
    animation: signal-pulse 2.2s ease-in-out infinite;
  }
  .kicker.soft { background: var(--gray-100); color: var(--subtext); }
  .kicker.soft::before { background: var(--signal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 20%, transparent); animation: none; }

  .stage {
    position: relative; overflow: hidden; padding: 36px 36px 30px;
    border: 1px solid var(--border); border-radius: 28px;
    background: var(--surface);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 24px;
    animation: rise .55s .05s cubic-bezier(.22, 1, .36, 1) both;
  }
  .stage-copy { position: relative; z-index: 1; min-width: 0; }
  .stage-portrait-wrap {
    /* 바깥 링: border-radius를 따르는 box-shadow (outline은 사각형으로 남는 브라우저가 있음) */
    width: clamp(140px, 22vw, 220px);
    height: clamp(140px, 22vw, 220px);
    border-radius: 50%;
    flex: 0 0 auto;
    align-self: center;
    isolation: isolate;
    box-shadow:
      0 0 0 4px color-mix(in srgb, var(--surface) 88%, transparent),
      0 18px 40px rgba(18, 22, 28, .14),
      0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent);
    animation: float 5s ease-in-out infinite, rise .6s .12s both;
  }
  .stage-portrait {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 18%;
    /* JPEG 사각 배경을 원으로 강제 클리핑 (다크모드에서도 유지) */
    overflow: hidden;
    clip-path: circle(50% at 50% 50%);
    -webkit-clip-path: circle(50% at 50% 50%);
    transform: translateZ(0);
  }
  html[data-theme="dark"] .stage-portrait-wrap {
    box-shadow:
      0 0 0 4px color-mix(in srgb, var(--border) 55%, #fff 8%),
      0 18px 40px rgba(0, 0, 0, .35),
      0 0 0 1px color-mix(in srgb, var(--border) 80%, transparent);
  }
  .stage h1, .hero-title {
    margin-top: 16px; max-width: 13ch;
    font-size: clamp(2rem, 1.35rem + 2.8vw, 3.2rem);
    animation: title-in .7s .08s cubic-bezier(.22, 1, .36, 1) both;
  }
  .stage .lede { animation: rise .55s .16s both; }
  .stage .cta-row { animation: rise .55s .22s both; }
  .stage[data-state="running"] {
    background: linear-gradient(115deg, color-mix(in srgb, var(--signal-soft) 55%, var(--surface)) 0%, var(--surface) 70%);
  }
  .stage[data-state="running"] .kicker::before { animation: signal-pulse 1s ease-in-out infinite; }
  .stage[data-state="running"] .stage-portrait-wrap { opacity: .92; }
  .cta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 24px; }
  .cta-meta { color: var(--subtext); font-size: .68rem; width: 100%; }

  .blue-button, .secondary-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 48px; padding: 0 18px; border-radius: 14px; font-size: .86rem; font-weight: 700;
    white-space: nowrap; transition: background .18s, transform .18s, box-shadow .18s, border-color .18s;
  }
  .blue-button { background: var(--signal); color: #fff; box-shadow: 0 12px 28px color-mix(in srgb, var(--signal) 28%, transparent); }
  .blue-button:hover:not(:disabled) { background: var(--signal-deep); transform: translateY(-2px); }
  .blue-button:active:not(:disabled), .secondary-button:active:not(:disabled) { animation: press .18s ease; }
  .blue-button:disabled, .secondary-button:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
  .blue-button svg { width: 16px; height: 16px; stroke-width: 2.1; }
  .secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
  .secondary-button:hover:not(:disabled) { background: var(--gray-100); }

  .collection-progress { display: grid; gap: 8px; margin-top: 18px; animation: rise .35s ease both; }
  .collection-progress[hidden] { display: none; }
  .progress-track { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--gray-200) 86%, transparent); overflow: hidden; }
  .progress-bar {
    height: 100%; width: 0%; border-radius: 99px;
    background: linear-gradient(90deg, var(--signal), var(--signal-deep), var(--signal));
    background-size: 200% 100%;
    transition: width .45s cubic-bezier(.22, 1, .36, 1);
  }
  .progress-bar[data-animated="true"] { animation: progress-shine 1.1s linear infinite; }
  @keyframes progress-shine { from { background-position: 0% 0; } to { background-position: 200% 0; } }
  .progress-meta { display: flex; align-items: center; gap: 8px; font-size: .72rem; }
  .progress-meta strong { color: var(--signal); font-weight: 800; font-variant-numeric: tabular-nums; }
  .progress-meta span { color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .progress-meta small { margin-left: auto; color: var(--subtext); font-size: .62rem; }

  .summary-grid, .rail {
    display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 12px; margin-top: 16px;
    animation: rise .6s .12s cubic-bezier(.22, 1, .36, 1) both;
  }
  .tile, .summary-card {
    padding: 20px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface);
    text-align: left; box-shadow: none;
    transition: transform .22s cubic-bezier(.22, 1, .36, 1), border-color .2s, box-shadow .22s;
  }
  .tile:hover, .summary-link:hover {
    transform: translateY(-4px);
    border-color: color-mix(in srgb, var(--signal) 40%, var(--border));
    box-shadow: 0 14px 30px rgba(18, 22, 28, .07);
  }
  .tile:active, .summary-link:active { transform: translateY(-1px) scale(.99); }
  .tile .label, .summary-card .label { color: var(--subtext); font-size: .72rem; font-weight: 600; }
  .tile .value, .summary-card .value {
    margin-top: 10px; font-family: var(--font-brand); font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem); font-weight: 700; letter-spacing: -.04em; color: var(--text);
    font-variant-numeric: tabular-nums;
  }
  .tile .value-sm, .summary-card .value-sm { font-size: 1.05rem; }
  .tile .hint, .summary-card .hint { margin-top: 6px; color: var(--subtext); font-size: .78rem; line-height: 1.4; }
  .tile.signal { background: linear-gradient(165deg, var(--signal-soft), var(--surface)); }
  .tile.signal .value { color: var(--signal-deep); }
  .summary-link { width: 100%; cursor: pointer; }

  .content-section, .strip { margin-top: 28px; display: grid; gap: 10px; animation: rise .65s .18s cubic-bezier(.22, 1, .36, 1) both; }
  .strip h2, .section-title h2 {
    font-family: var(--font-brand); font-size: clamp(.95rem, .9rem + .3vw, 1.05rem); letter-spacing: -.03em; color: var(--text);
  }
  .quick-grid { display: grid; gap: 10px; }
  .quick-card.row, .row {
    display: flex; align-items: center; gap: 14px; width: 100%; min-height: 0; padding: 16px 18px;
    border-radius: 16px; border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    text-align: left; transition: background .18s, transform .22s cubic-bezier(.22, 1, .36, 1), border-color .18s, box-shadow .22s;
  }
  .quick-card.row:hover {
    background: var(--surface); transform: translateX(6px);
    border-color: color-mix(in srgb, var(--signal) 30%, var(--border));
    box-shadow: 0 10px 24px rgba(18, 22, 28, .05);
  }
  .quick-card.row:active { transform: translateX(2px) scale(.995); }
  .mark, .quick-icon.mark {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    font-family: var(--font-brand); font-weight: 700; font-size: .85rem; flex: 0 0 auto;
    transition: transform .22s cubic-bezier(.22, 1, .36, 1);
  }
  .quick-card.row:hover .mark { transform: scale(1.06); }
  .mark.a, .soft-blue { background: var(--signal-soft); color: var(--signal-deep); }
  .mark.b, .soft-purple { background: #e7edf4; color: #2c4458; }
  .mark.c, .soft-mint { background: #f3ead0; color: #8a6a12; }
  .quick-card > span:nth-child(2) { display: grid; gap: 3px; min-width: 0; }
  .quick-card strong { color: var(--text); font-size: .88rem; letter-spacing: -.02em; }
  .quick-card small { color: var(--subtext); font-size: .74rem; }
  .quick-card > b { margin-left: auto; color: var(--subtext); font-size: 1.1rem; font-weight: 500; transition: transform .2s, color .2s; }
  .quick-card.row:hover > b { transform: translateX(3px); color: var(--signal); }
}

@layer archive {
  .archive-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    margin-bottom: 18px; padding: 14px 16px; border-radius: 16px;
    border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 80%, transparent);
  }
  .archive-toolbar > p { color: var(--subtext); font-size: .76rem; }
  .archive-toolbar > div { display: flex; gap: 8px; }
  .archive-toolbar .blue-button, .archive-toolbar .secondary-button { min-height: 40px; font-size: .78rem; }
  .archive-list { display: grid; gap: 10px; }
  .archive-item {
    overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    opacity: 0; transform: translateY(12px);
    transition: opacity .45s cubic-bezier(.22, 1, .36, 1), transform .45s cubic-bezier(.22, 1, .36, 1), border-color .2s, box-shadow .2s;
  }
  .archive-item.is-visible { opacity: 1; transform: none; }
  .archive-item:nth-child(2).is-visible { transition-delay: .05s; }
  .archive-item:nth-child(3).is-visible { transition-delay: .1s; }
  .archive-item:nth-child(4).is-visible { transition-delay: .15s; }
  .archive-item summary {
    display: grid; grid-template-columns: auto minmax(0,1fr) auto auto; align-items: center; gap: 12px;
    min-height: 72px; padding: 12px 16px; list-style: none; cursor: pointer;
  }
  .archive-item summary::-webkit-details-marker { display: none; }
  .archive-item summary:hover { background: var(--surface-alt); }
  .archive-folder { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; background: var(--signal-soft); color: var(--signal-deep); }
  .archive-folder svg { width: 21px; height: 21px; }
  .archive-name { display: grid; min-width: 0; gap: 3px; }
  .archive-name strong { overflow: hidden; color: var(--text); font-size: .84rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
  .archive-name small { color: var(--subtext); font-size: .7rem; }
  .download-link { padding: 7px 10px; border-radius: 8px; color: var(--signal); font-size: .72rem; font-weight: 700; text-decoration: none; }
  .download-link:hover { background: var(--signal-soft); }
  .chevron { color: var(--gray-500); font-size: 1.1rem; transition: transform .2s; }
  .archive-item[open] .chevron { transform: rotate(180deg); }
  .document-list { margin: 0 16px 14px 66px; border-top: 1px solid var(--border); list-style: none; }
  .document-list li { display: grid; grid-template-columns: 8px minmax(0,1fr) 28px; align-items: center; gap: 8px; min-height: 38px; border-bottom: 1px solid var(--gray-100); }
  .file-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--gray-300); }
  .document-list p { overflow: hidden; color: var(--gray-700); font-size: .74rem; text-overflow: ellipsis; white-space: nowrap; }
  .document-list em { justify-self: end; color: var(--gray-500); font-size: .58rem; font-style: normal; }
  .empty-state {
    display: grid; place-items: center; min-height: 320px; padding: 38px;
    border: 1px solid var(--border); border-radius: 24px; background: var(--surface); text-align: center;
  }
  .empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 16px; border-radius: 22px; background: var(--signal-soft); color: var(--signal-deep); }
  .empty-icon svg { width: 30px; height: 30px; }
  .empty-state h2 { font-family: var(--font-brand); color: var(--text); font-size: 1.2rem; letter-spacing: -.04em; }
  .empty-state p { margin: 7px 0 18px; color: var(--subtext); font-size: .8rem; }
}

@layer analyst {
  .analyst-layout {
    display: grid; grid-template-columns: 280px minmax(0,1fr); min-height: 510px;
    border: 1px solid var(--border); border-radius: 24px; background: var(--surface); overflow: hidden;
  }
  .suggestion-panel { display: flex; flex-direction: column; padding: 22px; border-right: 1px solid var(--border); background: var(--surface-alt); }
  .suggestion-panel h2 { font-family: var(--font-brand); color: var(--text); font-size: .95rem; letter-spacing: -.03em; }
  .suggestion-list { display: grid; gap: 8px; margin-top: 16px; }
  .suggestion-chip {
    display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 10px 12px;
    border-radius: 14px; background: var(--surface); color: var(--gray-700); text-align: left; font-size: .72rem; line-height: 1.45;
    border: 1px solid transparent; transition: border-color .18s, background .18s, color .18s;
  }
  .suggestion-chip:hover { background: var(--signal-soft); color: var(--signal-deep); border-color: var(--blue-line); }
  .suggestion-chip b { margin-left: 8px; color: var(--signal); font-size: 1.15rem; font-weight: 400; }
  .text-button { align-self: flex-start; margin-top: auto; padding: 8px 0; background: transparent; color: var(--subtext); font-size: .72rem; font-weight: 600; }
  .text-button:hover { color: var(--signal); }
  .chat-panel { display: flex; flex-direction: column; min-width: 0; }
  .chat-messages { display: flex; flex: 1; flex-direction: column; gap: 14px; overflow-y: auto; padding: 24px; list-style: none; scroll-behavior: smooth; }
  .message { display: flex; align-items: flex-start; gap: 9px; max-width: 80%; }
  .message-user { align-self: flex-end; flex-direction: row-reverse; }
  .message-stamp {
    display: grid; flex: 0 0 auto; place-items: center; width: 32px; height: 32px; border-radius: 50%;
    background: #8b95a1; color: #fff; font-family: var(--font-brand); font-size: .58rem; font-weight: 700;
    white-space: pre-line; text-align: center; line-height: 1.1;
  }
  .message-stamp-avatar {
    object-fit: cover;
    object-position: center 18%;
    background: transparent;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--border) 80%, transparent);
  }
  html[data-theme="dark"] .message-stamp-avatar {
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--border) 90%, #fff 8%);
  }
  .message-body { padding: 11px 13px; border-radius: 14px; border-top-left-radius: 4px; background: var(--gray-100); }
  .message-user .message-body { border-top-left-radius: 14px; border-top-right-radius: 4px; background: var(--signal-soft); }
  .message-body p { color: var(--text); font-size: .78rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
  .message-body small { display: block; margin-top: 6px; color: var(--subtext); font-size: .62rem; }
  .message-actions { display: flex; justify-content: flex-end; margin-top: 7px; }
  .copy-answer { padding: 0; background: transparent; color: var(--subtext); font-size: .6rem; font-weight: 600; }
  .copy-answer:hover { color: var(--signal); }
  .typing-body { display: flex; align-items: center; gap: 4px; min-height: 42px; }
  .typing-body i { width: 5px; height: 5px; border-radius: 50%; background: var(--signal); animation: typing .8s infinite alternate; }
  .typing-body i:nth-child(2) { animation-delay: .14s; }
  .typing-body i:nth-child(3) { animation-delay: .28s; }
  @keyframes typing { to { transform: translateY(-4px); opacity: .35; } }
  .composer { display: flex; align-items: center; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }
  .composer-field {
    display: flex; align-items: center; flex: 1; min-width: 0; min-height: 48px;
    padding: 10px 14px; border: 1px solid var(--border); border-radius: 14px;
    background: var(--surface); transition: border-color .18s, box-shadow .18s;
  }
  .composer-field:focus-within { border-color: var(--signal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 18%, transparent); }
  #chatInput {
    display: block; width: 100%; min-height: 28px; max-height: 116px; padding: 0; resize: none; border: 0; outline: 0;
    background: transparent; color: var(--text); font-family: var(--font); font-size: .86rem; line-height: 1.45;
    overflow-y: auto;
  }
  #chatInput::placeholder { color: var(--gray-500); }
  .send-button { min-width: 82px; min-height: 48px; align-self: center; }
  .disclaimer { margin-top: 12px; color: var(--subtext); font-size: .66rem; text-align: center; }
}

@layer viz {
  .viz-shell {
    display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px;
    min-height: 560px;
  }
  .viz-controls {
    display: flex; flex-direction: column; gap: 12px;
    padding: 18px; border: 1px solid var(--border); border-radius: 22px;
    background: var(--surface); box-shadow: var(--shadow);
  }
  .viz-field { display: grid; gap: 6px; }
  .viz-field > span { color: var(--subtext); font-size: .68rem; font-weight: 600; }
  .viz-field select, .viz-field input[type="search"], .viz-field input[type="text"], .viz-field input[type="date"] {
    width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface-alt); color: var(--text); font-size: .82rem;
  }
  #vizSeries {
    min-height: 280px; height: 320px; padding: 8px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface-alt); color: var(--text); font-size: .78rem; line-height: 1.45;
  }
  #vizSeries option { padding: 6px 8px; border-radius: 8px; }
  .viz-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .viz-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .viz-presets .secondary-button { min-height: 36px; padding: 0; font-size: .72rem; }
  .viz-presets .viz-preset.is-active {
    background: var(--signal-soft);
    border-color: color-mix(in srgb, var(--signal) 45%, var(--border));
    color: var(--signal-deep);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--signal) 22%, transparent);
  }
  html[data-theme="dark"] .viz-presets .viz-preset.is-active {
    background: color-mix(in srgb, var(--signal) 22%, var(--surface-alt));
    border-color: color-mix(in srgb, var(--signal) 50%, var(--border));
    color: color-mix(in srgb, var(--signal) 70%, #fff);
  }
  .viz-check {
    display: inline-flex; align-items: center; gap: 8px; width: fit-content;
    color: var(--text); font-size: .78rem; font-weight: 600; cursor: pointer; user-select: none;
  }
  .viz-check input {
    width: 16px; height: 16px; margin: 0; accent-color: var(--signal); cursor: pointer;
  }
  .viz-controls .blue-button, .viz-controls .secondary-button { width: 100%; }
  .viz-hint, .viz-usage, .viz-meta, .viz-status { color: var(--subtext); font-size: .68rem; line-height: 1.5; }
  .viz-usage { margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--border); }
  .viz-chart-panel {
    display: flex; flex-direction: column; gap: 12px;
    padding: 18px; border: 1px solid var(--border); border-radius: 22px;
    background: var(--surface); box-shadow: var(--shadow); min-width: 0;
  }
  .viz-chart-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
  .viz-chart-head h2 {
    font-family: var(--font-brand); font-size: 1.15rem; letter-spacing: -.03em; color: var(--text);
  }
  .viz-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
  .viz-legend span {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px;
    background: var(--gray-100); color: var(--subtext); font-size: .65rem; font-weight: 600;
  }
  .viz-legend i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
  .viz-canvas-wrap { position: relative; flex: 1; min-height: 360px; }
  .viz-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
}

@layer dialog {
  .scope-dialog {
    width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 22px;
    background: var(--surface); color: var(--text); box-shadow: 0 18px 60px rgba(18, 22, 28, .26);
  }
  .scope-dialog::backdrop { background: var(--dim); backdrop-filter: blur(3px); }
  .scope-sheet { padding: 24px; }
  .scope-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
  .scope-header h2 { font-family: var(--font-brand); color: var(--text); font-size: 1.18rem; letter-spacing: -.04em; }
  .scope-header p { margin-top: 5px; color: var(--subtext); font-size: .77rem; }
  .close-button { display: grid; flex: 0 0 auto; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--gray-100); color: var(--gray-700); font-size: 1.25rem; font-weight: 400; }
  .close-button:hover { background: var(--gray-200); }
  .category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 0; margin-top: 22px; border: 0; }
  .category-grid label {
    display: flex; align-items: center; gap: 10px; min-height: 72px; padding: 13px;
    border: 1px solid var(--border); border-radius: 14px; background: var(--surface); cursor: pointer;
    transition: border-color .18s, background .18s;
  }
  .category-grid label:hover { background: var(--surface-alt); }
  .category-grid label:has(input:checked) { border-color: var(--signal); background: var(--signal-soft); }
  .category-grid input { position: absolute; opacity: 0; }
  .category-check {
    display: grid; flex: 0 0 auto; place-items: center; width: 20px; height: 20px;
    border: 1.5px solid var(--gray-300); border-radius: 50%; color: transparent; font-size: .68rem; font-weight: 800;
  }
  .category-grid input:checked + .category-check { border-color: var(--signal); background: var(--signal); color: #fff; }
  .category-grid label > span:last-child { display: grid; gap: 2px; }
  .category-grid strong { color: var(--text); font-size: .8rem; }
  .category-grid small { color: var(--subtext); font-size: .67rem; }
  .scope-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; }
  .scope-actions > div { display: flex; gap: 8px; }
  .scope-actions .text-button { margin: 0; }
  .toast-region { position: fixed; z-index: 50; right: 20px; bottom: 20px; display: grid; gap: 8px; width: min(330px, calc(100% - 40px)); }
  .toast {
    display: flex; align-items: flex-start; gap: 9px; padding: 14px; border-radius: 14px;
    background: var(--ink); box-shadow: 0 8px 22px rgba(18, 22, 28, .18); color: #fff; animation: rise .2s ease both;
  }
  .toast.is-error { background: #c43b3b; }
  .toast i { flex: 0 0 auto; width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: #6ee7b7; }
  .toast p { flex: 1; font-size: .75rem; line-height: 1.55; }
  .toast button { padding: 0; background: transparent; color: rgba(255,255,255,.75); font-size: 1.05rem; }
}

@layer responsive {
  @media (max-width: 750px) {
    body { padding-bottom: 70px; overflow-x: clip; }
    .header-inner, .app-main { width: calc(100% - 28px); max-width: 100%; }
    #analystView, #vizView, #archiveView, #overviewView { min-width: 0; max-width: 100%; }
    .header-inner { height: 64px; }
    .desktop-nav { display: none; }
    .brand-text small { display: none; }
    .brand-avatar { width: 38px; height: 38px; border-radius: 50%; }
    .app-main { min-width: 0; min-height: calc(100vh - 64px); padding: 16px 0 36px; }
    .stage {
      grid-template-columns: 1fr;
      padding: 26px 20px;
      border-radius: 22px;
      background: var(--surface);
    }
    .stage-portrait-wrap {
      width: 112px; height: 112px;
      justify-self: start;
      order: -1;
      margin-bottom: 4px;
    }
    .stage h1 { font-size: 1.85rem; max-width: none; }
    .cta-row { display: grid; grid-template-columns: 1fr 1fr; }
    .cta-row .blue-button, .cta-row .secondary-button { width: 100%; min-height: 44px; }
    .cta-meta { grid-column: 1 / -1; }
    .rail, .summary-grid { grid-template-columns: 1fr; gap: 9px; }
    .mobile-nav {
      position: fixed; z-index: 25; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4,1fr);
      height: 65px; padding: 5px 10px env(safe-area-inset-bottom); border-top: 1px solid var(--border);
      background: var(--header-bg); backdrop-filter: blur(16px);
    }
    .mobile-nav-item { display: grid; place-items: center; align-content: center; gap: 3px; background: transparent; color: var(--gray-500); font-size: .6rem; }
    .mobile-nav-item svg { width: 20px; height: 20px; }
    .mobile-nav-item.is-active { color: var(--signal); font-weight: 700; }
    .archive-toolbar { align-items: stretch; flex-direction: column; }
    .archive-toolbar > div { display: grid; grid-template-columns: 1fr 1.4fr; }
    .archive-toolbar .blue-button, .archive-toolbar .secondary-button { width: 100%; }
    .archive-item summary { grid-template-columns: auto minmax(0,1fr) auto; }
    .download-link { display: none; }
    .document-list { margin: 0 12px 12px 56px; }
    .analyst-layout {
      grid-template-columns: minmax(0, 1fr);
      width: 100%;
      max-width: 100%;
      min-width: 0;
      min-height: calc(100vh - 230px);
    }
    .viz-shell { grid-template-columns: 1fr; min-width: 0; max-width: 100%; }
    .viz-canvas-wrap { min-height: 280px; }
    .suggestion-panel,
    .chat-panel {
      min-width: 0;
      max-width: 100%;
    }
    .suggestion-panel { padding: 16px; border-right: 0; border-bottom: 1px solid var(--border); }
    .suggestion-list {
      display: flex;
      gap: 7px;
      margin-top: 11px;
      max-width: 100%;
      overflow-x: auto;
      overscroll-behavior-x: contain;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: thin;
    }
    .suggestion-chip { flex: 0 0 min(205px, 72vw); }
    .suggestion-panel .text-button { display: none; }
    .chat-messages { padding: 16px; min-width: 0; }
    .message { max-width: min(92%, 100%); min-width: 0; }
    .message-body { min-width: 0; overflow-wrap: anywhere; }
    .composer { min-width: 0; max-width: 100%; padding: 10px; }
    .send-button { min-width: 44px; width: 44px; padding: 0; }
    .send-button span { display: none; }
    .category-grid { grid-template-columns: 1fr; }
    .scope-actions { flex-direction: column; align-items: stretch; }
    .scope-actions > div { display: grid; grid-template-columns: 1fr 1.55fr; }
    .toast-region { right: 16px; bottom: 78px; width: calc(100% - 32px); }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      scroll-behavior: auto !important; animation-duration: .01ms !important;
      animation-iteration-count: 1 !important; transition-duration: .01ms !important;
    }
    .archive-item { opacity: 1; transform: none; }
    .kicker::before { animation: none !important; }
    ::view-transition-old(root),
    ::view-transition-new(root) { animation: none !important; }
  }
}
