:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #697586;
  --line: #d8dde6;
  --accent: #0f766e;
  --accent-soft: #e2f4f1;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(20, 32, 48, .08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-top: 0;
  font-size: 1.35rem;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
}

.error {
  border: 1px solid #f4b8b8;
  background: #fff3f3;
  color: #9f1d1d;
  padding: 10px 12px;
  border-radius: 6px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  letter-spacing: 0;
}
h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  letter-spacing: 0;
}
p { margin: 0 0 10px; }
.topbar p {
  color: var(--muted);
  max-width: 780px;
}
.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
select, input[type="text"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }
button {
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 10px 13px;
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 9px 13px;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: #fff;
  text-decoration: none;
  white-space: nowrap;
}
button.secondary {
  background: #fff;
  color: var(--accent);
}
button:disabled {
  cursor: not-allowed;
  opacity: .48;
}
button.tiny {
  padding: 6px 8px;
  font-size: .82rem;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 20px 24px 48px;
  max-width: 1500px;
  margin: 0 auto;
}
.survey-panel, .dev-panel {
  min-width: 0;
}
.intro, .section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.intro { padding: 18px; }
.section-head {
  padding: 16px 18px;
  background: #fbfcfe;
  border-bottom: 1px solid var(--line);
}
.section-body { padding: 16px 18px 18px; }
.question {
  padding: 14px 0;
  border-bottom: 1px solid #eef1f5;
}
.question:last-child { border-bottom: 0; }
.q-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}
.q-label {
  font-weight: 750;
}
.required {
  color: var(--danger);
  margin-left: 4px;
}
.options {
  display: flex;
  gap: 8px 18px;
  flex-wrap: wrap;
}
.option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.likert {
  display: grid;
  grid-template-columns: auto repeat(var(--likert-points, 7), minmax(34px, 1fr)) auto;
  gap: 7px;
  align-items: center;
}
.likert label {
  display: grid;
  place-items: center;
  min-height: 34px;
}
.anchor {
  color: var(--muted);
  font-size: .84rem;
}
.intro-description {
  white-space: pre-line;
  color: var(--muted);
}
.matrix-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
}
th, td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
th:first-child, td:first-child {
  text-align: left;
  width: 42%;
}
th { background: #f3f6fa; }
.rank-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.checkline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  bottom: 12px;
  z-index: 5;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.wizard-progress,
.wizard-nav {
  display: none;
}
.wizard-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.wizard-track {
  height: 9px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  margin-top: 8px;
}
.wizard-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width .18s ease;
}
.status, .mini {
  color: var(--muted);
  font-size: .9rem;
}
body.mobile-wizard .layout {
  display: block;
  max-width: 860px;
}
body.mobile-wizard .survey-panel {
  width: 100%;
}
body.mobile-wizard .wizard-progress {
  display: block;
  position: sticky;
  top: 76px;
  z-index: 8;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
body.mobile-wizard .wizard-nav {
  display: inline-flex;
  justify-content: center;
}
body.mobile-wizard .section:not(.wizard-section-active),
body.mobile-wizard .intro.wizard-step:not(.wizard-step-active) {
  display: none;
}
body.mobile-wizard .section .question:not(.wizard-step-active) {
  display: none;
}
body.mobile-wizard .section .question.wizard-step-active {
  border-bottom: 0;
}
body.mobile-wizard .actions {
  justify-content: space-between;
}
body.mobile-wizard .actions #downloadCsv {
  display: none;
}
body.mobile-wizard .actions .status {
  flex-basis: 100%;
}
.comment-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border: 0;
  border-radius: 4px;
  padding: 2px 4px;
  background: transparent;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  opacity: .72;
}
.comment-button:hover,
.comment-button:focus-visible {
  color: var(--accent);
  opacity: 1;
}
.commentable {
  position: relative;
}
body.dev .commentable.has-comments {
  outline: 2px solid rgba(15, 118, 110, .26);
  outline-offset: 3px;
}
body.dev .commentable.has-direct-comments {
  background-image: linear-gradient(90deg, rgba(226, 244, 241, .62), transparent 42%);
}
body.dev .commentable.has-comments::after {
  content: attr(data-comment-count);
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .78rem;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(15, 118, 110, .22);
  pointer-events: none;
}
body.dev tr.commentable.has-comments::after {
  top: 4px;
  right: 4px;
}
.comment-target-highlight {
  outline: 3px solid #f2c94c !important;
  outline-offset: 4px !important;
  box-shadow: 0 0 0 6px rgba(242, 201, 76, .24);
}
.commentable.dev-target {
  outline: 2px solid rgba(15, 118, 110, .22);
  outline-offset: 3px;
}
.dev-panel {
  position: sticky;
  top: 96px;
  height: calc(100vh - 116px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.identity { margin-bottom: 12px; }
.dev-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.comment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
  background: #fff;
}
.comment-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
}
.comment-body { white-space: pre-wrap; margin: 8px 0; }
.comment-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.danger {
  border-color: #f0aaa3;
  background: #fff3f2;
  color: #9f1d1d;
}
.danger:hover {
  border-color: #d64b3f;
}
.inline-comments {
  margin-top: 14px;
}
.inline-comments:empty {
  display: none;
}
.inline-comments-head {
  color: var(--muted);
  font-size: .92rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.inline-comments .comment-card {
  background: #fbfcfe;
  margin-top: 8px;
}
.inline-comments .comment-meta {
  flex-direction: column;
  align-items: flex-start;
}
.revision-note {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #134e4a;
  padding: 8px 10px;
  margin: 8px 0;
  border-radius: 0 6px 6px 0;
  font-size: .9rem;
  white-space: pre-wrap;
}
.proposal-list {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}
.proposal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}
.proposal-generating {
  border-color: #f2c94c;
  background: #fffdf2;
}
.proposal-card.focused-proposal {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .16);
}
.proposal-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #f2c94c;
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0;
  background: #fff8d6;
  color: #7a5700;
  font-weight: 700;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(122, 87, 0, .2);
  border-top-color: #7a5700;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.thread-proposal {
  border: 1px solid #b8d8d3;
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0;
  background: #f7fbfa;
}
.thread-proposal.focused-proposal {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .16);
}
.proposal-head,
.proposal-actions,
.proposal-bulk-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.proposal-bulk-actions {
  justify-content: flex-start;
  margin-bottom: 10px;
}
.proposal-head {
  color: var(--muted);
  font-size: .84rem;
}
.proposal-change {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 8px;
}
.proposal-change ul {
  margin: 6px 0 0;
  padding-left: 20px;
}
.proposal-comment {
  border-left: 3px solid #cbd5e1;
  padding: 6px 8px;
  margin: 8px 0;
  background: #fff;
  white-space: pre-wrap;
}
.decision-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}
.decision-ok {
  border-color: #86c9aa;
  background: #edf9f3;
  color: #116339;
}
.decision-ng {
  border-color: #f0aaa3;
  background: #fff3f2;
  color: #9f1d1d;
}
.reply {
  border-left: 3px solid var(--accent-soft);
  margin-left: 12px;
  padding-left: 10px;
}
.linked-version {
  display: inline-block;
  padding: 4px 7px;
  background: var(--accent-soft);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: calc(100% - 24px);
}
dialog::backdrop { background: rgba(15, 23, 42, .35); }
.comment-save-status {
  min-height: 1.4em;
  margin: 6px 0 0;
}
menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
}
@media (max-width: 980px) {
  .topbar { position: static; flex-direction: column; align-items: stretch; }
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .dev-panel { position: static; height: auto; }
  .field-grid, .rank-grid { grid-template-columns: 1fr; }
  .likert { grid-template-columns: 1fr repeat(var(--likert-points, 7), minmax(30px, 1fr)) 1fr; }
}

@media (max-width: 720px) {
  body {
    font-size: 18px;
    line-height: 1.65;
  }
  .topbar {
    gap: 12px;
    padding: 14px 14px 10px;
  }
  /* 回答モードのモバイルでは開発用の操作類を隠してヘッダーを最小化（devモードは ?mode=dev で表示） */
  body.mobile-wizard .top-actions {
    display: none;
  }
  h1 {
    font-size: 1.2rem;
  }
  h2 {
    font-size: 1.15rem;
  }
  .topbar p,
  .status,
  .mini {
    font-size: 1rem;
  }
  .top-actions,
  .actions,
  .dev-actions,
  .proposal-actions {
    align-items: stretch;
  }
  .top-actions > *,
  .actions > button,
  .actions > .status {
    width: 100%;
  }
  select,
  input[type="text"],
  input[type="password"],
  textarea,
  button {
    min-height: 48px;
    font-size: 1rem;
  }
  button.tiny {
    min-height: 42px;
    font-size: .95rem;
  }
  button.comment-button {
    width: fit-content;
    min-height: 0;
    padding: 2px 4px;
    font-size: .82rem;
  }
  .layout {
    padding: 10px 10px 96px;
  }
  .intro,
  .section {
    border-radius: 8px;
    margin-bottom: 12px;
  }
  .intro,
  .section-head,
  .section-body {
    padding: 16px;
  }
  .q-head {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .q-label {
    font-size: 1.12rem;
  }
  .option,
  .checkline {
    width: 100%;
    align-items: flex-start;
    padding: 8px 0;
  }
  input[type="radio"],
  input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    margin-top: 3px;
  }
  .options {
    display: grid;
    gap: 6px;
  }
  .likert {
    grid-template-columns: repeat(var(--likert-points, 7), minmax(0, 1fr));
    gap: 4px;
  }
  .likert .anchor {
    grid-column: 1 / -1;
    font-size: .95rem;
  }
  .likert label {
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
  }
  .matrix-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    min-width: 680px;
  }
  th,
  td {
    padding: 10px;
    font-size: .95rem;
  }
  .comment-card,
  .thread-proposal,
  .proposal-card {
    padding: 12px;
  }
  .comment-meta,
  .proposal-head,
  .proposal-actions {
    display: grid;
    gap: 6px;
  }
  body.mobile-wizard .wizard-progress {
    top: 0;
    margin-bottom: 12px;
    padding: 12px;
  }
  body.mobile-wizard .actions {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
  }
  body.mobile-wizard .actions button[type="submit"],
  body.mobile-wizard .actions #downloadCsv,
  body.mobile-wizard .actions .status {
    grid-column: 1 / -1;
  }
}
