:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1d2433;
  --muted: #667085;
  --primary: #1f6feb;
  --primary-dark: #1759c2;
  --danger: #b42318;
  --danger-bg: #fff2f0;
  --green: #157347;
  --shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

.login-page {
  min-height: 100vh;
  background: #eef2f7;
}

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

button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #b7c0cf;
  background: #f8fafc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.danger {
  border-color: #f1b9b4;
  color: var(--danger);
  background: var(--danger-bg);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}

input,
select {
  height: 34px;
  padding: 0 10px;
}

textarea {
  padding: 8px 10px;
  resize: vertical;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

#summary {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  height: 34px;
}

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

.login-panel {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 6px;
}

.login-error {
  padding: 9px 10px;
  border: 1px solid #f1b9b4;
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-bg);
}

main {
  padding: 16px 20px 24px;
}

.filters,
.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.filters {
  flex-wrap: wrap;
}

.field {
  width: 160px;
}

.search-field {
  width: min(360px, 100%);
  flex: 1 1 260px;
}

label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  color: var(--text);
  font-size: 14px;
}

.checkbox-field input,
.selection input,
td input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.toolbar {
  justify-content: space-between;
  margin-top: 12px;
}

.selection,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.question-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.question-card {
  padding: 16px 18px 12px;
  border: 1px solid #e2e7ef;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.muted {
  color: var(--muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #cfd8e3;
  border-radius: 999px;
  background: #f8fafc;
  white-space: nowrap;
}

.question-title {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  font-size: 16px;
  line-height: 1.7;
}

.question-no {
  color: #111827;
  font-weight: 700;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.option-list {
  display: grid;
  gap: 6px;
  margin: 12px 0 0 28px;
  padding: 0;
  list-style: none;
}

.option-list li {
  display: grid;
  grid-template-columns: 28px 1fr;
  min-height: 26px;
  line-height: 1.6;
}

.option-label {
  color: #344054;
  font-weight: 700;
}

.answer-line {
  margin: 12px 0 0 28px;
  color: var(--green);
  font-weight: 700;
}

.question-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #edf0f5;
}

.question-menu .selected {
  border-color: #9bc6ae;
  color: var(--green);
  background: #eefbf3;
}

.paper-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.paper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf0f5;
}

.paper-head h2 {
  margin: 0;
  font-size: 18px;
}

.paper-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.paper-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.paper-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #e6eaf0;
  border-radius: 8px;
  background: #fbfcfe;
}

.paper-name {
  font-weight: 700;
}

.paper-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

#editForm,
.duplicate-content {
  padding: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.icon-btn {
  width: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.full {
  margin-top: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.duplicate-group {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.duplicate-group h3 {
  margin: 0;
  padding: 10px 12px;
  background: #f1f4f8;
  font-size: 14px;
}

.duplicate-group ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.duplicate-group li {
  padding: 10px 12px;
  border-top: 1px solid #e8ebf1;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: none;
  max-width: 420px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: #1d2939;
  box-shadow: var(--shadow);
}

#toast.show {
  display: block;
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .filters,
  .toolbar,
  .selection,
  .result-actions,
  .paper-head,
  .paper-item {
    align-items: stretch;
    flex-direction: column;
  }

  .field,
  .search-field {
    width: 100%;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}
