/* ==========================================================================
   Veriss Certificates: extends the shared Veriss design system (theme.css + app.css)
   Shell helpers, menus, drawer, charts, and the pieces specific to Certificates
   (template editor, recipient preview, verification page).
   ========================================================================== */

/* ---------- Accessibility helpers ---------- */
:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 100;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-md);
  background: var(--primary-600);
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
}

.skip-link:focus {
  top: 0.75rem;
}

.hp-field {
  position: absolute !important;
  left: -10000px !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------- Mobile safety ---------- */
/* Nothing may make the page wider than the screen (that is what makes a page "drift" sideways on phones).
   clip (unlike hidden) doesn't create a scroll container, so sticky headers keep working. */
html,
body {
  max-width: 100%;
  overflow-x: clip;
}

/* Flex and grid children may shrink below their content's width; long words, links and emails wrap */
.main-content,
.content-area,
.modern-card {
  min-width: 0;
}

.page-title,
.card-title,
.answer-value,
.cell-strong {
  overflow-wrap: anywhere;
}

/* iOS Safari zooms in when a field with text under 16px gets focus, and the page then sits zoomed and shifted.
   On touch screens and narrower viewports every text field uses 16px. (:root raises specificity above the
   Tailwind "!text-sm" helpers some filters use.) */
@media (max-width: 1024px), (pointer: coarse) {
  :root input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  :root select,
  :root textarea {
    font-size: 16px !important;
  }
}

/* Lucide icons rendered by <lucide-icon> */
svg.lucide {
  flex: none;
}

/* Sidebar links are real links here */
.sidebar-item {
  text-decoration: none;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3rem 0.625rem;
  border: 1px solid var(--neutral-300);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--neutral-600);
  background: var(--surface);
  cursor: pointer;
}

.chip-toggle.on {
  border-color: var(--primary-500);
  background: var(--primary-50);
  color: var(--primary-800);
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--neutral-700);
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch .track {
  width: 2.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: var(--neutral-300);
  position: relative;
  transition: background-color 0.15s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s ease;
}

.switch input:checked + .track {
  background: var(--primary-600);
}

.switch input:checked + .track::after {
  transform: translateX(1rem);
}

.switch input:focus-visible + .track {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--neutral-500);
  white-space: nowrap;
}

/* ---------- Share box ---------- */
.share-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.375rem 0.375rem 0.75rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--neutral-50);
  min-width: 0;
}

.share-box code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--neutral-700);
}


/* Overflow menu */
.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 40;
  min-width: 12rem;
  padding: 0.375rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.menu.up {
  top: auto;
  bottom: calc(100% + 0.25rem);
}

.menu button,
.menu a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--neutral-700);
  text-align: left;
}

.menu button:hover,
.menu a:hover,
.menu button:focus-visible,
.menu a:focus-visible {
  background: var(--neutral-100);
}

.menu .danger {
  color: var(--error-600);
}

.menu hr {
  margin: 0.25rem 0;
  border-color: var(--neutral-100);
}

/* ---------- Bar chart ---------- */
.vf-chart {
  display: flex;
  align-items: stretch;
  gap: 0.375rem;
  height: 200px;
}

.vf-chart-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
}

.vf-chart-track {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  border-radius: 6px;
  background: var(--neutral-50);
}

.vf-chart-bar {
  width: 100%;
  min-height: 0;
  border-radius: 6px 6px 3px 3px;
  background: var(--primary-500);
  transition: height 0.35s ease;
}

.vf-chart-col:hover .vf-chart-bar {
  background: var(--primary-600);
}

.vf-chart-value {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--neutral-700);
  white-space: nowrap;
}

.vf-chart-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--neutral-500);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .vf-chart { gap: 0.1875rem; }
  .vf-chart-value { display: none; }
}

.cell-clip {
  display: block;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-link {
  cursor: pointer;
}

/* Mobile list of responses instead of a wide table */
.response-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.625rem;
}

.response-card {
  display: block;
  width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: left;
  padding: 0.875rem 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.response-card:hover {
  border-color: var(--primary-300);
}

/* Drawer for a single response */
/* Above the fixed header (z-index 90) and the sidebar, like the shared modals */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--overlay-bg, rgba(15, 23, 42, 0.5));
  display: flex;
  justify-content: flex-end;
}

.drawer {
  width: 100%;
  max-width: 36rem;
  height: 100%;
  height: 100dvh;
  background: var(--surface);
  box-shadow: var(--shadow-2xl);
  display: flex;
  flex-direction: column;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--neutral-200);
}

.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 0.5rem 1.25rem 1.5rem;
}

.drawer-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--neutral-200);
}

/* Small definition list (admin form detail) */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.875rem 1.25rem;
}

.meta-grid dt {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--neutral-500);
}

.meta-grid dd {
  margin-top: 0.125rem;
  font-size: 0.875rem;
  color: var(--neutral-900);
  overflow-wrap: anywhere;
}

[v-cloak] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .vf-chart-bar { transition: none; }
}

/* ---------- Builder: save bar pinned to the bottom on phones and tablets ---------- */
.builder-mobile-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem calc(0.625rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--neutral-200);
  box-shadow: 0 -8px 24px -12px rgba(16, 24, 40, 0.25);
}

.builder-mobile-bar .save-state {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 1024px) {
  .builder-mobile-bar { display: none; }
}

@media (max-width: 1023px) {
  .has-mobile-bar { padding-bottom: 5rem; }
}

/* Responses filters: on phones the extra filters fold behind a button */
@media (max-width: 639px) {
  .filter-bar .filter-field,
  .filter-bar .filter-field-wide {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }
}

/* Dialog footers placed directly in .modal-content (not inside .modal-body) need their own padding.
   On phones the footer stays pinned to the bottom of the sheet so the buttons are always reachable. */
.modal-content > .modal-footer {
  margin-top: 0;
  padding: 1rem 1.5rem 1.25rem;
  background: var(--surface);
}

@media (max-width: 640px) {
  .modal-content > .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding: 0.875rem 1.125rem calc(0.875rem + env(safe-area-inset-bottom));
  }
}

/* Admin lists as cards on phones */
.list-card {
  display: block;
  padding: 0.875rem 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--surface);
  min-width: 0;
  overflow-wrap: anywhere;
}

a.list-card:hover {
  border-color: var(--primary-300);
}

/* ---------- Pop-up menus (export, form actions) ---------- */
.menu-backdrop,
.menu-title,
.menu .menu-cancel {
  display: none;
}

/* On phones a menu opens as a sheet along the bottom of the screen instead of a dropdown that can hang off an
   edge. (:root beats Tailwind width helpers such as !min-w-[16rem] on individual menus.) */
@media (max-width: 639px) {
  .menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--overlay-bg, rgba(15, 23, 42, 0.5));
    animation: vp-fade 0.18s ease-out;
  }

  :root .menu,
  :root .menu.up {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    top: auto;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
    z-index: 1001;
    min-width: 0 !important;
    max-height: 75vh;
    overflow-y: auto;
    padding: 0.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    animation: vp-rise 0.22s ease-out;
  }

  .menu button,
  .menu a {
    min-height: 2.875rem;
    font-size: 0.9375rem;
  }

  .menu-title {
    display: block;
    padding: 0.5rem 0.625rem 0.625rem;
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--neutral-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu .menu-cancel {
    display: flex;
    justify-content: center;
    margin-top: 0.25rem;
    border-top: 1px solid var(--neutral-100);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    font-weight: 600;
    color: var(--neutral-700);
  }
}

/* ==========================================================================
   Certificates: templates list
   ========================================================================== */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1.25rem;
}

.tpl-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.2s ease;
}

.tpl-card:hover {
  border-color: var(--primary-300);
  box-shadow: var(--shadow-md);
}

.tpl-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.414 / 1;
  padding: 0.875rem;
  background:
    linear-gradient(45deg, var(--neutral-100) 25%, transparent 25%, transparent 75%, var(--neutral-100) 75%) 0 0 / 16px 16px,
    linear-gradient(45deg, var(--neutral-100) 25%, transparent 25%, transparent 75%, var(--neutral-100) 75%) 8px 8px / 16px 16px,
    var(--neutral-50);
  border-bottom: 1px solid var(--neutral-200);
}

.tpl-thumb img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: var(--shadow-md);
}

.tpl-thumb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--neutral-500);
}

.tpl-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1rem 1.125rem 1rem;
}

.tpl-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--neutral-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.875rem;
}

/* File drop zone (template background, signatures, recipient lists) */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 9.5rem;
  padding: 1.25rem;
  text-align: center;
  border: 2px dashed var(--neutral-300);
  border-radius: var(--radius-lg);
  background: var(--neutral-50);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone:hover,
.drop-zone.over,
.drop-zone:focus-within {
  border-color: var(--primary-400);
  background: var(--primary-50);
}

.drop-zone.filled {
  border-style: solid;
}

.drop-preview {
  max-height: 7rem;
  max-width: 100%;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
}

.swal2-confirm.swal-danger {
  background: var(--error-600) !important;
}

/* ==========================================================================
   Certificates: template editor
   ========================================================================== */
.editor-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: -0.5rem 0 1rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-xs);
}

.editor-name {
  width: 100%;
  padding: 0.125rem 0.375rem;
  margin-left: -0.375rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
  color: var(--neutral-900);
}

.editor-name:hover { border-color: var(--neutral-200); }
.editor-name:focus { outline: none; border-color: var(--primary-400); box-shadow: var(--ring); background: var(--surface); }

.save-state {
  font-size: 0.75rem;
  color: var(--neutral-500);
}

.editor-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1200px) {
  .editor-grid { grid-template-columns: minmax(0, 1fr) 22rem; align-items: start; }
  .editor-panel { position: sticky; top: calc(var(--header-h) + 5rem); max-height: calc(100vh - var(--header-h) - 6rem); overflow-y: auto; padding-right: 2px; }
}

.stage-wrap {
  padding: 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(45deg, var(--neutral-100) 25%, transparent 25%, transparent 75%, var(--neutral-100) 75%) 0 0 / 20px 20px,
    linear-gradient(45deg, var(--neutral-100) 25%, transparent 25%, transparent 75%, var(--neutral-100) 75%) 10px 10px / 20px 20px,
    var(--neutral-50);
}

.stage {
  position: relative;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--shadow-xl);
  border-radius: 2px;
  touch-action: none;
}

.stage:focus-visible { outline: 2px solid var(--primary-500); outline-offset: 4px; }

.stage-bg,
.stage-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage-canvas { pointer-events: none; }

.stage-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.field-box {
  position: absolute;
  cursor: move;
  touch-action: none;
  border: 1px dashed rgb(var(--teal-600) / 0.55);
  background: rgb(var(--teal-400) / 0.06);
  transition: background 0.12s ease;
}

.field-box:hover { background: rgb(var(--teal-400) / 0.12); border-color: rgb(var(--teal-600) / 0.9); }

.field-box.selected {
  border: 1.5px solid rgb(var(--teal-600));
  background: rgb(var(--teal-400) / 0.1);
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.7);
  z-index: 5;
}

.field-chip {
  position: absolute;
  left: -1px;
  bottom: 100%;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 14rem;
  padding: 0.0625rem 0.375rem;
  border-radius: 4px 4px 0 0;
  background: rgb(var(--teal-600));
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.field-box:hover .field-chip,
.field-box.selected .field-chip { opacity: 1; }

.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid rgb(var(--teal-600));
  border-radius: 3px;
  background: #fff;
  touch-action: none;
}

@media (pointer: coarse) {
  .handle { width: 20px; height: 20px; }
}

.handle.h-nw { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.handle.h-n { left: 50%; top: 0; transform: translate(-50%, -50%); cursor: ns-resize; }
.handle.h-ne { right: 0; top: 0; transform: translate(50%, -50%); cursor: nesw-resize; }
.handle.h-e { right: 0; top: 50%; transform: translate(50%, -50%); cursor: ew-resize; }
.handle.h-se { right: 0; bottom: 0; transform: translate(50%, 50%); cursor: nwse-resize; }
.handle.h-s { left: 50%; bottom: 0; transform: translate(-50%, 50%); cursor: ns-resize; }
.handle.h-sw { left: 0; bottom: 0; transform: translate(-50%, 50%); cursor: nesw-resize; }
.handle.h-w { left: 0; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }

.guide {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  background: #e5487a;
}

.guide-v { left: 50%; top: 0; bottom: 0; width: 1px; }
.guide-h { top: 50%; left: 0; right: 0; height: 1px; }

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.panel-card {
  padding: 1.125rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.panel-title {
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--neutral-900);
}

.add-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.add-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--neutral-700);
  text-align: left;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.add-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-btn:hover:not(:disabled) { border-color: var(--primary-400); background: var(--primary-50); color: var(--primary-800); }
.add-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.field-list { display: flex; flex-direction: column; gap: 0.25rem; }

.field-list button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--neutral-700);
  text-align: left;
}

.field-list button:hover { background: var(--neutral-100); }
.field-list button.active { background: var(--primary-50); color: var(--primary-800); font-weight: 600; }

.font-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--neutral-900);
}

.font-trigger:hover { border-color: var(--primary-400); }

.font-menu {
  left: 0;
  right: 0;
  max-height: 22rem;
  overflow-y: auto;
}

.font-menu button { padding: 0.375rem 0.625rem; }
.font-menu button.active { background: var(--primary-50); color: var(--primary-800); }

.font-group {
  padding: 0.5rem 0.625rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--neutral-500);
}

.color-input {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.color-input input[type="color"] {
  flex: none;
  width: 2.625rem;
  height: 2.625rem;
  padding: 0.1875rem;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
}

.swatch {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 999px;
  border: 1px solid var(--neutral-300);
  box-shadow: inset 0 0 0 2px var(--surface);
}

.swatch.on { outline: 2px solid var(--primary-500); outline-offset: 1px; }

.pos-details summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--neutral-700);
}

/* ==========================================================================
   Certificates: issuing a batch
   ========================================================================== */
.wizard-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1100px) {
  .wizard-grid { grid-template-columns: minmax(0, 1fr) 21rem; align-items: start; }
  .order-col { position: sticky; top: calc(var(--header-h) + 1.25rem); }
}

.step-card {
  padding: 1.25rem 1.375rem 1.5rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}

.step-head {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  margin-bottom: 1.125rem;
}

.step-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 999px;
  border: 2px solid var(--neutral-300);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--neutral-600);
}

.step-num.done {
  border-color: var(--primary-600);
  background: var(--primary-600);
  color: #fff;
}

.step-title { font-size: 1rem; font-weight: 700; color: var(--neutral-900); }
.step-sub { font-size: 0.8125rem; color: var(--neutral-500); margin-top: 0.125rem; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--neutral-50);
  color: var(--primary-700);
}

.mapping {
  padding: 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.mapping-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.375rem 1rem;
  align-items: center;
}

@media (min-width: 640px) {
  .mapping-grid { grid-template-columns: 9rem minmax(0, 1fr); gap: 0.75rem 1rem; }
}

.mapping-label { font-size: 0.8125rem; font-weight: 600; color: var(--neutral-700); margin-top: 0.375rem; }

@media (min-width: 640px) {
  .mapping-label { margin-top: 0; }
}

.summary-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.sum-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--neutral-200);
  background: var(--neutral-50);
  font-size: 0.8125rem;
  color: var(--neutral-700);
}

.sum-chip b { font-weight: 700; }
.sum-chip.ok { border-color: var(--success-200); background: var(--success-50); color: var(--success-700); }
.sum-chip.bad { border-color: var(--error-200); background: var(--error-50); color: var(--error-700); }
.sum-chip.warn { border-color: var(--warning-100); background: var(--warning-50); color: var(--warning-700); }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.table-scroll .modern-table { border: 0; }
.recip-table td { vertical-align: top; }
.recip-table tr.row-error td,
.recip-table tr.row-duplicate td { background: var(--error-50); }
.recip-table tr.row-empty td { color: var(--neutral-400); }

.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}

.format-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  border: 1.5px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: left;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.format-card:hover { border-color: var(--primary-300); }
.format-card.on { border-color: var(--primary-500); box-shadow: var(--ring); }

.order-card {
  padding: 1.25rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.order-lines { margin-top: 1rem; display: grid; gap: 0.5rem; }
.order-lines div { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.875rem; }
.order-lines dt { color: var(--neutral-500); }
.order-lines dd { color: var(--neutral-900); font-weight: 600; text-align: right; }

.order-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--neutral-300);
  font-weight: 700;
  color: var(--neutral-900);
}

.order-total span:last-child { font-size: 1.5rem; letter-spacing: -0.02em; }

.order-problems { margin-top: 1rem; display: grid; gap: 0.5rem; }
.order-problems li {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--warning-700);
}
.order-problems li svg { flex: none; margin-top: 0.125rem; }
.recip-table td.cell-strong,
.recip-table td:nth-child(3) { white-space: nowrap; }
.recip-table td:last-child { min-width: 12rem; }
.step-card .segmented { max-width: 100%; overflow-x: auto; }
.step-card .segmented button { white-space: nowrap; }

/* Centered status panel (waiting for payment, confirming, done) */
.state-panel {
  padding: 3rem 1.5rem;
  text-align: center;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

/* ==========================================================================
   Certificates: public verification page
   ========================================================================== */
.verify-body { background: var(--surface); }

.verify-main {
  background:
    radial-gradient(800px 360px at 85% -10%, rgb(var(--teal-400) / 0.16), transparent 65%),
    radial-gradient(600px 320px at -10% 10%, rgb(var(--brand-navy-800) / 0.07), transparent 60%);
  min-height: calc(100vh - 4rem - 5rem);
}

.verify-wrap { max-width: 44rem; margin: 0 auto; padding: 3.5rem 1rem 4rem; }

.verify-search { display: flex; gap: 0.625rem; }

@media (max-width: 520px) {
  .verify-search { flex-direction: column; }
}

.verify-result {
  border: 1px solid var(--neutral-200);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.verify-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--neutral-200);
}

.verify-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 999px;
}

.verify-status-label { font-size: 1.125rem; font-weight: 800; letter-spacing: -0.01em; }
.verify-status-text { font-size: 0.875rem; color: var(--neutral-600); margin-top: 0.125rem; }

.is-valid .verify-status { background: var(--success-50); }
.is-valid .verify-status-icon { background: var(--success-100); color: var(--success-700); }
.is-valid .verify-status-label { color: var(--success-700); }
.is-revoked .verify-status { background: var(--error-50); }
.is-revoked .verify-status-icon { background: var(--error-100); color: var(--error-700); }
.is-revoked .verify-status-label { color: var(--error-700); }
.is-not_found .verify-status-icon { background: var(--neutral-100); color: var(--neutral-500); }
.is-not_found .verify-status-label { color: var(--neutral-900); }
.is-revoked .verify-name { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: rgb(var(--slate-400) / 0.7); }

.verify-body-grid { display: grid; gap: 1.5rem; padding: 1.75rem 1.5rem; }

@media (min-width: 640px) {
  .verify-body-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 2rem; }
}

.verify-k { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--neutral-500); }
.verify-name { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; color: var(--neutral-900); margin-top: 0.25rem; overflow-wrap: anywhere; }
.verify-title { margin-top: 0.5rem; font-size: 0.9375rem; color: var(--primary-700); font-weight: 600; }

.verify-details { display: grid; gap: 0.875rem; }
.verify-details dt { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--neutral-500); }
.verify-details dd { margin-top: 0.125rem; font-size: 0.9375rem; font-weight: 600; color: var(--neutral-900); overflow-wrap: anywhere; }

.verify-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  padding: 0.875rem 1.5rem;
  border-top: 1px solid var(--neutral-200);
  background: var(--neutral-50);
  font-size: 0.75rem;
  color: var(--neutral-500);
}

.verify-foot span { display: inline-flex; align-items: center; gap: 0.375rem; }

.verify-how {
  display: grid;
  gap: 1rem;
  margin-top: 2.5rem;
}

@media (min-width: 640px) {
  .verify-how { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.verify-how > div {
  padding: 1.125rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.verify-how p { margin-top: 0.75rem; font-size: 0.875rem; color: var(--neutral-600); }
.verify-how b { color: var(--neutral-900); }

@media print {
  .public-header, .verify-search, #verify-hint, .site-footer, .skip-link { display: none !important; }
  .verify-main { background: none; }
  .verify-result { box-shadow: none; }
}

/* Batch progress */
.progress-block { margin-top: 1.125rem; }
.progress-block .progress-fill { transition: width 0.6s ease; }

.live-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.25rem;
  border-radius: 999px;
  background: var(--success-500);
  animation: live-pulse 1.6s ease-in-out infinite;
}

@keyframes live-pulse { 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  .progress-block .progress-fill { transition: none; }
}

.cert-table td { vertical-align: middle; }
.progress-fill.ok { background: var(--success-500); }
.cert-table th.text-right { text-align: right; }

/* Overview: first-run steps */
.first-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.first-step:hover { border-color: var(--primary-300); background: var(--primary-50); }
.first-step b { display: block; color: var(--neutral-900); font-size: 0.9375rem; }
.first-step small { display: block; color: var(--neutral-500); font-size: 0.8125rem; margin-top: 0.125rem; }

/* Shared page head shell for the list pages */
.list-head-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.mini-progress { width: 7rem; height: 0.375rem; border-radius: 999px; background: var(--neutral-100); overflow: hidden; margin-bottom: 0.25rem; }
.mini-progress > div { height: 100%; background: var(--success-500); border-radius: 999px; }
.modern-link-plain { color: var(--neutral-900); }
.modern-link-plain:hover { color: var(--primary-700); }

/* Receipt */
.receipt {
  max-width: 48rem;
  margin: 0 auto;
  padding: 2.25rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.receipt-head { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--neutral-200); }
.receipt-k { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--neutral-500); margin-bottom: 0.25rem; }
.receipt-parties { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); padding: 1.5rem 0; }
.receipt-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.receipt-table th { text-align: left; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--neutral-500); padding: 0.625rem 0.5rem; border-bottom: 1px solid var(--neutral-200); }
.receipt-table td { padding: 0.875rem 0.5rem; border-bottom: 1px solid var(--neutral-100); color: var(--neutral-800); }
.receipt-table th.text-right, .receipt-table td.text-right { text-align: right; }
.receipt-table tfoot td { font-weight: 800; font-size: 1rem; color: var(--neutral-900); border-bottom: 0; padding-top: 1rem; }

@media print {
  .sidebar, .header-bar, .skip-link { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .content-area { padding: 0 !important; }
  .receipt { border: 0; box-shadow: none; }
}
.modern-table th.text-right { text-align: right; }

/* Admin drawers */
.drawer-h { margin: 1.5rem 0 0.625rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--neutral-500); }
.verify-mini { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; padding: 0.875rem 1rem; border-radius: var(--radius-md); }
.verify-mini.is-valid { background: var(--success-50); color: var(--success-700); }
.verify-mini.is-revoked { background: var(--error-50); color: var(--error-700); }

/* ==========================================================================
   Admin sign-in
   ========================================================================== */
.admin-auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 460px at 50% -12%, rgb(var(--teal-400) / 0.16), transparent 70%),
    radial-gradient(700px 420px at 100% 110%, rgb(var(--brand-navy-800) / 0.08), transparent 65%),
    var(--neutral-50);
}

@media (min-width: 640px) {
  .admin-auth { padding: 1.5rem 2rem 1.5rem; }
}

.admin-auth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

.admin-auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
}

.admin-auth-card {
  width: 100%;
  max-width: 27rem;
  padding: 1.75rem 1.375rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
}

@media (min-width: 640px) {
  .admin-auth-card { padding: 2.5rem 2.25rem 2.25rem; }
}

.admin-auth-head { margin-bottom: 1.75rem; }

.admin-auth-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgb(var(--brand-navy-800)), rgb(var(--brand-navy-950)));
  color: rgb(var(--teal-300));
  box-shadow: var(--shadow-md);
}

.admin-auth-kicker {
  margin-bottom: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-700);
}

.admin-auth-note {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--neutral-200);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--neutral-500);
}

.admin-auth-note svg { flex: none; margin-top: 0.1875rem; }

.admin-auth-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

/* ==========================================================================
   Free credits (admin console and order summary)
   ========================================================================== */
.credit-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--primary-200);
  border-radius: 999px;
  background: var(--primary-50);
  color: var(--primary-800);
  font-size: 0.8125rem;
  font-weight: 700;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.credit-pill.zero { border-color: var(--neutral-200); background: var(--surface); color: var(--neutral-500); font-weight: 600; }
.credit-pill:hover { border-color: var(--primary-400); }
.credit-pill-action { font-size: 0.75rem; font-weight: 600; color: var(--primary-700); }

.credit-balance {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: var(--primary-50);
}

.credit-form {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.credit-grant {
  padding: 0.875rem 1rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
}

.credit-grant.dim { background: var(--neutral-50); }

.order-credits {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.875rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--primary-50);
  color: var(--primary-800);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.order-credits svg { flex: none; margin-top: 0.125rem; }
.order-lines dd.credit { color: var(--success-700); }

/* Sample design picker (new template, editor) */
.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.625rem;
}

.sample-card {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.375rem;
  border: 2px solid var(--neutral-200);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: left;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.sample-card:hover { border-color: var(--primary-300); }
.sample-card.on { border-color: var(--primary-500); box-shadow: var(--ring); }

.sample-card .sample-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.414 / 1;
  border-radius: 5px;
  background: var(--neutral-100);
  overflow: hidden;
}

.sample-card .sample-thumb img { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-sm); }
.sample-card .sample-name { padding: 0 0.25rem 0.125rem; font-size: 0.75rem; font-weight: 700; color: var(--neutral-800); }

/* Payment services */
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1.25rem;
}

.service-tile {
  display: flex;
  flex-direction: column;
  padding: 1.125rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}

.service-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 1rem 0 0.25rem;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: var(--neutral-50);
}

.service-stats dt { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--neutral-500); }
.service-stats dd { margin-top: 0.125rem; font-size: 0.9375rem; font-weight: 700; color: var(--neutral-900); }
.service-stats dd span { font-size: 0.75rem; font-weight: 500; color: var(--neutral-500); }
.service-import { padding: 1rem; border: 1px solid var(--neutral-200); border-radius: var(--radius-md); }
.file-chip { flex-wrap: wrap; }
.file-chip > .flex-1 { flex-basis: 12rem; }
/* Recipients source switch: one option per line on phones */
@media (max-width: 32rem) { .source-switch { grid-auto-flow: row; } }
