// Strips Material's default dialog padding for just this panel (scoped via the panelClass, same
// ::ng-deep .mat-mdc-dialog-container pattern already used elsewhere, e.g. trainingvenue.component.scss)
// so .preview-shell fills the dialog edge-to-edge instead of sitting inside a padded box.
::ng-deep .cert-preview-dialog-panel {
  .mat-mdc-dialog-container,
  .mdc-dialog__surface {
    padding: 0 !important;
    border-radius: 12px;
    overflow: hidden;
    height: 100%;
  }
  .mat-mdc-dialog-content {
    padding: 0 !important;
    margin: 0 !important;
    max-height: none !important;
    height: 100%;
  }
}

.preview-shell {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary, #fff);
  height: 100%;
}

// ── Top bar ──────────────────────────────────────────────────────────────
.preview-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-default, #e5e7eb);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;

  mat-icon { font-size: 20px; width: 20px; height: 20px; }
  &:hover { background: var(--bg-selected); }
}

.topbar-title {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  min-width: 0;

  .title-main {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
  }
  .title-sub {
    font-size: 12px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-default, #d1d5db);
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;

  mat-icon { font-size: 16px; width: 16px; height: 16px; }
  &:hover:not(:disabled) { background: var(--bg-selected); }
  &:disabled { opacity: 0.5; cursor: not-allowed; }

  &.btn-primary {
    background: var(--action-primary-default);
    border-color: var(--action-primary-default);
    color: var(--action-primary-text, #fff);
    &:hover:not(:disabled) { background: var(--action-primary-hover, var(--action-primary-default)); }
  }
}

.btn-close-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 4px;

  mat-icon { font-size: 20px; width: 20px; height: 20px; }
  &:hover { background: var(--bg-selected); }
}

// ── Body: card + sidebar ─────────────────────────────────────────────────
.preview-body {
  display: flex;
  flex: 1;
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
  flex-wrap: wrap;
  align-content: flex-start;
}

.cert-card-wrap {
  flex: 2 1 480px;
  min-width: 0;
}

.cert-card {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 72px 32px;
  border-radius: 16px;
  border: 1px solid var(--category-bg-alpha, #e9d8fd);
  background:
    radial-gradient(circle at 15% 10%, rgba(240, 168, 62, 0.08), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(124, 58, 237, 0.06), transparent 45%),
    var(--bg-secondary, #fbfaf7);
}

.cert-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 22px;
}

.cert-lead {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.cert-name {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 34px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 4px 0 6px;
}

.cert-empid {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 22px;
}

.cert-programme {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 6px 0;
}

.cert-context {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 28px;
}

.cert-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  border-top: 1px solid var(--border-default, #e5e7eb);
}

.cert-sign {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;

  .sign-name {
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    font-size: 16px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-default, #d1d5db);
    padding-bottom: 4px;
    margin-bottom: 4px;
  }
  .sign-label {
    font-size: 11px;
    color: var(--text-tertiary);
  }
}

.cert-qr {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  border: 1px solid var(--border-default, #d1d5db);
  color: var(--text-tertiary);
  flex-shrink: 0;

  mat-icon { font-size: 30px; width: 30px; height: 30px; }
}

.cert-date {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;

  .date-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-default, #d1d5db);
    padding-bottom: 4px;
    margin-bottom: 4px;
  }
  .date-label {
    font-size: 11px;
    color: var(--text-tertiary);
  }
}

.preview-caption {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-top: 14px;
}

// ── Sidebar ──────────────────────────────────────────────────────────────
.preview-sidebar {
  flex: 1 1 95px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-status {
  border: 1px solid var(--border-default, #e5e7eb);
  border-radius: 10px;
  padding: 14px;

  .status-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
  }

  .expiry-line {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);

    mat-icon { font-size: 16px; width: 16px; height: 16px; color: var(--text-tertiary); }
    strong { color: var(--text-primary); }
  }
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;

  &.st-active   { background: var(--category-bg-alpha, #bbf7d0); color: var(--category-text-alpha, #16a34a); }
  &.st-expired  { background: var(--status-error-bg, #fecaca); color: var(--status-error-text, #b91c1c); }
  &.st-revoked  { background: var(--bg-selected); color: var(--text-secondary); }
  &.st-renewal  { background: #fde68a; color: #92400e; }
}

.days-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;

  &.days-expired { background: var(--status-error-bg, #fecaca); color: var(--status-error-text, #b91c1c); }
  &.days-warning { background: #fde68a; color: #92400e; }
  &.days-ok      { background: var(--bg-selected); color: var(--text-secondary); }
}

.sidebar-card {
  border: 1px solid var(--border-default, #e5e7eb);
  border-radius: 10px;
  padding: 16px;

  h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 6px;

    mat-icon { font-size: 16px; width: 16px; height: 16px; color: var(--category-text-alpha, #16a34a); }
  }
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
  &:last-child { margin-bottom: 0; }

  span {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-tertiary);
  }
  strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
  }
}

.verification-card {
  p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 12px;
    line-height: 1.5;
  }
}

.btn-verify-now {
  width: 100%;
  padding: 9px;
  border-radius: 6px;
  border: 1px solid var(--border-default, #d1d5db);
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);

  &:hover { background: var(--bg-selected); }
}

// ── Print: only the certificate card ────────────────────────────────────
@media print {
  .preview-topbar,
  .preview-sidebar,
  .preview-caption {
    display: none !important;
  }
  .preview-body { padding: 0; }
  .cert-card { border: none; }
}
