/* ==========================================================================
   Base & App Styles (Modern UI)
   ========================================================================== */
   :root {
    --bg-color: #f8fafc;
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --border-color: #e2e8f0;
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --text-main: #0f172a;
    --text-muted: #64748b;
  }
  
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
  }
  
  .app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
  }
  
  .sidebar {
    width: 400px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 4px 0 24px rgba(0,0,0,0.06);
  }
  
  .sidebar-header {
    padding: 28px 24px 20px 24px;
    border-bottom: 1px solid var(--border-color);
  }
  
  .sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
  }
  
  .sidebar-header p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.4;
  }
  
  .header-links {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
  }

  .team-section { width: 100%; margin-top: 8px; }
  .team-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
  .team-names { display: flex; flex-wrap: wrap; gap: 5px; }
  .team-names span, .team-names a { font-size: 0.72rem; background: #e0e7ff; color: var(--primary-color); padding: 3px 8px; border-radius: 4px; font-weight: 500; text-decoration: none; transition: background 0.2s, transform 0.1s; }
  .team-names a:hover { background: #c7d2fe; }
  .team-names a:active { transform: scale(0.96); }
  .acknowledgement a { color: inherit; text-decoration: none; }
  .acknowledgement a:hover strong { text-decoration: underline; }
  .acknowledgement { font-size: 0.7rem; color: var(--text-muted); margin-top: 6px; font-style: italic; }
  .acknowledgement strong { color: var(--text-main); font-weight: 600; }

  .creator-credit {
    font-size: 0.8rem !important;
    color: var(--primary-color) !important;
    background: #e0e7ff;
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    margin: 0;
  }
  .creator-credit strong {
    font-weight: 700;
  }

  .marketing-credit {
    font-size: 0.8rem !important;
    color: #0369a1 !important;
    background: #e0f2fe;
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    margin: 0;
  }
  .marketing-credit strong {
    font-weight: 700;
  }

  .header-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    text-decoration: none;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 6px;
    transition: background 0.2s, transform 0.1s;
  }
  .header-badge:active {
    transform: scale(0.95);
  }
  .github-link {
    color: var(--text-main);
    background: #e2e8f0;
  }
  .github-link:hover {
    background: #cbd5e1;
  }
  .mail-link {
    color: #b45309;
    background: #fef3c7;
  }
  .mail-link:hover {
    background: #fde68a;
  }

  .page-nav {
    display: flex; gap: 0; margin-top: 14px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border-color);
  }
  .page-nav-tab {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 12px; font-size: 0.8rem; font-weight: 600; text-decoration: none;
    color: var(--text-muted); background: var(--bg-color); transition: all 0.2s;
  }
  .page-nav-tab:hover { background: #e2e8f0; color: var(--text-main); }
  .page-nav-tab.active { background: var(--primary-color); color: #fff; pointer-events: none; }

  #generator-form {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
  }
  
  #generator-form::-webkit-scrollbar {
    width: 6px;
  }
  #generator-form::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
  }
  
  .sidebar-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 4px 0;
  }

  h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--primary-color);
    letter-spacing: 1.5px;
    font-weight: 700;
    margin-bottom: -4px;
  }

  .form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  .form-row {
    display: flex;
    gap: 16px;
  }
  
  .form-row .form-group {
    flex: 1;
    min-width: 0;
  }
  
  label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
  }
  
  input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: #fff;
    color: #334155;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  }
  
  input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
  }

  .checkbox-group .checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
  }

  .checkbox-group input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--primary-color);
    cursor: pointer;
    margin: 0;
  }

  select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: #fff;
    color: #334155;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
  }

  select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
  }

  select option[value=""][disabled] {
    color: #94a3b8;
  }
  
  .sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.97);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .sidebar-actions {
    margin-top: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  .btn-primary, .btn-secondary {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
  }
  
  .btn-primary {
    background: var(--primary-color);
    color: #fff;
  }
  
  .btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  }
  
  .btn-secondary {
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid #cbd5e1;
  }
  
  .btn-secondary:hover {
    background: #e2e8f0;
  }
  
  .btn-primary:active, .btn-secondary:active {
    transform: translateY(0) scale(0.98);
  }

  /* Word export buttons */
  .word-export-row {
    display: flex;
    gap: 10px;
  }
  .btn-word {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: #2b579a; /* Word blue */
    color: #fff;
  }
  .btn-word:hover {
    background: #1e3f70;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(43, 87, 154, 0.25);
  }
  .btn-word:active {
    transform: translateY(0) scale(0.98);
  }
  .btn-word-alt {
    background: #41a5ee; /* lighter Word blue */
  }
  .btn-word-alt:hover {
    background: #2b8fd9;
    box-shadow: 0 4px 12px rgba(65, 165, 238, 0.25);
  }
  .btn-word:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
  }

  /* Merge Section */
  .merge-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px dashed var(--border-color);
    margin-top: 2px;
  }

  .merge-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .merge-label::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
  }

  .upload-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border: 1.5px dashed #cbd5e1;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: #f8fafc;
    transition: all 0.2s ease;
    user-select: none;
  }

  .upload-area:hover {
    border-color: var(--primary-color);
    background: #f5f3ff;
    color: var(--primary-color);
  }

  .upload-area.has-file {
    border-style: solid;
    border-color: #22c55e;
    background: #f0fdf4;
    color: #16a34a;
    font-weight: 600;
  }

  .btn-merge {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: #fff;
    letter-spacing: 0.01em;
  }

  .btn-merge:hover:not(:disabled) {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.3);
  }

  .btn-merge:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
  }

  .btn-merge:disabled {
    opacity: 0.35;
    cursor: not-allowed;
  }

  /* ==========================================================================
     Preview Area (Wrapper for A4)
     ========================================================================== */
  .preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .preview-toolbar {
    height: 60px;
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    font-size: 1rem;
    font-weight: 600;
    backdrop-filter: blur(12px);
  }

  .zoom-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  }
  
  .zoom-controls button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
    color: var(--text-main);
  }
  
  .zoom-controls button:hover {
    background: #f1f5f9;
  }
  
  .preview-wrapper {
    flex: 1;
    overflow: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }

  /* ==========================================================================
     EXACT HTML TEMPLATE STYLES (A4, Times New Roman, specific fonts)
     ========================================================================== */
  
  #template-root {
    transform-origin: top center;
    transition: transform 0.2s ease;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1), 0 5px 15px rgba(0,0,0,0.05);
  }
  
  #template-root .page {
    /* A4 dimensions at 96 DPI */
    width: 794px;
    min-height: 1123px;
    background: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Times New Roman to perfectly match standard academic reports */
    font-family: "Times New Roman", Times, serif;
    color: #000;
    padding: 18px;
  }
  
  /* Double Border */
  #template-root .page-border-outer {
    flex: 1;
    border: 4px solid #000;
    padding: 4px;
    display: flex;
    flex-direction: column;
  }

  #template-root .page-border-inner {
    flex: 1;
    border: 2px solid #000;
    padding: 50px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  /* ── Header ── */
  #template-root .header {
    text-align: center;
    margin-bottom: 25px;
    width: 100%;
    line-height: 1.5;
  }
  
  #template-root .college-name {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
  }
  
  #template-root .university-name {
    font-size: 16px;
    margin-bottom: 4px;
  }
  
  #template-root .autonomous-badge {
    font-size: 15px;
    margin-bottom: 10px;
  }
  
  /* ── Logos ── */
  #template-root .logo-container {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  #template-root .vtu-container {
    margin-bottom: 30px;
  }

  #template-root .vtu-logo {
    height: 125px;
    width: auto;
    object-fit: contain;
  }

  #template-root .dbit-container {
    margin: 40px 0 20px 0;
  }

  #template-root .dbit-logo {
    height: 130px;
    width: auto;
    object-fit: contain;
  }
  
  /* ── Topic Section ── */
  #template-root .topic-section {
    text-align: center;
    margin-bottom: 25px;
    width: 100%;
    line-height: 1.6;
  }

  #template-root .report-topic {
    font-size: 18px;
    margin-bottom: 8px;
  }

  #template-root .subject-name {
    font-size: 18px;
    font-weight: bold;
  }
  
  /* ── Degree Info ── */
  #template-root .degree-info {
    text-align: center;
    margin-bottom: 20px;
    font-size: 18px;
    line-height: 1.8;
  }
  
  /* ── Submitted By Section ── */
  #template-root .submitted-by-header {
    font-size: 18px;
    margin-bottom: 8px;
    text-align: left;
  }

  #template-root .footer-columns {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    font-size: 18px;
    line-height: 1.8;
    margin-top: auto; /* Pushes to the bottom */
  }

  #template-root .student-column,
  #template-root .guide-column {
    text-align: left;
  }

  #template-root .info-row {
    margin-bottom: 8px;
  }

  #template-root .info-label {
    display: inline-block;
    min-width: 50px; /* Aligns "Name:" and "Sem:" */
  }

  #template-root .guide-column .info-label {
    min-width: 85px; /* Aligns "Guided By" */
  }

  /* Bold toggle for the Submitted By / Guided By blocks */
  #template-root .footer-columns.bold-text {
    font-weight: 700;
  }
  #template-root .footer-columns.bold-text .submitted-by-header,
  #template-root .footer-columns.bold-text .info-label,
  #template-root .footer-columns.bold-text .info-value {
    font-weight: 700;
  }

  
  /* ==========================================================================
     Activity Book Cover Template
     ========================================================================== */
  .template-picker label { color: var(--primary-color); }

  /* Field groups must reproduce the form's own flex spacing, since wrapping
     the fields moved them out of #generator-form's direct flex children. */
  .tpl-group {
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  #template-root .ab-page {
    /* inherits .page sizing (794x1123, Times New Roman) */
    padding: 0;
  }
  .ab-inner {
    width: 100%;
    min-height: 100%;
    padding: 34px 48px;
    font-family: "Times New Roman", Times, serif;
    color: #000;
  }

  .ab-header {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 6px;
  }
  .ab-header td { vertical-align: middle; }
  .ab-logo-cell { width: 96px; text-align: center; }
  .ab-logo { height: 82px; width: auto; object-fit: contain; }
  .ab-header-text { text-align: center; line-height: 1.5; padding: 0 6px; }
  .ab-trust { font-weight: bold; font-style: italic; font-size: 13px; }
  .ab-college { font-weight: bold; font-size: 23px; letter-spacing: 0.3px; }
  .ab-affil { font-weight: bold; font-size: 15px; }
  .ab-addr { font-size: 14px; }
  .ab-phone { font-size: 14px; }
  .ab-link { color: #1155cc; text-decoration: underline; }

  .ab-title-block { text-align: center; margin-top: 64px; line-height: 1.7; }
  .ab-course { font-weight: bold; font-size: 34px; }
  .ab-code { font-weight: bold; font-size: 30px; }
  .ab-activity { font-weight: bold; font-size: 32px; }

  .ab-year { font-weight: bold; font-size: 17px; margin: 16px 0; }
  .ab-year-top { text-align: center; margin-bottom: 22px; }
  .ab-year-mid { text-align: left; margin: 22px 0 4px; }

  .ab-fields { margin-top: 34px; }
  .ab-row {
    display: flex;
    align-items: flex-end;
    font-size: 16px;
    margin-bottom: 24px;
  }
  .ab-flabel { flex: 0 0 250px; max-width: 250px; }
  .ab-fsep { flex: 0 0 18px; }
  .ab-fval {
    flex: 1;
    border-bottom: 1px solid #000;
    min-height: 19px;
    padding: 0 0 2px 8px;
    white-space: nowrap;
    overflow: hidden;
  }

  /* ==========================================================================
     Mobile Responsiveness
     ========================================================================== */
  @media screen and (max-width: 768px) {
    .app-container {
      flex-direction: column;
      overflow-y: auto;
    }
  
    body {
      overflow-y: auto;
    }
  
    .sidebar {
      width: 100%;
      border-right: none;
      border-bottom: 1px solid var(--border-color);
      flex: none;
    }
  
    #generator-form {
      overflow-y: visible;
    }
  
    .preview-area {
      flex: none;
      overflow: visible;
    }
  
    .preview-wrapper {
      padding: 20px;
      overflow-x: auto;
      justify-content: flex-start;
    }
  
    #template-root {
      transform-origin: top left;
      /* Scaling handled in JS */
    }
    
    .preview-toolbar {
      /* Ensure toolbar doesn't overlap weirdly */
      z-index: 10;
      position: sticky;
      top: 0;
    }
  }

  /* ==========================================================================
     Template Chooser Intro (first-visit overlay)
     ========================================================================== */
  .tpl-intro {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
  }
  .tpl-intro.show { display: flex; }

  .tpl-intro-card {
    background: #fff;
    border-radius: 20px;
    padding: 36px 32px;
    width: min(94vw, 760px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
    animation: tpl-pop 0.18s ease;
  }
  @keyframes tpl-pop {
    from { transform: translateY(8px) scale(0.98); opacity: 0; }
    to   { transform: none; opacity: 1; }
  }
  .tpl-intro-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 6px;
    letter-spacing: -0.5px;
  }
  .tpl-intro-card > p {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 24px;
  }
  .tpl-intro-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  .tpl-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    text-align: left;
    padding: 22px 18px;
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    background: #f8fafc;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s ease;
  }
  .tpl-option:hover {
    border-color: var(--primary-color);
    background: #fff;
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(79, 70, 229, 0.15);
  }
  .tpl-option.selected {
    border-color: var(--primary-color);
    background: #eef2ff;
  }
  .tpl-option-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 11px;
    background: #e0e7ff;
    color: var(--primary-color);
  }
  .tpl-option-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
  }
  .tpl-option-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
  }
  @media screen and (max-width: 680px) {
    .tpl-intro { padding: 12px; align-items: flex-start; }
    .tpl-intro-card { padding: 22px 18px; border-radius: 16px; max-height: calc(100vh - 24px); }
    .tpl-intro-card h2 { font-size: 1.25rem; }
    .tpl-intro-card > p { font-size: 0.85rem; margin-bottom: 18px; }
    .tpl-intro-options { grid-template-columns: 1fr; gap: 12px; }
    .tpl-option {
      flex-direction: row;
      align-items: center;
      flex-wrap: wrap;
      padding: 16px;
      gap: 8px 14px;
    }
    .tpl-option:hover { transform: none; }
    .tpl-option-icon { width: 38px; height: 38px; flex: 0 0 38px; }
    .tpl-option-title { flex: 1; font-size: 0.95rem; }
    .tpl-option-desc { flex-basis: 100%; }
  }
