/* Ergonomics Research — Web UI v1
   One-tone navy / blue-gray palette, no accent colour. Mobile first; on wide screens
   the app stays a centred single column like a phone app. */

:root {
  --navy: #243B5A;          /* Deep Navy */
  --slate: #587089;         /* Slate Blue */
  --pale: #EEF3F6;          /* Pale Blue Gray */
  --paper: #F7F6F3;         /* Off White (page) */
  --white: #FFFFFF;
  --ink: #27313D;           /* Charcoal (body text) */
  --muted: #6F7782;         /* Secondary Gray (on white only) */
  --line: #D9E1E8;          /* hairlines: a lighter step of the same blue-gray */
  --navy-soft: #DCE5ED;     /* active chip background: a lighter step of navy */

  --radius: 16px;
  --radius-sm: 10px;
  --col: 640px;
  --tap: 44px;
  --shadow: 0 1px 2px rgba(36, 59, 90, .06), 0 4px 16px rgba(36, 59, 90, .06);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, ul { margin: 0; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon { width: 1.1em; height: 1.1em; flex: none; }

:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 20;
  background: var(--navy); color: var(--white); padding: 10px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

/* --- App shell ------------------------------------------------------------------------ */

.app {
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}
main:focus { outline: none; }

.app-header {
  background: var(--navy);
  color: var(--white);
  padding: calc(20px + env(safe-area-inset-top)) 20px 20px;
}
.app-header__title { font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; line-height: 1.3; }
.app-header__lead { margin-top: 4px; font-size: .9rem; color: #DCE5ED; }

.search { position: relative; margin-top: 16px; }
.search__icon { position: absolute; left: 14px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--slate); pointer-events: none; }
.search__input {
  width: 100%; min-height: 48px; padding: 10px 14px 10px 44px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--white); color: var(--ink);
  font-size: 1rem;                       /* ≥16px: no zoom on iOS focus */
}
.search__input::placeholder { color: var(--muted); }
.search__input:focus-visible { outline: 3px solid #9FB3C8; outline-offset: 2px; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px 6px;
}
.counts { display: flex; flex-wrap: wrap; column-gap: 14px; font-size: .85rem; color: var(--slate); line-height: 1.5; }
.counts strong { color: var(--navy); font-weight: 700; margin: 0 1px; }

.active-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 0; }
.active-chips:empty { display: none; }

/* --- Buttons & chips ------------------------------------------------------------------ */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--navy); background: var(--white); color: var(--navy);
  font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none;
}
.button--primary { background: var(--navy); color: var(--white); }
.button--secondary { background: var(--white); color: var(--navy); }
.button--toolbar { flex: none; padding: 8px 14px; font-size: .85rem; }
.button--icon { min-width: var(--tap); padding: 0; border-color: transparent; font-size: 1.4rem; font-weight: 400; }
.button--back { border-color: transparent; background: transparent; padding-left: 8px; font-size: 1rem; }
.button:disabled { opacity: .6; cursor: default; }
@media (hover: hover) {
  .button:hover:not(:disabled) { background: var(--pale); }
  .button--primary:hover:not(:disabled) { background: #1C2F48; }
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; font-size: .78rem; font-weight: 600; line-height: 1.4;
  padding: 4px 10px;
}
.chip--domain { background: var(--navy); color: var(--white); }
.chip--outline { background: var(--white); color: var(--navy); border: 1px dashed var(--slate); font-weight: 500; }
.domain-note { font-size: .74rem; font-weight: 600; color: var(--slate); align-self: center; margin-right: 2px; }
.chip--tag { background: var(--white); color: var(--slate); border: 1px solid var(--line); }
.chip--active {
  min-height: 36px; padding: 6px 12px; cursor: pointer;
  background: var(--navy-soft); color: var(--navy); border: 1px solid var(--navy);
}

/* --- Cards ---------------------------------------------------------------------------- */

.cards { display: grid; gap: 14px; padding: 12px 16px 0; }

.card {
  position: relative;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  display: grid; gap: 8px;
}
.card:focus-within { outline: 3px solid var(--navy); outline-offset: 2px; }
.card__link { color: inherit; text-decoration: none; }
.card__link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card__link:focus-visible { outline: none; }
@media (hover: hover) { .card:hover { border-color: var(--slate); } }

.card__domain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.card__title { font-size: 1.08rem; font-weight: 700; line-height: 1.5; color: var(--ink); }
.card__original { font-size: .82rem; line-height: 1.5; color: var(--muted); }
.card__meta { font-size: .8rem; color: var(--muted); }
.card__tags { display: flex; flex-wrap: wrap; gap: 6px; }

.status-line {
  font-size: .78rem; color: var(--slate); line-height: 1.5;
  padding-left: 10px; border-left: 3px solid var(--line);
}

.summary {
  background: var(--pale); border-radius: var(--radius-sm); padding: 12px 14px;
}
.summary__heading {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px;
  font-size: .82rem; font-weight: 700; color: var(--navy); margin-bottom: 6px;
}
.ai-label { font-size: .7rem; font-weight: 600; color: var(--slate); }
.summary__list { list-style: none; padding: 0; display: grid; gap: 6px; }
.summary__list li { position: relative; padding-left: 16px; font-size: .9rem; line-height: 1.65; }
.summary__list li::before {
  content: ""; position: absolute; left: 2px; top: .68em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--slate);
}
.summary-fallback {
  font-size: .82rem; color: var(--slate); background: var(--pale);
  border-radius: var(--radius-sm); padding: 10px 14px;
}

.metrics { display: flex; gap: 22px; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 2px; }
.metrics__item { display: grid; gap: 0; }
.metrics__name { font-size: .7rem; font-weight: 600; color: var(--slate); letter-spacing: .03em; }
.metrics__value { font-size: 1.05rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.metrics__value--none { color: var(--muted); font-weight: 500; }
.metrics__source { font-size: .7rem; color: var(--muted); }

.retracted {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--navy); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: .88rem; font-weight: 700; color: var(--navy); background: var(--white);
}

/* --- States --------------------------------------------------------------------------- */

.loading { display: grid; gap: 14px; padding: 12px 16px 0; }
.card--skeleton { gap: 10px; box-shadow: none; }
.sk { display: block; border-radius: 8px; background: linear-gradient(90deg, var(--pale) 0%, #F6F9FB 50%, var(--pale) 100%); background-size: 200% 100%; animation: sk 1.4s ease-in-out infinite; }
.sk--chip { width: 96px; height: 22px; border-radius: 999px; }
.sk--title { width: 88%; height: 22px; }
.sk--line { width: 60%; height: 14px; }
.sk--short { width: 40%; }
.sk--box { width: 100%; height: 92px; border-radius: var(--radius-sm); }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

.state { display: grid; justify-items: center; gap: 16px; text-align: center; padding: 48px 24px; }
.state__message { color: var(--ink); font-size: .95rem; }
.more { display: flex; justify-content: center; padding: 20px 16px 0; }

/* --- Detail --------------------------------------------------------------------------- */

.detail-bar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(247, 246, 243, .94); backdrop-filter: blur(8px);
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  border-bottom: 1px solid var(--line);
}
.detail-main { padding: 16px; }
.detail-main .loading { padding: 0; }
.detail-main .state { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.detail { display: grid; gap: 12px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 18px; }
.detail__title { font-size: 1.3rem; line-height: 1.5; font-weight: 700; color: var(--ink); }
.detail__title:focus { outline: none; }
.detail__original { font-size: .9rem; color: var(--muted); line-height: 1.55; }

.section { display: grid; gap: 10px; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--line); }
.section__heading { font-size: .95rem; font-weight: 700; color: var(--navy); }

.overview { display: grid; gap: 12px; }
.overview__item dt { font-size: .78rem; font-weight: 700; color: var(--slate); }
.overview__item dd { font-size: .94rem; line-height: 1.75; }

.rows { display: grid; gap: 0; }
.rows__item { display: grid; grid-template-columns: 7.5em 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--pale); }
.rows__item:last-child { border-bottom: 0; }
.rows__item dt { font-size: .8rem; color: var(--slate); font-weight: 600; }
.rows__item dd { font-size: .88rem; overflow-wrap: anywhere; }

.links { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.links__item {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 8px 16px;
  border: 1px solid var(--navy); border-radius: 999px; color: var(--navy); font-weight: 600; font-size: .88rem; text-decoration: none;
}
@media (hover: hover) { .links__item:hover { background: var(--pale); } }

.notice {
  margin-top: 8px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--pale); font-size: .78rem; line-height: 1.7; color: var(--ink);
}
.notice__label { font-weight: 700; color: var(--navy); margin-bottom: 2px; }

/* --- Bottom sheet --------------------------------------------------------------------- */

.sheet {
  width: 100%; max-width: var(--col); max-height: 86vh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--white); color: var(--ink);
}
.sheet::backdrop { background: rgba(39, 49, 61, .45); }
.sheet[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet__form { display: flex; flex-direction: column; max-height: 86vh; }
.sheet__header { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px 20px; }
.sheet__title { font-size: 1rem; font-weight: 700; color: var(--navy); }
.sheet__body { overflow-y: auto; padding: 4px 20px 12px; display: grid; gap: 18px; }
.sheet__footer {
  display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 20px; max-height: 80vh; }
}

.choice-group { border: 0; margin: 0; padding: 0; }
.choice-group__legend { font-size: .82rem; font-weight: 700; color: var(--slate); padding: 0; margin-bottom: 8px; }
.choice-group__options { display: flex; flex-wrap: wrap; gap: 8px; }
.choice__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--white);
  font-size: .85rem; color: var(--ink); cursor: pointer;
}
.choice__count { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.choice__input:checked + .choice { background: var(--navy); border-color: var(--navy); color: var(--white); font-weight: 600; }
.choice__input:checked + .choice .choice__count { color: #DCE5ED; }
.choice__input:checked + .choice::before { content: "✓"; font-size: .8rem; }   /* not colour alone */
.choice__input:focus-visible + .choice { outline: 3px solid var(--navy); outline-offset: 2px; }

/* --- Wider screens ---------------------------------------------------------------------- */

@media (min-width: 700px) {
  body { background: #ECEFF2; }
  .app { background: var(--paper); box-shadow: 0 0 0 1px var(--line); }
  .app-header { border-radius: 0 0 20px 20px; }
}
