/* =============================================================
   Blaze Certificate Generator — style.css
   Colour scheme, layout, components, responsive rules
   ============================================================= */

/* ── Custom Properties ──────────────────────────────────────── */
:root {
  --color-navy:       #1e3a5f;   /* matches Blaze Admin panel's brand.navy */
  --color-gold:       #c9a84c;
  --color-red:        #c9333a;
  --color-white:      #ffffff;
  --color-light-grey: #f4f6fa;
  --color-navy-light: #243358;   /* hover / subtle variant */
  --color-navy-dark:  #111b30;   /* active / pressed */
  --color-gold-light: #d9b96a;   /* hover on gold elements */
  --color-text-muted: #6b7897;   /* muted text on white bg */
  --color-border:     #dde2ef;   /* light dividers */

  /* Blaze Admin panel brand colours (AdminNavbar / AdminSidebar) */
  --admin-red:    #dc2626;
  --admin-orange: #f5b85f;
  --admin-text:   #1f2937;
  --admin-text-muted: #6b7280;
  --font-heading: 'Poppins', sans-serif;
  --font-admin:   'Inter', system-ui, sans-serif;

  --sidebar-width:    260px;
  --topbar-height:    56px;
  --admin-topbar-height: 56px;
  --radius:           6px;
  --radius-sm:        4px;
  --transition:       0.18s ease;

  --font-base: 'Montserrat', Arial, sans-serif;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-base);
  background-color: var(--color-light-grey);
  color: var(--color-navy);
  min-height: 100vh;
  overflow-x: hidden;
}

img {
  display: block;
  max-width: 100%;
}

/* ── Accessibility Utility ──────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Top Bar (matches Blaze Admin panel's AdminNavbar) ───────── */
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--admin-topbar-height);
  padding: 0 20px;
  background-color: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.admin-topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.admin-topbar__logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background-color: var(--admin-red);
  font-size: 0.9rem;
  line-height: 1;
}

.admin-topbar__title {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-navy);
  white-space: nowrap;
}

.admin-topbar__sep {
  color: var(--admin-text-muted);
  font-size: 0.85rem;
}

.admin-topbar__page {
  font-family: var(--font-admin);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--admin-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-topbar__actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.admin-topbar__back {
  font-family: var(--font-admin);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--admin-text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition);
}

.admin-topbar__back:hover {
  color: var(--admin-red);
}

/* .btn--outline was designed for the old dark top bar — on the new white
   admin topbar it needs a light-background variant for contrast */
.admin-topbar .btn--outline {
  color: var(--color-navy);
  border-color: var(--color-border);
  background-color: var(--color-light-grey);
}

.admin-topbar .btn--outline:hover:not(:disabled) {
  background-color: #e9edf6;
  border-color: var(--color-navy);
  color: var(--color-navy);
}

/* ── Admin Nav (matches Blaze Admin panel's AdminSidebar links) ─ */
.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-admin);
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  transition: background-color var(--transition), color var(--transition);
}

.admin-nav__link:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--color-white);
}

.admin-nav__link--active {
  background-color: rgba(255, 255, 255, 0.15);
  color: var(--color-white);
}

/* ── Banner Area ────────────────────────────────────────────── */
.banner-area {
  position: sticky;
  top: var(--topbar-height);
  z-index: 90;
  width: 100%;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
}

.banner--error {
  background-color: #fde8e9;
  color: var(--color-red);
  border-left: 4px solid var(--color-red);
}

.banner--warning {
  background-color: #fdf5e0;
  color: #7a5a00;
  border-left: 4px solid var(--color-gold);
}

/* ── CSV Preview Area ───────────────────────────────────────── */
.csv-preview-area {
  padding: 0 20px;
  background-color: var(--color-white);
  overflow-x: auto;
}

.csv-preview-area:empty {
  display: none;
}

.csv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  color: var(--color-navy);
  margin: 12px 0;
}

.csv-table th,
.csv-table td {
  padding: 6px 12px;
  text-align: left;
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.csv-table th {
  background-color: var(--color-navy);
  color: var(--color-white);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.csv-table tr:nth-child(even) td {
  background-color: var(--color-light-grey);
}

/* ── App Layout (two-column) ────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: calc(100vh - var(--topbar-height));
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background-color: var(--color-navy);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar__section {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__section:last-child {
  border-bottom: none;
}

.sidebar__section-heading {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--color-gold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
}

/* ── Template Gallery ───────────────────────────────────────── */
.template-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.template-gallery__item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  background-color: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition), background-color var(--transition);
}

.template-gallery__item img {
  width: 100%;
  aspect-ratio: 1536 / 1024;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background-color: var(--color-white);
}

.template-gallery__item span {
  font-size: 0.6875rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.25;
}

.template-gallery__item:hover {
  background-color: rgba(201, 168, 76, 0.1);
}

.template-gallery__item.is-selected {
  border-color: var(--color-gold);
  background-color: rgba(201, 168, 76, 0.15);
}

.template-gallery__item.is-selected span {
  color: var(--color-gold);
}

.template-gallery__divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 10px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.template-gallery__divider::before,
.template-gallery__divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.12);
}

/* ── Drop Zone ──────────────────────────────────────────────── */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 12px;
  border: 2px dashed var(--color-gold);
  border-radius: var(--radius);
  background-color: rgba(201, 168, 76, 0.07);
  cursor: pointer;
  text-align: center;
  transition:
    background-color var(--transition),
    border-color var(--transition);
  outline: none;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  background-color: rgba(201, 168, 76, 0.15);
  border-color: var(--color-gold-light);
}

.drop-zone.drop-zone--active {
  background-color: rgba(201, 168, 76, 0.22);
  border-color: var(--color-gold-light);
}

.drop-zone__icon {
  font-size: 2rem;
  line-height: 1;
}

.drop-zone__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-white);
  line-height: 1.3;
}

.drop-zone__hint {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

/* ── Template Thumbnail ─────────────────────────────────────── */
.template-thumbnail,
#templateThumbnail {
  width: 120px;
  height: auto;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-gold);
  margin-top: 10px;
  display: block;
}

/* ── Form Fields ────────────────────────────────────────────── */
.form-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color var(--transition);
}

.field-label:hover {
  color: var(--color-gold);
}

/* Highlight state set by Position_Editor via JS */
.field-label.is-selected {
  color: var(--color-gold);
}

.field-input {
  width: 100%;
  padding: 7px 10px;
  font-family: var(--font-base);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-navy);
  background-color: var(--color-light-grey);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  outline: none;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.field-input:focus {
  background-color: var(--color-white);
  border-color: var(--color-gold);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.25);
}

.field-input::placeholder {
  color: #a0a8bc;
  font-weight: 400;
}

.field-input--date {
  /* Date inputs need some extra tweaks for cross-browser consistency */
  cursor: pointer;
  color-scheme: light;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-family: var(--font-base);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    opacity var(--transition);
  outline: none;
  user-select: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.5);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Primary — gold background, navy text */
.btn--primary {
  background-color: var(--color-gold);
  color: var(--color-navy);
  border-color: var(--color-gold);
}

.btn--primary:hover:not(:disabled) {
  background-color: var(--color-gold-light);
  border-color: var(--color-gold-light);
}

.btn--primary:active:not(:disabled) {
  background-color: #b8932e;
  border-color: #b8932e;
}

/* Secondary — navy background, gold border, white text */
.btn--secondary {
  background-color: var(--color-navy);
  color: var(--color-white);
  border-color: var(--color-gold);
}

.btn--secondary:hover:not(:disabled) {
  background-color: var(--color-navy-light);
  border-color: var(--color-gold-light);
}

.btn--secondary:active:not(:disabled) {
  background-color: var(--color-navy-dark);
}

/* Outline — transparent background, gold border, white text (top bar use) */
.btn--outline {
  background-color: transparent;
  color: var(--color-gold);
  border-color: var(--color-gold);
}

.btn--outline:hover:not(:disabled) {
  background-color: rgba(201, 168, 76, 0.12);
  color: var(--color-gold-light);
  border-color: var(--color-gold-light);
}

/* Ghost — transparent, subtle border */
.btn--ghost {
  background-color: transparent;
  color: rgba(255, 255, 255, 0.7);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn--ghost:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--color-white);
  border-color: rgba(255, 255, 255, 0.35);
}

/* Full-width variant */
.btn--full {
  width: 100%;
}

/* Sidebar action buttons — add spacing between stacked buttons */
.sidebar__section--actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 20px;
  margin-top: auto;
}

/* ── Canvas Panel ───────────────────────────────────────────── */
.canvas-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background-color: var(--color-light-grey);
  overflow: auto;
}

/* Preview canvas — hidden working canvas (full resolution, portrait) */
#preview {
  display: none;  /* hidden — we draw to this, then copy rotated to #displayCanvas */
}

/* Display canvas — shows rotated landscape view of the portrait certificate */
#displayCanvas {
  display: block;
  max-height: calc(100vh - var(--topbar-height) - 48px);
  max-width: 100%;
  width: auto;
  height: auto;
  background-color: var(--color-white);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  cursor: crosshair;
  touch-action: none;  /* prevents scroll hijacking on touch devices */
}

/* Canvas panel */
.canvas-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-color: var(--color-light-grey);
  overflow: auto;
}

/* ── Responsive — Mobile < 768 px ───────────────────────────── */
@media (max-width: 767px) {
  /* Stack layout: sidebar above canvas */
  .app-layout {
    flex-direction: column;
  }

  /* Sidebar spans full width */
  .sidebar {
    width: 100%;
    flex-shrink: unset;
    overflow-y: visible;
  }

  /* Canvas panel fills viewport width, no extra padding */
  .canvas-panel {
    padding: 12px 0;
    overflow: visible;
    overflow-x: hidden;
  }

  /* Canvas scales to 100vw, preserves aspect ratio, no horizontal overflow */
  #preview {
    width: 100vw;
    max-width: 100vw;
    border-radius: 0;
    box-shadow: none;
    /* aspect-ratio retained from base rule — browser handles height */
  }

  /* Download buttons full width (already handled by .btn--full, but ensure all action btns) */
  .sidebar__section--actions .btn {
    width: 100%;
  }

  /* Top bar — allow title to wrap gracefully on very small screens */
  .admin-topbar__page {
    display: none;
  }
  .admin-topbar__sep {
    display: none;
  }

  /* CSV table — allow horizontal scroll within its container */
  .csv-preview-area {
    padding: 0 12px;
  }
}

/* ── Scrollbar Styling (optional, Webkit) ───────────────────── */
.sidebar::-webkit-scrollbar {
  width: 5px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.28);
}
