:root {
  --bg: #0a0a0c;
  --surface: #121215;
  --surface-2: #17171b;
  --surface-3: #1d1d22;
  --line: #242429;
  --line-soft: #1a1a1e;
  --text: #ececef;
  --muted: #8a8a94;
  --dim: #5d5d67;
  --accent: #9aa0ff;
  --accent-strong: #7b83ff;
  --danger: #ff6a5e;
  --ok: #4ade80;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  font-size: 15px;
}

.app {
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.12s ease;
}

a:hover {
  color: #b7bcff;
}

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

.topbar {
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 10, 12, 0.86);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 13px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand:hover {
  color: var(--text);
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--text);
  color: #0a0a0c;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.spacer {
  flex: 1;
}

.who {
  color: var(--dim);
  font-size: 12.5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 34px 22px 72px;
}

.container.narrow {
  max-width: 720px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

h1 {
  font-size: 24px;
  letter-spacing: -0.025em;
  margin: 0;
  font-weight: 620;
}

h2 {
  font-size: 16px;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.sub {
  color: var(--muted);
  font-size: 13px;
  margin: 5px 0 0;
}

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

.small {
  font-size: 13px;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
  color: #c9c9d4;
}

/* -------------------------------- cards ------------------------------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
}

.card + .card {
  margin-top: 10px;
}

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.form-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: background 0.12s ease;
}

.form-card:hover {
  background: var(--surface-2);
}

.form-card h3 {
  margin: 0;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.form-card h3 a {
  color: var(--text);
}

.form-card h3 a:hover {
  color: var(--accent);
}

.card-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--dim);
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 550;
  background: var(--surface-3);
  color: var(--muted);
  letter-spacing: 0.01em;
}

.pill.ok {
  background: rgba(74, 222, 128, 0.12);
  color: var(--ok);
}

.pill.warn {
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
}

.pill.info {
  background: rgba(154, 160, 255, 0.1);
  color: var(--accent);
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: auto;
}

.card-actions .btn[data-action="delete-form"] {
  margin-left: auto;
  color: var(--dim);
}

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

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 13px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  line-height: 1.25;
}

.btn:hover {
  background: var(--surface-2);
  border-color: #313138;
  color: var(--text);
}

.btn.primary {
  background: var(--text);
  border-color: var(--text);
  color: #0a0a0c;
  font-weight: 600;
}

.btn.primary:hover {
  background: #ffffff;
  border-color: #ffffff;
  color: #000;
}

.btn.danger {
  color: var(--danger);
  background: transparent;
}

.btn.danger:hover {
  background: rgba(255, 106, 94, 0.1);
  border-color: rgba(255, 106, 94, 0.35);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.sm {
  padding: 5px 9px;
  font-size: 12.5px;
  border-radius: 7px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* -------------------------------- forms ------------------------------- */

.field {
  margin-bottom: 20px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-weight: 550;
  font-size: 13.5px;
  margin-bottom: 7px;
  color: #d6d6de;
}

.req {
  color: var(--dim);
  margin-left: 3px;
}

.field-help {
  color: var(--dim);
  font-size: 12.5px;
  margin-bottom: 8px;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.12s ease, background 0.12s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--dim);
}

input:hover,
textarea:hover,
select:hover {
  border-color: #2e2e35;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-strong);
  background: var(--surface-2);
}

textarea {
  resize: vertical;
  min-height: 84px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.field.invalid input,
.field.invalid textarea,
.field.invalid select {
  border-color: rgba(255, 106, 94, 0.6);
}

.field-error {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 6px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14.5px;
  cursor: pointer;
  padding: 9px 11px;
  border-radius: 8px;
  transition: background 0.12s ease;
}

.option:hover {
  background: var(--surface);
}

.option.checked {
  background: var(--surface-2);
}

.option input[type="checkbox"],
.option input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  margin: 1px 0 0;
  width: 16px;
  height: 16px;
  flex: none;
  cursor: pointer;
  position: relative;
  border: 1px solid #3a3a44;
  border-radius: 4px;
  background: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.option input[type="radio"] {
  border-radius: 50%;
}

.option input:hover {
  border-color: #4c4c58;
}

.option input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(154, 160, 255, 0.3);
}

.option input:checked {
  background: var(--text);
  border-color: var(--text);
}

.option input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4.5px;
  top: 1.5px;
  width: 5px;
  height: 9px;
  border: solid #0a0a0c;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.option input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #0a0a0c;
}

.heading-field {
  margin: 32px 0 16px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

.heading-field:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.heading-field h2 {
  margin: 0;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
  font-weight: 600;
}

.heading-field .field-help {
  margin: 5px 0 0;
}

/* -------------------------------- login ------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 8px 0;
}

.login-card .brand {
  margin-bottom: 26px;
}

.login-card h2 {
  font-size: 20px;
  font-weight: 620;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.token-input {
  font-family: var(--mono);
  font-size: 12.5px !important;
  letter-spacing: 0.01em;
  min-height: 74px;
  background: var(--surface) !important;
}

.error-box {
  background: rgba(255, 106, 94, 0.08);
  color: #ff9d94;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* --------------------------------- table ------------------------------ */

.table-wrap {
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th,
td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.clickable {
  cursor: pointer;
  transition: background 0.1s ease;
}

tbody tr.clickable:hover {
  background: var(--surface-2);
}

.empty {
  text-align: center;
  padding: 52px 24px;
  color: var(--muted);
}

.empty-icon {
  font-size: 26px;
  margin-bottom: 12px;
  opacity: 0.5;
  filter: grayscale(1);
}

/* -------------------------------- misc -------------------------------- */

.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--mono);
  color: #b6b6c2;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  margin: 26px 0 18px;
}

.tab {
  border: none;
  background: none;
  padding: 9px 0;
  font: inherit;
  font-weight: 500;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

pre.json {
  background: #08080a;
  color: #b9bcc8;
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  max-height: 520px;
  margin: 0;
}

.code-editor {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 330px;
  background: #08080a !important;
}

.answer-row {
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
}

.answer-row:last-child {
  border-bottom: none;
}

.answer-q {
  color: var(--muted);
  font-size: 13px;
}

.answer-a {
  font-size: 14.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tag {
  display: inline-block;
  background: var(--surface-3);
  color: #d3d3dd;
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 12.5px;
  margin: 0 5px 5px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1c1c21;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  z-index: 100;
  max-width: calc(100vw - 40px);
  animation: toast-in 0.14s ease;
}

.toast.error {
  background: rgba(255, 106, 94, 0.16);
  color: #ffb0a8;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* -------------------------------- modal ------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.66);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.modal {
  background: #101013;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 24px;
  animation: modal-in 0.14s ease;
}

.modal-wide {
  max-width: 820px;
}

.modal h2 {
  margin-bottom: 4px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

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

.modal-close {
  float: right;
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--dim);
  cursor: pointer;
  padding: 2px 6px;
}

.modal-close:hover {
  color: var(--text);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------ public form --------------------------- */

.public-wrap {
  min-height: 100vh;
  padding: 56px 16px 72px;
}

.public-card {
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 36px;
}

.public-head {
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}

.public-head h1 {
  font-size: 23px;
  margin-bottom: 8px;
  font-weight: 620;
}

.public-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  white-space: pre-wrap;
}

.brand-foot {
  text-align: center;
  margin-top: 26px;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #3f3f47;
}

.success-box {
  text-align: center;
  padding: 30px 10px;
}

.success-mark {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.1);
  color: var(--ok);
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  font-size: 22px;
}

.skeleton {
  height: 12px;
  border-radius: 4px;
  background: #17171b;
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.035), transparent);
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

@media (max-width: 640px) {
  .container {
    padding: 24px 16px 56px;
  }

  .public-wrap {
    padding: 20px 10px 48px;
  }

  .public-card {
    padding: 24px 18px;
    border-radius: 12px;
  }

  h1 {
    font-size: 21px;
  }

  .answer-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .who {
    display: none;
  }

  .card-actions .btn {
    flex: 1;
  }

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