:root {
  color-scheme: light;
  --page: #f3f7f6;
  --surface: #ffffff;
  --surface-soft: #edf4f2;
  --surface-strong: #dceae7;
  --ink: #132421;
  --ink-soft: #405651;
  --muted: #6d7e79;
  --line: #d4dfdc;
  --line-strong: #aebfba;
  --accent: #087b72;
  --accent-hover: #05645d;
  --accent-soft: #d8efeb;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning: #966300;
  --warning-soft: #fff5d6;
  --success: #177252;
  --success-soft: #e1f4eb;
  --shadow: 0 18px 55px rgba(29, 63, 56, .10);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

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

button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(8, 123, 114, .24);
  outline-offset: 2px;
}

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 16px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .15s ease;
}

button:hover:not(:disabled) { border-color: #7d9690; background: var(--surface-soft); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .46; cursor: default; }
button.primary { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 700; }
button.primary:hover:not(:disabled) { border-color: var(--accent-hover); background: var(--accent-hover); }
button.secondary { background: transparent; color: var(--ink-soft); }
button.danger { border-color: #e6b9b5; background: var(--danger-soft); color: var(--danger); }
button.quiet-button, button.icon-button { min-height: 34px; padding: 0 11px; background: transparent; }
.full-button { width: 100%; min-height: 46px; }

.eyebrow, .section-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: clamp(22px, 5vw, 72px);
  background:
    linear-gradient(115deg, rgba(8, 123, 114, .08), transparent 48%),
    var(--page);
}

.auth-shell {
  position: relative;
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(330px, .75fr);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.auth-close {
  position: absolute;
  z-index: 2;
  top: 16px;
  right: 16px;
  min-height: 34px;
  border-color: transparent;
  background: rgba(255, 255, 255, .82);
  color: var(--ink-soft);
}

.auth-close:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface); }

.auth-intro {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(34px, 6vw, 74px);
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.auth-intro h1 { margin: 0; font-size: clamp(42px, 6vw, 68px); line-height: 1.08; letter-spacing: -.04em; }
.auth-lead { max-width: 480px; margin: 24px 0 0; font-size: clamp(19px, 2.2vw, 25px); line-height: 1.55; color: var(--ink-soft); }
.boundary-copy { max-width: 480px; margin: 34px 0 0; padding-top: 20px; border-top: 1px solid var(--line-strong); color: var(--muted); font-size: 13px; }

.auth-panel { align-self: center; padding: 38px clamp(28px, 4vw, 48px); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.auth-tab { min-height: 44px; border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 0 8px; }
.auth-tab:hover:not(:disabled) { border: 0; background: transparent; color: var(--ink); }
.auth-tab.active { box-shadow: inset 0 -2px var(--accent); color: var(--ink); font-weight: 750; }
.auth-form { display: grid; gap: 18px; }

.field { min-width: 0; }
.field label { display: block; margin-bottom: 6px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea, .case-index select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
}
.field input, .field select { height: 42px; }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.field input::placeholder, .field textarea::placeholder { color: #91a09c; }
.field input:disabled { background: var(--surface-soft); color: var(--ink-soft); cursor: not-allowed; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px rgba(8, 123, 114, .12); }
.field small, .selection-help { display: block; margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.form-message { min-height: 22px; margin: 0; color: var(--danger); font-size: 13px; }
.form-message.success { color: var(--success); }

.app-shell { min-height: 100vh; }
.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px clamp(18px, 4vw, 58px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); font-size: 11px; font-weight: 900; letter-spacing: .05em; }
.brand-lockup .eyebrow { margin: 0; font-size: 9px; }
.brand-lockup h1 { margin: 1px 0 0; font-size: 19px; line-height: 1.2; }
.account-area { display: flex; align-items: center; gap: 12px; }
.account-name { color: var(--ink-soft); font-size: 13px; }

.data-banner {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 13px clamp(18px, 4vw, 58px);
  background: #143b37;
  color: #fff;
}
.snapshot-block { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.snapshot-label, .snapshot-age { color: #bcd2cd; font-size: 12px; }
.snapshot-block strong { font-size: 16px; }
.capability-boundary { margin: 0; color: #dce9e6; font-size: 12px; text-align: center; }
.freshness { min-width: 84px; border-radius: 999px; padding: 5px 10px; text-align: center; font-size: 12px; font-weight: 800; }
.freshness-ok { background: #dff6ec; color: #0f6548; }
.freshness-due { background: var(--warning-soft); color: #765000; }
.freshness-stale { background: #ffe2de; color: #982117; }
.freshness-unknown { background: rgba(255, 255, 255, .14); color: #fff; }

.primary-nav { display: flex; gap: 30px; padding: 0 clamp(18px, 4vw, 58px); background: var(--surface); border-bottom: 1px solid var(--line); }
.nav-tab { min-height: 52px; border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 0; }
.nav-tab:hover:not(:disabled) { border: 0; background: transparent; color: var(--ink); }
.nav-tab.active { box-shadow: inset 0 -3px var(--accent); color: var(--ink); font-weight: 800; }

.main-view { width: 100%; }
.view-heading {
  min-height: 148px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  padding: 34px clamp(18px, 4vw, 58px) 26px;
  background: var(--surface);
}
.view-heading h2 { margin: 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.2; letter-spacing: -.025em; }
.view-heading p:not(.section-kicker) { max-width: 690px; margin: 10px 0 0; color: var(--muted); }

.stats-band { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); padding: 0 clamp(18px, 4vw, 58px); background: var(--surface-soft); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats-band div { min-height: 72px; padding: 13px 18px 11px 0; border-right: 1px solid var(--line); }
.stats-band div + div { padding-left: 18px; }
.stats-band div:last-child { border-right: 0; }
.stats-band span { display: block; color: var(--muted); font-size: 12px; }
.stats-band strong { display: block; margin-top: 3px; font-size: 21px; line-height: 1.25; }

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) 108px minmax(200px, 1.5fr) minmax(150px, 1fr) 136px 136px 104px auto;
  gap: 12px;
  align-items: end;
  padding: 20px clamp(18px, 4vw, 58px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.filter-actions { display: flex; gap: 8px; }

.results { padding: 24px clamp(18px, 4vw, 58px) 46px; }
.results-bar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.results-bar h3 { display: inline; margin: 0 12px 0 0; font-size: 18px; }
.results-bar span { color: var(--muted); font-size: 13px; }
.pager { display: flex; align-items: center; gap: 8px; }
.pager button { min-height: 34px; padding: 0 10px; }
.pager span { min-width: 60px; color: var(--ink); text-align: center; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { width: 100%; min-width: 1120px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; overflow-wrap: anywhere; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-soft); color: var(--ink-soft); font-size: 12px; font-weight: 800; }
tbody tr:hover { background: #f8fbfa; }
tbody tr:last-child td { border-bottom: 0; }
.date-column { width: 104px; }
.code-column { width: 78px; }
.company-column { width: 120px; }
.number-column { width: 145px; }
.category-column { width: 140px; }
.link-column { width: 160px; }
.title-button { display: inline; min-height: 0; border: 0; border-radius: 0; background: transparent; padding: 0; color: var(--ink); text-align: left; white-space: normal; line-height: 1.55; }
.title-button:hover { color: var(--accent); background: transparent; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.source-links { display: grid; justify-items: start; gap: 4px; }
.source-links a { line-height: 1.35; white-space: nowrap; }
.muted-value { color: var(--muted); }
.empty-row td { height: 170px; text-align: center; vertical-align: middle; color: var(--muted); }

.research-heading { min-height: 170px; background: var(--surface-soft); }
.workbench {
  min-height: 610px;
  display: grid;
  grid-template-columns: minmax(250px, 340px) minmax(0, 1fr);
  margin: 0 clamp(18px, 4vw, 58px) 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.case-index { border-right: 1px solid var(--line); background: #f8fbfa; }
.case-index-toolbar { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.case-index-toolbar h3 { margin: 0; font-size: 16px; }
.case-index-toolbar select { width: 118px; height: 36px; padding: 0 8px; }
.case-list { display: grid; }
.case-list-item { width: 100%; min-height: 100px; display: block; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 15px 16px; text-align: left; white-space: normal; }
.case-list-item:hover:not(:disabled) { border-color: var(--line); background: var(--surface-soft); }
.case-list-item.active { background: var(--surface); box-shadow: inset 3px 0 var(--accent); }
.case-list-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.case-list-title { display: block; color: var(--ink); font-weight: 750; line-height: 1.4; }
.case-list-company { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 2px 8px; background: var(--surface-strong); color: var(--ink-soft); font-size: 11px; font-weight: 800; }
.status-pill.preregistered { background: var(--accent-soft); color: var(--accent-hover); }
.status-pill.closed { background: #e8eaeb; color: #58615f; }
.case-workspace { min-width: 0; padding: clamp(24px, 4vw, 48px); }
.empty-workspace { max-width: 600px; margin: 120px auto 0; text-align: center; }
.empty-workspace h3 { margin: 0; font-size: 25px; }
.empty-workspace p:not(.section-kicker) { color: var(--muted); }
.empty-state { margin: 0; padding: 70px 24px; color: var(--muted); text-align: center; }
.empty-state.compact { padding: 40px 18px; font-size: 13px; }

.case-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.case-header h3 { margin: 5px 0 5px; font-size: clamp(22px, 3vw, 32px); line-height: 1.3; }
.case-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.case-section { padding: 25px 0; border-bottom: 1px solid var(--line); }
.case-section:last-child { border-bottom: 0; }
.case-section h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.case-statement { margin: 0; font-size: 18px; line-height: 1.7; white-space: pre-wrap; }
.case-section.falsifier { margin: 22px 0; padding: 22px; border: 1px solid #e6cfa2; border-radius: 10px; background: #fffaf0; }
.case-section.falsifier h4 { color: #805a0b; }
.source-plan { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.source-plan li { border: 1px solid var(--line); border-radius: 999px; background: var(--surface-soft); padding: 5px 10px; font-size: 12px; }
.case-action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.case-action-row .action-note { margin: 0 0 0 auto; color: var(--muted); font-size: 12px; }
.declaration-form, .closure-form, .edit-case-form { display: grid; gap: 14px; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-chip { position: relative; }
.choice-chip input { position: absolute; opacity: 0; pointer-events: none; }
.choice-chip span { display: block; border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 12px; cursor: pointer; }
.choice-chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); font-weight: 750; }
.choice-chip input:focus-visible + span { outline: 3px solid rgba(8, 123, 114, .24); outline-offset: 2px; }
.closure-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 28px; }
.closure-summary div { min-width: 0; }
.closure-summary dt { color: var(--muted); font-size: 12px; }
.closure-summary dd { margin: 4px 0 0; white-space: pre-wrap; }

.case-dialog { width: min(780px, calc(100vw - 28px)); max-height: min(880px, calc(100vh - 28px)); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; box-shadow: var(--shadow); }
.case-dialog::backdrop { background: rgba(16, 34, 30, .38); backdrop-filter: blur(2px); }
.case-dialog > form { display: flex; flex-direction: column; max-height: inherit; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 25px; }
.dialog-body { flex: 1; display: grid; gap: 18px; padding: 24px; overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); background: #fafcfc; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 18px; align-items: start; }
.emphasis-field textarea { border-left: 4px solid var(--accent); }
.falsification-field textarea { border-left: 4px solid #c28a19; background: #fffdf8; }
.company-picker { position: relative; }
.company-results { position: absolute; z-index: 5; top: 72px; left: 0; right: 0; max-height: 240px; overflow-y: auto; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: 0 12px 30px rgba(22, 50, 44, .15); }
.company-option { width: 100%; min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 8px 11px; text-align: left; }
.company-option:last-child { border-bottom: 0; }
.company-option small { color: var(--muted); }
.selection-help.selected { color: var(--success); font-weight: 700; }

.detail-drawer { position: fixed; inset: 0 0 0 auto; z-index: 30; width: min(580px, 94vw); background: var(--surface); border-left: 1px solid var(--line-strong); transform: translateX(102%); transition: transform .18s ease-out; overflow-y: auto; }
.detail-drawer.open { transform: translateX(0); }
.drawer-mask { position: fixed; inset: 0; z-index: 29; background: rgba(12, 30, 26, .34); }
.drawer-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0; font-size: 17px; }
.drawer-header button { min-height: 32px; }
.drawer-content { padding: 22px; }
.drawer-content h3 { margin: 0 0 18px; font-size: 19px; line-height: 1.55; }
.detail-list { margin: 0; }
.detail-list div { display: grid; grid-template-columns: 108px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.content-section { margin-top: 22px; }
.content-section h4 { margin: 0 0 10px; font-size: 14px; }
.content-preview { max-height: 42vh; overflow: auto; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #f7f9f8; color: #2c3f3a; font: 13px/1.7 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.toast { position: fixed; z-index: 50; right: 22px; bottom: 22px; max-width: min(420px, calc(100vw - 44px)); border: 1px solid var(--line-strong); border-radius: 10px; background: #153f3a; color: #fff; padding: 12px 16px; box-shadow: var(--shadow); }
.toast.error { background: #7d231c; }

@media (max-width: 1280px) {
  .filters { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
  .filter-actions { justify-content: flex-end; }
}

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-intro { min-height: auto; padding: 42px 34px; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-lead { margin-top: 16px; }
  .boundary-copy { margin-top: 24px; }
  .data-banner { grid-template-columns: 1fr auto; gap: 8px 18px; }
  .capability-boundary { grid-column: 1 / -1; grid-row: 2; text-align: left; }
  .workbench { grid-template-columns: 1fr; }
  .case-index { max-height: 330px; overflow-y: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .case-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-list-item { border-right: 1px solid var(--line); }
}

@media (max-width: 680px) {
  body { font-size: 14px; }
  .auth-gate { padding: 12px; }
  .auth-shell { border-radius: 12px; }
  .auth-intro { padding: 32px 24px; }
  .auth-intro h1 { font-size: 42px; }
  .auth-panel { padding: 28px 22px; }
  .app-header { align-items: flex-start; }
  .account-area { gap: 4px; }
  .account-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .data-banner { grid-template-columns: 1fr; }
  .freshness { justify-self: start; }
  .primary-nav { gap: 24px; overflow-x: auto; }
  .nav-tab { flex: 0 0 auto; }
  .view-heading { min-height: 150px; align-items: flex-start; flex-direction: column; padding-top: 28px; }
  .research-heading button { width: 100%; }
  .stats-band { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .stats-band div:nth-child(2) { border-right: 0; }
  .stats-band div:nth-child(3), .stats-band div:nth-child(4) { border-top: 1px solid var(--line); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .company-field, .title-field, .number-field, .filter-actions { grid-column: 1 / -1; }
  .filter-actions button { flex: 1; }
  .results-bar { align-items: flex-start; flex-direction: column; }
  .pager { width: 100%; justify-content: space-between; }
  .workbench { margin-left: 0; margin-right: 0; border-left: 0; border-right: 0; border-radius: 0; }
  .case-list { grid-template-columns: 1fr; }
  .case-workspace { padding: 26px 20px; }
  .empty-workspace { margin-top: 70px; }
  .case-header { flex-direction: column; }
  .case-header .status-pill { align-self: flex-start; }
  .case-action-row { align-items: stretch; flex-direction: column; }
  .case-action-row .action-note { margin-left: 0; }
  .form-grid, .closure-summary { grid-template-columns: 1fr; }
  .dialog-header, .dialog-body, .dialog-actions { padding-left: 18px; padding-right: 18px; }
  .dialog-actions button { flex: 1; }
}

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