/* ==========================================================================
   Thiết Kế & In Hàng Loạt Giấy Khen, Giấy Chứng Nhận - TCT.VN
   Chuẩn khổ A4 Landscape (297mm x 210mm) - Tỷ lệ 1.414:1
   ========================================================================== */

:root {
  --primary-color: #0d6efd;
  --primary-hover: #0b5ed7;
  --bg-color: #f1f5f9;
  --surface-color: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --border-focus: #3b82f6;

  /* Theme: Gold Classic */
  --gold-primary: #b38728;
  --gold-secondary: #fbf5b7;
  --gold-accent: #aa771c;
  --gold-dark: #6e4e13;

  /* Theme: Red National */
  --red-primary: #b91c1c;
  --red-secondary: #fef2f2;
  --red-accent: #dc2626;
  --red-dark: #7f1d1d;

  /* Theme: Blue Honor */
  --blue-primary: #1e40af;
  --blue-secondary: #eff6ff;
  --blue-accent: #3b82f6;
  --blue-dark: #172554;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

/* ==========================================================================
   Header Styles
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

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

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #f8fafc;
  color: #334155;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid #cbd5e1;
  transition: all 0.2s ease;
}

.btn-back:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(217, 119, 6, 0.25);
}

.app-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #0f172a;
}

.app-header .subtitle {
  font-size: 0.8rem;
  color: #64748b;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-backup {
  background: #ffffff;
  color: #1e293b;
  border: 1.5px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.btn-backup:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
  transform: translateY(-1px);
}

.btn-restore {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1.5px solid #93c5fd;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.1);
}

.btn-restore:hover {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e40af;
  transform: translateY(-1px);
}

.btn-print-all {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.btn-print-all:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
}

.btn-export-png {
  background: #0f766e;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 118, 110, 0.3);
}

.btn-export-png:hover {
  background: #115e59;
  transform: translateY(-1px);
}

/* ==========================================================================
   Main Layout: Sidebar (Inputs) + Preview Area
   ========================================================================== */
.main-container {
  display: flex;
  min-height: calc(100vh - 65px);
}

.sidebar-config {
  width: 460px;
  min-width: 420px;
  max-width: 480px;
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 65px);
}

.preview-area {
  flex: 1;
  background: #e2e8f0;
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 65px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Cards inside Sidebar */
.card-config {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-header-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-sample {
  background: #eff6ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-sample:hover {
  background: #dbeafe;
}

.btn-sample.btn-reset-data {
  background: #f8fafc;
  color: #64748b;
  border-color: #cbd5e1;
}

.btn-sample.btn-reset-data:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* Theme Picker Radio Cards */
.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-option {
  cursor: pointer;
}

.theme-option input {
  display: none;
}

.theme-box {
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 14px;
  transition: all 0.2s ease;
  position: relative;
}

.theme-badge {
  display: inline-block;
  margin-right: 6px;
  font-size: 1rem;
}

.theme-name {
  font-weight: 700;
  font-size: 0.88rem;
  display: block;
}

.theme-desc {
  font-size: 0.75rem;
  color: #64748b;
  display: block;
}

.theme-gold .theme-badge { color: #d97706; }
.theme-red .theme-badge { color: #dc2626; }
.theme-blue .theme-badge { color: #2563eb; }

.theme-option input:checked + .theme-box {
  border-color: #2563eb;
  background: #f8fafc;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width {
  grid-column: span 2;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
}

.form-group input,
.form-group select {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #1e293b;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.helper-text {
  font-size: 0.76rem;
  color: #64748b;
  margin-bottom: 8px;
}

.helper-text code {
  background: #f1f5f9;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.74rem;
  color: #0f172a;
}

.txt-area {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: monospace;
  font-size: 0.82rem;
  line-height: 1.4;
  resize: vertical;
  outline: none;
}

.txt-area:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.82rem;
  color: #475569;
}

.btn-secondary {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

/* Preview Toolbar */
.preview-toolbar {
  width: 100%;
  max-width: 1050px;
  background: #ffffff;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.preview-info {
  font-size: 0.82rem;
  color: #334155;
}

.preview-tip {
  color: #d97706;
  margin-left: 10px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-controls button {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}

.zoom-controls span {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 44px;
  text-align: center;
}

/* ==========================================================================
   Certificate Page Layout (A4 Landscape: 297mm x 210mm)
   Tỷ lệ chuẩn 1.4142. Màn hình hiển thị: 1050px x 742px
   ========================================================================== */
.certificates-container {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
  width: 100%;
  transform-origin: top center;
  transition: transform 0.2s ease;
}

.cert-page {
  width: 1050px;
  height: 742px;
  background: #fffdf7;
  position: relative;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  page-break-after: always;
  break-after: page;
}

/* Inner Frame Border (Vector SVG or CSS ornament) */
.cert-border-outer {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  bottom: 14px;
  border: 3px solid;
  pointer-events: none;
  z-index: 1;
}

.cert-border-inner {
  position: absolute;
  top: 22px;
  left: 22px;
  right: 22px;
  bottom: 22px;
  border: 1px solid;
  pointer-events: none;
  z-index: 1;
}

/* Corner Ornaments (SVG) */
.cert-corner {
  position: absolute;
  width: 90px;
  height: 90px;
  pointer-events: none;
  z-index: 2;
}

.cert-corner-tl { top: 18px; left: 18px; }
.cert-corner-tr { top: 18px; right: 18px; transform: scaleX(-1); }
.cert-corner-bl { bottom: 18px; left: 18px; transform: scaleY(-1); }
.cert-corner-br { bottom: 18px; right: 18px; transform: scale(-1, -1); }

/* Center Background Watermark */
.cert-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  height: 320px;
  opacity: 0.055;
  pointer-events: none;
  z-index: 0;
}

/* Certificate Inner Content */
.cert-inner-content {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 100%;
  padding: 20px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
}

/* Header Columns: Agency/School vs Motto */
.cert-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  margin-top: 4px;
}

.cert-header-left {
  text-align: center;
  max-width: 440px;
}

.cert-agency {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.cert-school {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 2px;
  letter-spacing: 0.3px;
}

.cert-header-left-line {
  width: 120px;
  height: 1px;
  margin: 4px auto 0;
}

.cert-header-right {
  text-align: center;
  max-width: 440px;
}

.cert-national-motto {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.cert-sub-motto {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 2px;
  font-style: italic;
}

.cert-header-right-line {
  width: 150px;
  height: 1.5px;
  margin: 4px auto 0;
}

/* Emblems / Ribbon Top Center */
.cert-emblem-badge {
  display: flex;
  justify-content: center;
  margin: -6px 0 2px 0;
}

.emblem-svg {
  width: 58px;
  height: 58px;
}

/* Certificate Title: GIẤY KHEN */
.cert-main-title {
  margin: 0 0 6px 0;
}

.cert-title-text {
  font-family: 'Playfair Display', serif;
  font-size: 3.4rem;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  line-height: 1.1;
  display: inline-block;
}

.cert-award-line {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-top: 2px;
}

/* Awardee Section */
.cert-recipient-section {
  margin: 4px 0;
}

.cert-recipient-label {
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  font-style: italic;
  font-weight: 600;
}

.cert-student-name {
  font-family: 'Playfair Display', 'Alex Brush', serif;
  font-size: 2.7rem;
  font-weight: 700;
  margin: 2px 0;
  letter-spacing: 1px;
  line-height: 1.2;
}

.cert-student-class {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Title / Honor Awarded */
.cert-honor-section {
  margin: 4px 0;
}

.cert-reason-text {
  font-size: 1.05rem;
  font-style: italic;
  max-width: 780px;
  margin: 0 auto 4px auto;
}

.cert-title-awarded {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  display: inline-block;
  padding: 2px 24px;
  border-bottom: 2px double;
}

.cert-school-year {
  font-size: 1rem;
  font-weight: 600;
  font-style: italic;
  margin-top: 4px;
}

/* Signer & Footer */
.cert-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  margin-bottom: 8px;
  padding: 0 30px;
}

.cert-footer-left {
  text-align: left;
}

.cert-decision-no {
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 500;
}

.cert-footer-right {
  text-align: center;
  min-width: 250px;
}

.cert-date {
  font-size: 0.92rem;
  font-style: italic;
  margin-bottom: 4px;
}

.cert-signer-role {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 60px; /* Space for signature and stamp */
}

.cert-signer-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ==========================================================================
   THEME PALETTES & STYLES
   ========================================================================== */

/* 1. Theme: VÀNG KIM CỔ ĐIỂN (Gold Classic) */
.theme-gold-classic {
  background: radial-gradient(circle at center, #fffdf8 0%, #fefcf3 100%);
  color: #3d2f13;
}
.theme-gold-classic .cert-border-outer {
  border-color: #b38728;
  border-width: 5px;
  outline: 2px solid #dfba60;
  outline-offset: -9px;
}
.theme-gold-classic .cert-border-inner {
  border-color: #aa771c;
  border-style: double;
  border-width: 3px;
}
.theme-gold-classic .cert-corner { fill: #b38728; }
.theme-gold-classic .cert-watermark { fill: #b38728; }
.theme-gold-classic .cert-agency { color: #52401f; }
.theme-gold-classic .cert-school { color: #855b11; }
.theme-gold-classic .cert-header-left-line { background: #b38728; }
.theme-gold-classic .cert-national-motto { color: #855b11; }
.theme-gold-classic .cert-sub-motto { color: #3d2f13; }
.theme-gold-classic .cert-header-right-line { background: #b38728; }
.theme-gold-classic .cert-title-text {
  color: #926615;
  text-shadow: 1px 1px 0px #fff, 2px 2px 3px rgba(179, 135, 40, 0.3);
}
.theme-gold-classic .cert-award-line { color: #855b11; }
.theme-gold-classic .cert-student-name { color: #9a1e1e; }
.theme-gold-classic .cert-student-class { color: #4b3917; }
.theme-gold-classic .cert-title-awarded {
  color: #926615;
  border-color: #b38728;
  background: rgba(251, 245, 183, 0.25);
}
.theme-gold-classic .cert-signer-role { color: #52401f; }
.theme-gold-classic .cert-signer-name { color: #1e293b; }

/* 2. Theme: ĐỎ CỜ TRUYỀN THỐNG (Red National) */
.theme-red-national {
  background: radial-gradient(circle at center, #fffdfd 0%, #fff7f7 100%);
  color: #3b0d0c;
}
.theme-red-national .cert-border-outer {
  border-color: #b91c1c;
  border-width: 6px;
  outline: 2px solid #ef4444;
  outline-offset: -10px;
}
.theme-red-national .cert-border-inner {
  border-color: #dc2626;
  border-style: solid;
  border-width: 1.5px;
}
.theme-red-national .cert-corner { fill: #b91c1c; }
.theme-red-national .cert-watermark { fill: #dc2626; }
.theme-red-national .cert-agency { color: #5f1515; }
.theme-red-national .cert-school { color: #991b1b; }
.theme-red-national .cert-header-left-line { background: #b91c1c; }
.theme-red-national .cert-national-motto { color: #991b1b; }
.theme-red-national .cert-sub-motto { color: #3b0d0c; }
.theme-red-national .cert-header-right-line { background: #b91c1c; }
.theme-red-national .cert-title-text {
  color: #b91c1c;
  text-shadow: 1px 1px 0px #fff, 2px 2px 2px rgba(185, 28, 28, 0.25);
}
.theme-red-national .cert-award-line { color: #7f1d1d; }
.theme-red-national .cert-student-name { color: #b91c1c; }
.theme-red-national .cert-student-class { color: #450a0a; }
.theme-red-national .cert-title-awarded {
  color: #b91c1c;
  border-color: #dc2626;
  background: rgba(254, 226, 226, 0.35);
}
.theme-red-national .cert-signer-role { color: #5f1515; }
.theme-red-national .cert-signer-name { color: #1e293b; }

/* 3. Theme: XANH VINH DANH HIỆN ĐẠI (Blue Honor) */
.theme-blue-honor {
  background: radial-gradient(circle at center, #fbfdff 0%, #f4f8fc 100%);
  color: #111e38;
}
.theme-blue-honor .cert-border-outer {
  border-color: #1e3a8a;
  border-width: 5px;
  outline: 2px solid #3b82f6;
  outline-offset: -9px;
}
.theme-blue-honor .cert-border-inner {
  border-color: #2563eb;
  border-style: double;
  border-width: 3px;
}
.theme-blue-honor .cert-corner { fill: #1e3a8a; }
.theme-blue-honor .cert-watermark { fill: #2563eb; }
.theme-blue-honor .cert-agency { color: #1e3a8a; }
.theme-blue-honor .cert-school { color: #1d4ed8; }
.theme-blue-honor .cert-header-left-line { background: #2563eb; }
.theme-blue-honor .cert-national-motto { color: #1e3a8a; }
.theme-blue-honor .cert-sub-motto { color: #0f172a; }
.theme-blue-honor .cert-header-right-line { background: #2563eb; }
.theme-blue-honor .cert-title-text {
  color: #1e40af;
  text-shadow: 1px 1px 0px #fff, 2px 2px 3px rgba(30, 64, 175, 0.25);
}
.theme-blue-honor .cert-award-line { color: #1d4ed8; }
.theme-blue-honor .cert-student-name { color: #1e3a8a; }
.theme-blue-honor .cert-student-class { color: #1e293b; }
.theme-blue-honor .cert-title-awarded {
  color: #1e40af;
  border-color: #3b82f6;
  background: rgba(239, 246, 255, 0.5);
}
.theme-blue-honor .cert-signer-role { color: #1e3a8a; }
.theme-blue-honor .cert-signer-name { color: #0f172a; }


/* ==========================================================================
   PRINT MEDIA STYLES (Chuẩn Khổ A4 Landscape)
   ========================================================================== */
@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  html, body {
    width: 297mm;
    height: 210mm;
    margin: 0;
    padding: 0;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .no-print {
    display: none !important;
  }

  .main-container {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .preview-area {
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .certificates-container {
    gap: 0 !important;
    transform: none !important;
    width: 297mm !important;
  }

  .cert-page {
    width: 297mm !important;
    height: 210mm !important;
    max-width: 297mm !important;
    max-height: 210mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    position: relative !important;
  }
}

/* ==========================================================================
   Responsive UI for screen
   ========================================================================== */
@media (max-width: 1024px) {
  .app-header {
    flex-wrap: wrap;
    gap: 12px;
    height: auto;
    padding: 12px 16px;
  }

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

  .main-container {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar-config {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid #cbd5e1;
  }

  .preview-area {
    max-height: none;
    min-height: 500px;
    overflow-x: auto;
  }
}
