@import "./styles.shared-theme.css";

:root {
  --form-btn-w-draft-restore: 112px;
  --form-btn-w-draft-discard: 176px;
  --form-choice-min-h: 52px;
}

/* Fixed-width buttons — prevent layout shift on language toggle */
.btn--i18n-fixed {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn--draft-restore {
  width: var(--form-btn-w-draft-restore);
  min-width: var(--form-btn-w-draft-restore);
  max-width: var(--form-btn-w-draft-restore);
}

.btn--draft-discard {
  width: var(--form-btn-w-draft-discard);
  min-width: var(--form-btn-w-draft-discard);
  max-width: var(--form-btn-w-draft-discard);
}

body.page-form .page > main.form-main {
  display: grid;
  gap: 14px;
  min-width: 0;
  overflow-x: clip;
}

body.page-form .stack,
body.page-form .field,
body.page-form fieldset {
  min-width: 0;
}

body.page-form fieldset.field {
  border: 0;
  padding: 0;
  margin: 0;
}

body.page-form legend {
  padding: 0;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--fg);
}

body.page-form {
  overflow-x: clip;
}

body.page-form .actions {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

body.page-form .actions .btn {
  width: 100%;
  max-width: 100%;
}

body.page-form .form-submit-status {
  margin: 10px 0 0;
  text-align: center;
  min-height: 1.25em;
}

body.page-form .actions.form-actions--success .form-submit-status {
  order: -1;
  margin: 0 0 12px;
}

body.page-form .form-start-new {
  width: 100%;
  max-width: 100%;
}

.survey-header {
  display: grid;
  gap: 8px;
  margin: 0 0 2px;
  padding: 0;
}

.survey-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.survey-header-top h1 {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
}

.language-switcher {
  flex-shrink: 0;
}

.lang-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.lang-toggle-btn:hover {
  border-color: var(--muted);
  background: #424242;
}

.lang-toggle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.lang-toggle-mark {
  position: relative;
  display: block;
  width: 24px;
  height: 22px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.lang-toggle-mark::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 1.5px;
  background: currentColor;
  opacity: 0.45;
  transform: translate(-50%, -50%) rotate(-38deg);
}

.lang-toggle-mark__zh {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 11px;
  letter-spacing: 0;
}

.lang-toggle-mark__en {
  position: absolute;
  right: 0;
  bottom: 0;
  font-size: 8px;
  letter-spacing: 0.02em;
}

.form-block {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.form-block__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.form-section {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.eval-group {
  position: relative;
  min-width: 0;
  padding: 0 0 10px 14px;
}

.eval-group + .eval-group {
  margin-top: 8px;
  padding-top: 10px;
}

.eval-group::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 2px;
  background: var(--eval-accent);
}

.eval-group--orange {
  --eval-accent: #f97316;
}

.eval-group--green {
  --eval-accent: #22c55e;
}

.eval-group--purple {
  --eval-accent: #a855f7;
}

body.page-form textarea.why-textarea {
  min-height: 72px;
  font-size: max(16px, 1em);
  line-height: 1.35;
}

body.page-form textarea.why-textarea::placeholder {
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
  color: var(--muted);
  opacity: 0.5;
}

body.page-form .hint-subtle {
  color: var(--muted);
  opacity: 0.5;
  font-size: 12px;
  line-height: 1.35;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field-upload {
  gap: 8px;
}

.device-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.choice-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.choice-options--count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-option,
.device-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: var(--form-choice-min-h);
  padding: 10px 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.choice-option {
  min-height: var(--form-choice-min-h);
  padding: 10px 6px;
}

.choice-option__content {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.choice-option__emoji {
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

.choice-option__text {
  font-size: 11px;
  line-height: 1.25;
}

.device-option span {
  font-size: 12px;
  line-height: 1.25;
}

.choice-option:has(input:checked),
.device-option:has(input:checked) {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.choice-option input,
.device-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field-label {
  color: var(--fg);
  font-size: 14px;
}

.file-upload-tile {
  position: relative;
  border: 1px dashed #555;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  background: var(--bg);
}

.file-upload-tile__prompt {
  display: block;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  min-height: 1.35em;
}

.file-upload-tile input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-preview {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 8px;
}

.draft-restore-bar {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #3b82f6;
  background: rgba(59, 130, 246, 0.12);
}

.draft-restore-bar__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.hint.ok {
  color: #86efac;
}

.hint.error {
  color: #ff9c9c;
}

.eval-pill-preview {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #dbeafe;
  color: #1e3a8a;
}

@media (max-width: 720px) {
  .draft-restore-bar__actions {
    flex-direction: column;
  }

  .draft-restore-bar__actions .btn--i18n-fixed {
    align-self: flex-start;
  }
}
