/* 文献ハブ — cafe デザインシステム準拠 */

:root {
  /* color tokens */
  --primary: #5D4432;
  --primary-hover: #4a3627;
  --primary-soft: #EFE8E1;
  --secondary: #E9E3DD;
  --success: #16A34A;
  --warning: #D97706;
  --danger: #DC2626;
  --surface: #F9F7F5;
  --surface-raised: #FFFFFF;
  --text: #3E2B1E;
  --text-muted: #7A6555;
  --border: #E2D9D0;
  --border-strong: #CFC2B5;

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

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(62, 43, 30, .06), 0 8px 24px rgba(62, 43, 30, .06);
  --font: "Poppins", "Noto Sans JP", -apple-system, "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

/* display:flex / grid を持つ要素でも hidden 属性を効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-weight: 400;
  line-height: 1.75;
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 var(--sp-6); }

.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;
}

/* ---------------------------------------------------------------- header */

.site-header {
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-5); padding-top: var(--sp-5); padding-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: var(--sp-4); }

.brand-mark {
  font-size: 28px; line-height: 1; color: var(--primary);
  background: var(--primary-soft);
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 auto;
}

.brand h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: .01em; }
.brand-sub { margin: 0; font-size: 13px; color: var(--text-muted); }

.user-box { display: flex; align-items: center; gap: var(--sp-4); }
.user-name { font-size: 14px; color: var(--text-muted); }

/* ---------------------------------------------------------------- layout */

main.wrap { padding-top: var(--sp-7); padding-bottom: var(--sp-8); }

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--sp-6);
  margin-bottom: var(--sp-6);
}

.card h2 { margin: 0 0 var(--sp-2); font-size: 18px; font-weight: 600; }

.login-card { max-width: 520px; margin-inline: auto; text-align: center; }
.login-card .btn { margin-top: var(--sp-5); }

.muted { color: var(--text-muted); font-size: 14px; margin: 0; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-6) 0 var(--sp-8);
  background: var(--surface-raised);
}
.site-footer p { font-size: 13px; line-height: 1.8; }
.site-footer a { color: var(--primary); }

/* ------------------------------------------------------------------ tabs */

.tabs {
  display: flex; gap: var(--sp-2);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp-6);
}

.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  font: inherit; font-weight: 500; font-size: 15px;
  color: var(--text-muted);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { color: var(--text); background: var(--primary-soft); }
.tab:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------------------------------------------------------------- fields */

.field { margin-bottom: var(--sp-5); }
.field:last-child { margin-bottom: 0; }

.field > label, .field > legend, fieldset.field legend {
  display: block; font-size: 14px; font-weight: 500;
  margin-bottom: var(--sp-3); padding: 0;
}

fieldset.field { border: 0; margin-inline: 0; padding: 0; }

input[type="text"], input[type="number"], select {
  width: 100%; font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-4);
  min-height: 44px;
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

input::placeholder { color: #A6968A; }

.hint { font-size: 13px; color: var(--text-muted); margin: var(--sp-3) 0 0; }

.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-5); }

.check-row { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-6); }

.check {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: 15px; cursor: pointer;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.check:hover { border-color: var(--border-strong); }
.check .muted { font-size: 12px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); flex: 0 0 auto; }

.inline-field {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: 14px; color: var(--text-muted); white-space: nowrap;
}
.inline-field select { width: auto; min-width: 170px; min-height: 40px; padding: var(--sp-3) var(--sp-4); }

/* --------------------------------------------------------------- buttons */

.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 500; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-3);
  min-height: 44px; padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text);
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--secondary); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-quiet { border-color: transparent; background: var(--primary-soft); color: var(--primary); }
.btn-quiet:hover { background: var(--secondary); }

.btn-lg { font-size: 15px; padding: var(--sp-4) var(--sp-7); min-height: 48px; }

.btn-danger-quiet { border-color: transparent; background: none; color: var(--danger); }
.btn-danger-quiet:hover { background: #FDECEC; }

.actions { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }

.status { font-size: 14px; color: var(--text-muted); }

/* ---------------------------------------------------------------- alerts */

.alert {
  border-radius: var(--radius-sm);
  padding: var(--sp-4) var(--sp-5);
  font-size: 14px;
  margin: 0 0 var(--sp-4);
  border: 1px solid transparent;
  line-height: 1.7;
}
.alert-danger  { background: #FDECEC; border-color: #F5C6C6; color: #8B1D1D; }
.alert-warning { background: #FEF3E2; border-color: #F5D9A8; color: #7C4A06; }
.alert:last-child { margin-bottom: 0; }

/* -------------------------------------------------------------- toolbars */

.toolbar {
  display: flex; align-items: center; gap: var(--sp-4);
  flex-wrap: wrap;
  padding: var(--sp-4) 0;
  border-top: 1px solid var(--border);
}
.toolbar .spacer { flex: 1 1 auto; }

.results-head { margin-bottom: var(--sp-4); }

/* -------------------------------------------------------------- progress */

.progress { padding: var(--sp-4) 0; border-top: 1px solid var(--border); }
.progress-bar {
  height: 8px; border-radius: 999px; background: var(--secondary);
  overflow: hidden; margin-bottom: var(--sp-3);
}
.progress-bar span {
  display: block; height: 100%; width: 0%;
  background: var(--primary);
  transition: width .25s ease;
}

/* ---------------------------------------------------------------- tables */

.table-scroll { overflow-x: auto; border-top: 1px solid var(--border); }

table.papers { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 860px; }

table.papers th {
  text-align: left; font-weight: 600; font-size: 13px; color: var(--text-muted);
  padding: var(--sp-4) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  position: sticky; top: 0; z-index: 1;
}

table.papers td {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.papers tr:hover td { background: #FCFAF8; }

.col-check { width: 44px; }
.col-year  { width: 64px; }
.col-venue { width: 200px; }
.col-src   { width: 130px; }
.col-abs   { width: 84px; }
.col-sets  { width: 220px; }

.paper-title { font-weight: 500; color: var(--text); text-decoration: none; line-height: 1.6; }
.paper-title:hover { color: var(--primary); text-decoration: underline; }
.paper-authors { font-size: 12px; color: var(--text-muted); margin: var(--sp-2) 0 0; }

table.papers input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 500;
  padding: 2px var(--sp-3); border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
  margin: 0 var(--sp-2) var(--sp-2) 0; white-space: nowrap;
}
.badge-ok   { background: #E6F6EC; color: #146C35; }
.badge-none { background: var(--secondary); color: var(--text-muted); }
.badge-warn { background: #FEF3E2; color: #7C4A06; }

/* 要約は本文行の直下に、表の幅いっぱいで置く */
tr.summary-row td { padding-top: 0; border-bottom: 1px solid var(--border); }
/* 論文行と要約行を1つの塊に見せる（間の罫線を消す） */
table.papers tr:has(+ tr.summary-row) td { border-bottom: 0; }
table.papers tr.summary-row:hover td { background: transparent; }

.summary-cell {
  max-width: 72ch;
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px; line-height: 1.9;
  white-space: pre-wrap;
}
.summary-cell strong { color: var(--primary); }
.summary-cell.is-error { border-left-color: var(--warning); color: #7C4A06; }

.empty { padding: var(--sp-7); text-align: center; color: var(--text-muted); font-size: 14px; }

/* ------------------------------------------------------------ sets list */

.sets-list { display: grid; gap: var(--sp-4); margin-bottom: var(--sp-5); }

.set-row {
  display: flex; align-items: flex-start; gap: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface);
}
.set-row:hover { border-color: var(--border-strong); }
.set-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); margin-top: 4px; }
.set-row .set-body { flex: 1 1 auto; min-width: 0; }
.set-name { font-weight: 500; font-size: 15px; margin: 0; }
.set-meta { font-size: 12.5px; color: var(--text-muted); margin: var(--sp-2) 0 0; }

/* ------------------------------------------------------------------ venn */

.venn-box { display: flex; flex-wrap: wrap; gap: var(--sp-5); margin-bottom: var(--sp-5); }

.venn-stat {
  flex: 1 1 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-5);
  background: var(--surface);
}
.venn-stat .n { font-size: 26px; font-weight: 600; color: var(--primary); line-height: 1.2; }
.venn-stat .l { font-size: 13px; color: var(--text-muted); margin-top: var(--sp-2); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 760px) {
  .wrap { padding-inline: var(--sp-5); }
  .field-row { grid-template-columns: 1fr; }
  .header-inner { align-items: flex-start; }
  .tab { padding-inline: var(--sp-4); font-size: 14px; }
  .toolbar .spacer { flex-basis: 100%; height: 0; }
}
