* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #f5f7fb;
  color: #1f2937;
}

.templates-page {
  display: block;
}

.auth-page {
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
}

.auth-page .footer {
  margin-top: 0;
  padding-bottom: 12px;
}

.auth-card {
  align-self: center;
}

.certificate-only {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.certificate-only .certificate-page {
  flex: 1 0 auto;
  width: 100%;
  display: grid;
  place-items: center;
}

.certificate-only .footer {
  margin-top: auto;
  padding-bottom: 12px;
}

.card {
  width: min(420px, 92vw);
  background: #ffffff;
  padding: 32px;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
  display: grid;
  gap: 16px;
}

.subtitle {
  color: #6b7280;
  margin: 0;
}

.admin-user {
  margin-left: 12px;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  background: #eef2ff;
  padding: 4px 10px;
  border-radius: 999px;
}

.form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
}

select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  font-family: inherit;
  background: #ffffff;
}

textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  font-family: inherit;
  resize: vertical;
}

.file-uploader {
  display: grid;
  gap: 8px;
}

.file-uploader input[type="file"] {
  display: none;
}

.file-uploader-control {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed #cbd5f5;
  background: #f8fafc;
}

.file-uploader-name {
  font-size: 12px;
  color: #6b7280;
}

.file-progress {
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  display: none;
}

.file-progress.is-active {
  display: block;
}

.file-progress-bar {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.2s ease;
}

button {
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.8;
  display: inline-block;
  flex-shrink: 0;
}

.error {
  background: #fee2e2;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.link {
  color: #2563eb;
  text-decoration: none;
}

.page {
  width: min(1100px, 92vw);
  margin: 40px auto;
  display: grid;
  gap: 24px;
  justify-items: stretch;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.panel {
  background: #ffffff;
  padding: 24px;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  display: grid;
  gap: 16px;
  width: 100%;
}

.templates-layout {
  grid-template-columns: 1fr;
  align-items: start;
  justify-items: stretch;
}

.templates-editor {
  width: 100%;
  display: grid;
  gap: 16px;
}

.tabs {
  width: 100%;
  display: grid;
  gap: 16px;
}

.tab-list {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}

.tab-button {
  border: 1px solid transparent;
  background: #f1f5f9;
  color: #1f2937;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.tab-button.is-active {
  background: #2563eb;
  color: #ffffff;
}

.tab-panel {
  width: 100%;
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.templates-list {
  width: 100%;
  display: grid;
  gap: 12px;
  justify-items: stretch;
}

.panel h2 {
  margin: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-field {
  flex: 1 1 220px;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
}

.form-row input[type="text"] {
  min-width: 220px;
}

.form-row input[name="q"] {
  min-width: 200px;
}

.form-row select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
}

.inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.secondary {
  background: #e2e8f0;
  color: #1f2937;
}

.danger {
  background: #ef4444;
}

.warning {
  background: #f59e0b;
  color: #1f2937;
}

.hint {
  font-size: 13px;
  color: #6b7280;
  margin: 0;
}

.footer {
  margin-top: 32px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
  width: 100%;
}

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

.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

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

.table-wrapper {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.table-wrapper.is-loading {
  opacity: 0.6;
  transform: translateY(2px);
}

.pagination,
.panel-header {
  transition: opacity 0.2s ease;
}

.fade-in {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.muted {
  color: #6b7280;
}

.cert-cell {
  position: relative;
  min-width: 80px;
}

.cert-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  cursor: zoom-in;
}

.image-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  cursor: zoom-in;
}

.image-preview {
  position: fixed;
  top: 120px;
  right: 24px;
  padding: 12px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  display: none;
  z-index: 40;
  pointer-events: none;
}

.image-preview img {
  display: block;
  max-width: min(520px, 85vw);
  max-height: min(520px, 80vh);
  border-radius: 8px;
}

.cert-preview {
  position: fixed;
  top: 120px;
  right: 24px;
  padding: 12px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  display: none;
  z-index: 40;
  pointer-events: none;
}

.cert-preview img {
  display: block;
  max-width: min(640px, 90vw);
  max-height: min(640px, 80vh);
  border-radius: 8px;
}

.cert-cell:hover .cert-preview {
  display: block;
}

.template-url {
  display: inline-block;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #2563eb;
  cursor: zoom-in;
}

.preview-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  font-size: 12px;
  color: #1f2937;
  cursor: zoom-in;
}

.template-preview {
  position: fixed;
  top: 120px;
  right: 24px;
  padding: 0 12px 12px 0;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  display: none;
  z-index: 40;
  pointer-events: none;
  width: min(105mm, 90vw);
  height: min(148.5mm, 80vh);
  overflow: hidden;
}

.template-preview-body {
  width: calc(210mm - 24px);
  height: calc(297mm - 24px);
  display: block;
  transform: scale(0.5);
  transform-origin: top left;
}

.cert-cell:hover .template-preview {
  display: block;
}

.cert-cell:hover .image-preview {
  display: block;
}

mark {
  background: #fde68a;
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 14px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
}

.modal-card {
  position: relative;
  width: min(360px, 92vw);
  background: #ffffff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  display: grid;
  gap: 12px;
  z-index: 1;
}

.modal-card.form-modal {
  width: min(720px, 94vw);
}

.modal-card.debug-modal {
  width: 96vw;
  height: 92vh;
  grid-template-rows: auto auto 1fr auto;
}

.debug-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.debug-meta {
  font-size: 14px;
  color: #4b5563;
}

.debug-actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.debug-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
  height: 100%;
  align-items: stretch;
}

.debug-panel {
  display: grid;
  grid-template-rows: 32px 1fr;
  gap: 8px;
  min-height: 0;
  height: 100%;
}

.debug-preview {
  gap: 10px;
}

.debug-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 32px;
}

.debug-panel-actions {
  display: inline-flex;
  gap: 6px;
}

.debug-label {
  font-size: 13px;
  color: #6b7280;
}

.debug-generate {
  padding: 6px 10px;
  font-size: 12px;
}

.debug-format {
  padding: 6px 10px;
  font-size: 12px;
}

.debug-save {
  padding: 6px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.debug-save .icon {
  width: 16px;
  height: 16px;
  display: inline-block;
}

.debug-preview-frame {
  width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  overflow: hidden;
  display: grid;
  place-items: start;
  padding: 0;
}

.debug-preview-frame .template-preview-body {
  width: 210mm;
  height: 297mm;
  transform: scale(0.52);
  transform-origin: top left;
}

.debug-panel textarea {
  height: 100%;
  resize: none;
}

.code-editor {
  position: relative;
  height: 100%;
}

.code-highlight,
.code-editor textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  overflow: auto;
}

.code-editor textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: transparent;
  caret-color: #111827;
  overflow: auto;
}

.code-editor textarea:focus {
  outline: none;
  border-color: #2563eb;
}

.token.tag {
  color: #2563eb;
}

.token.attr-name {
  color: #7c3aed;
}

.token.attr-value {
  color: #059669;
}

.token.punctuation {
  color: #64748b;
}

.token.comment {
  color: #9ca3af;
}

@media (max-width: 960px) {
  .debug-body {
    grid-template-columns: 1fr;
  }

  .debug-preview-frame {
    height: min(60vh, 520px);
  }
}

.modal-form .form-row {
  align-items: flex-end;
}

.modal-card h3 {
  margin: 0;
  font-size: 18px;
}

.modal-card p {
  margin: 0;
  color: #6b7280;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.tooltip {
  position: fixed;
  top: 20px;
  right: 24px;
  background: #111827;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 30;
}

.tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.certificate-card {
  width: min(520px, 92vw);
}

.upload-form input[type="file"] {
  padding: 8px;
  background: #f8fafc;
}

.upload-form input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

.upload-form input[type="search"]::-webkit-search-decoration,
.upload-form input[type="search"]::-webkit-search-cancel-button,
.upload-form input[type="search"]::-webkit-search-results-button,
.upload-form input[type="search"]::-webkit-search-results-decoration {
  display: none;
}

.certificate-preview img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
}

.certificate-template img {
  width: 200px;
  height: 340px;
  object-fit: cover;
  display: block;
  box-shadow: none;
  border-radius: 4px;
}

.certificate-only {
  background: #ffffff;
}

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

.certificate-text {
  background: #f8fafc;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #e5e7eb;
}

.certificate-text pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  color: #0f172a;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-form {
  margin: 0;
}


.table-actions button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.table-input {
  width: 180px;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.table-select {
  width: 180px;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
}

.table-file {
  width: 180px;
  padding: 4px 0;
  font-size: 12px;
}

.table-textarea {
  width: 260px;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  font-family: inherit;
  resize: vertical;
}

.table-textarea.readonly {
  min-height: 72px;
  white-space: pre-wrap;
  background: #f8fafc;
  color: #374151;
}

.table-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  text-decoration: none;
}

.table-actions a.secondary {
  background: #e2e8f0;
  color: #1f2937;
}

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .page {
    width: 100%;
    margin: 20px auto;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 12px;
  }

  .panel {
    padding: 18px;
  }

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

  .tab-list {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row input,
  .form-row select,
  .form-row button {
    width: 100%;
  }

  table {
    font-size: 12px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .table-actions {
    flex-wrap: wrap;
  }
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5f5;
}

.status-pending {
  background: #f59e0b;
}

.status-complete {
  background: #22c55e;
}
