:root {
  --ink: #102235;
  --muted: #687684;
  --paper: #fffdf8;
  --wash: #f3efe6;
  --line: #d8d3c7;
  --teal: #357b7b;
  --gold: #bd8d31;
  --brand-purple: #453e82;
  --clay: #9b4f3f;
  --good: #2f7d55;
  --bad: #b5473f;
  --shadow: 0 18px 50px rgba(16, 34, 53, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(110deg, rgba(53, 123, 123, 0.13), transparent 36%),
    linear-gradient(250deg, rgba(189, 141, 49, 0.13), transparent 42%),
    var(--wash);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
.button-link {
  font: inherit;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--brand-purple);
  min-height: 44px;
  padding: 0 18px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover:not(:disabled),
.button-link:hover:not(.disabled-link) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(16, 34, 53, 0.16);
}

button:disabled,
.disabled-link {
  cursor: not-allowed;
  opacity: 0.48;
  pointer-events: none;
}

a {
  color: inherit;
  text-decoration: none;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #2a3d4f;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  min-height: 180px;
  padding: 14px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(53, 123, 123, 0.14);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 0 clamp(20px, 5vw, 72px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-weight: 800;
}

.brand-logo {
  display: block;
  width: clamp(168px, 24vw, 260px);
  max-height: 54px;
  object-fit: contain;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family: Georgia, serif;
  font-size: 15px;
  letter-spacing: 0;
}

.nav-links {
  display: flex;
  gap: 20px;
  color: #34495d;
  font-weight: 700;
}

.verify-shell,
.admin-shell {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.verify-shell {
  display: grid;
  grid-template-columns: minmax(300px, 0.78fr) minmax(480px, 1.22fr);
  gap: 28px;
  align-items: start;
}

.verify-panel,
.result-panel,
.admin-panel,
.records-panel,
.preview-panel {
  border: 1px solid rgba(216, 211, 199, 0.9);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.verify-panel,
.result-panel,
.admin-panel,
.records-panel,
.preview-panel {
  padding: clamp(20px, 3vw, 30px);
}

.section-kicker {
  color: var(--clay);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 8px 0 0;
  letter-spacing: 0;
}

h1 {
  max-width: 12ch;
  font-size: clamp(42px, 6vw, 70px);
  line-height: 0.98;
}

h2 {
  font-size: 24px;
  line-height: 1.15;
}

.intro-copy {
  max-width: 44rem;
  margin: 18px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.verify-form,
.admin-form {
  margin-top: 28px;
}

.code-entry,
.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.code-entry input {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.form-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-card {
  display: grid;
  gap: 4px;
  margin-top: 26px;
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  background: #f8f3e8;
  padding: 16px;
  color: #435263;
}

.status-card strong {
  color: var(--ink);
}

.status-card.success {
  border-left-color: var(--good);
  background: #edf7f1;
}

.status-card.error {
  border-left-color: var(--bad);
  background: #fbefec;
}

.result-header,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.secondary-action {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.certificate-frame {
  width: 100%;
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8f6f0;
}

.image-frame {
  display: grid;
  min-height: 360px;
  place-items: center;
}

.image-frame img {
  display: block;
  width: 100%;
  max-height: 78vh;
  object-fit: contain;
}

.image-frame img:not([src]) {
  min-height: 360px;
}

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

.credential-list div {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 6px 0 0;
  font-weight: 800;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(220px, 0.45fr);
  gap: 18px;
}

.field {
  min-width: 0;
}

.icon-action {
  width: 48px;
  padding: 0;
  font-weight: 900;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.builder-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(440px, 1.05fr);
  gap: 24px;
  margin-top: 24px;
  align-items: start;
}

.count-pill {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
}

.table-wrap {
  margin-top: 22px;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 14px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid #ece6d9;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #415569;
  font-size: 12px;
  text-transform: uppercase;
}

.selected-row {
  background: #eef7f6;
}

.text-action {
  min-height: 34px;
  padding: 0 12px;
  color: var(--teal);
  background: transparent;
  font-weight: 800;
}

.danger-action {
  color: var(--bad);
}

.table-input {
  min-width: 170px;
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

#json-output {
  margin-top: 18px;
}

@media (max-width: 900px) {
  .verify-shell,
  .builder-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    max-width: 13ch;
  }
}

@media (max-width: 620px) {
  .topbar,
  .result-header,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .verify-shell,
  .admin-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 18px;
  }

  .code-entry,
  .inline-field,
  .field-grid,
  .credential-list {
    grid-template-columns: 1fr;
  }

  .form-actions button,
  .code-entry button {
    width: 100%;
  }
}
