:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #0f172a;
    --sidebar-bg: rgba(30, 41, 59, 0.85);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Cover Page Variables - Defaults */
    --cp-font-heading: 'Montserrat', sans-serif;
    --cp-font-body: 'Inter', sans-serif;
    --cp-text: #000000;
    --cp-bg: #ffffff;
    --cp-accent: #000000;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    background-image: radial-gradient(circle at top right, #312e81 0%, #0f172a 50%);
}

/* Mobile Top Bar - hidden on desktop */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 56px;
    background: rgba(30, 41, 59, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.mobile-title {
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.3px;
}

/* Hamburger Button */
.hamburger-btn {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
    transition: background 0.2s;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.13); }
.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: #f8fafc;
    border-radius: 2px;
    transition: all 0.3s;
}

/* Sidebar Close Button */
.sidebar-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar-close-btn {
    display: none;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #f8fafc;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.sidebar-close-btn:hover { background: rgba(255,100,100,0.2); }

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 49;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 420px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    height: 100%;
    overflow-y: auto;
    padding: 2.5rem 2rem;
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}

.sidebar-header h2 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.sidebar-header p {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-weight: 400;
}

.form-section {
    background: rgba(255, 255, 255, 0.03);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 0 20px rgba(255,255,255,0.01);
}

.form-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.2rem;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-section h3::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-color);
}

.form-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    color: #cbd5e1;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-group.half {
    flex: 1;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(0,0,0,0.2);
    color: #f8fafc;
}

input[type="file"] {
    padding: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: rgba(255,255,255,0.05);
}

input[type="file"]::-webkit-file-upload-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 4px;
    margin-right: 1rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: var(--primary-hover);
}

input:hover, select:hover {
    border-color: rgba(255,255,255,0.2);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(0,0,0,0.4);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
    transform: translateY(-1px);
}

select option {
    background: #1e293b;
    color: white;
}

.template-selector {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.template-btn {
    flex: 1 1 30%;
    padding: 0.75rem 0.5rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.template-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    transform: translateY(-2px);
}

.template-btn.active {
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

button[class^="btn-"] {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-secondary {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    border-color: white;
}

/* Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    padding: 2rem;
    background: transparent;
}

.preview-scaler {
    position: relative;
    /* width and height will be set by JS */
}

.preview-wrapper {
    /* Scale logic will be handled by JS or CSS transform */
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    background: white;
    /* A4 dimensions at 96dpi */
    width: 794px;
    height: 1123px;
    flex-shrink: 0;
    transform-origin: top left;
    position: absolute;
    top: 0;
    left: 0;
}

/* A4 Page Base Styles */
.cover-page {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--cp-bg);
    color: var(--cp-text);
    padding: 3rem; /* roughly ~1 inch safe zone */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    overflow: hidden;
}

#t-logo {
    max-height: 120px;
    max-width: 160px;
    object-fit: contain;
}

/* --------------------------------------
   TEMPLATE 1: MINIMAL PROFESSIONAL
   -------------------------------------- */
.minimal {
    --cp-font-heading: 'Montserrat', sans-serif;
    --cp-font-body: 'Inter', sans-serif;
    --cp-text: #111827;
    --cp-bg: #ffffff;
    --cp-accent: #374151;
    text-align: center;
}

.minimal .page-border {
    display: none;
}

.minimal .cover-header {
    margin-top: 2rem;
}

.minimal .logo-placeholder {
    color: var(--cp-accent);
    margin-bottom: 1.5rem;
}

.minimal .t-uni-name {
    font-family: var(--cp-font-heading);
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.minimal .t-dept-name {
    font-family: var(--cp-font-body);
    font-size: 16px;
    font-weight: 500;
    color: #4b5563;
}

.minimal .cover-title {
    margin: 2rem 0;
    padding: 1rem 0;
}

.minimal .badge {
    display: inline-block;
    padding: 6px 16px;
    background: var(--cp-accent);
    color: white;
    font-family: var(--cp-font-heading);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    border-radius: 4px;
    margin-bottom: 0;
}

.minimal .t-course-title {
    font-family: var(--cp-font-heading);
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 1rem;
}

.minimal .t-exp-name {
    font-family: var(--cp-font-body);
    font-size: 20px;
    font-weight: 400;
    color: #1f2937;
}

.minimal .cover-info {
    text-align: left;
    max-width: 500px;
    margin: 0 auto;
    font-family: var(--cp-font-body);
    font-size: 15px;
    line-height: 1.8;
}

.minimal .info-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed #d1d5db;
    padding: 4px 0;
}

.minimal .info-row .label {
    font-weight: 600;
    color: #374151;
}

.minimal .cover-submission {
    display: flex;
    justify-content: space-between;
    text-align: left;
    margin-top: 4rem;
    font-family: var(--cp-font-body);
    font-size: 14px;
    line-height: 1.6;
}

.minimal .submitted-by h5, .minimal .submitted-to h5 {
    font-family: var(--cp-font-heading);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 1rem;
    text-transform: uppercase;
    color: var(--cp-accent);
}

.minimal .submitted-by .name, .minimal .submitted-to .name {
    font-weight: 600;
    font-size: 16px;
}

.minimal .cover-footer {
    display: none;
}

/* --------------------------------------
   TEMPLATE 2: TECH STYLE
   -------------------------------------- */
.tech {
    --cp-font-heading: 'Montserrat', sans-serif;
    --cp-font-body: 'Roboto Mono', monospace;
    --cp-text: #0f172a;
    --cp-bg: #ffffff;
    --cp-accent: #2563eb;
}

.tech::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 12px;
    background: linear-gradient(90deg, #2563eb, #0ea5e9, #38bdf8);
}
.tech::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0; height: 12px;
    background: linear-gradient(90deg, #2563eb, #0ea5e9, #38bdf8);
}

.tech .page-border {
    position: absolute;
    top: 30px; left: 30px; right: 30px; bottom: 30px;
    border: 1px solid #e2e8f0;
    pointer-events: none;
}

.tech .cover-header {
    text-align: right;
    margin-top: 2rem;
    position: relative;
    padding-right: 1.5rem;
    border-right: 4px solid var(--cp-accent);
}

.tech .logo-placeholder {
    display: block;
    margin-bottom: 1rem;
}

.tech .t-uni-name {
    font-family: var(--cp-font-heading);
    font-size: 24px;
    font-weight: 800;
    color: var(--cp-accent);
}

.tech .t-dept-name {
    font-family: var(--cp-font-body);
    font-size: 14px;
    color: #64748b;
    margin-top: 0.5rem;
}

.tech .cover-title {
    margin: 2rem 0;
    background: #f8fafc;
    padding: 1rem;
}

.tech .badge {
    display: inline-block;
    padding: 4px 12px;
    border: 1px solid var(--cp-accent);
    color: var(--cp-accent);
    font-family: var(--cp-font-body);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 0;
    text-transform: uppercase;
}

.tech .t-course-title {
    font-family: var(--cp-font-heading);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.tech .t-exp-name {
    font-family: var(--cp-font-body);
    font-size: 18px;
    color: #334155;
}

.tech .cover-info {
    font-family: var(--cp-font-body);
    font-size: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.tech .info-row {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 4px;
}

.tech .info-row .label {
    display: block;
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.tech .info-row .value {
    font-weight: 600;
    color: #0f172a;
}

.tech .cover-submission {
    display: flex;
    justify-content: space-between;
    font-family: var(--cp-font-body);
    font-size: 13px;
    line-height: 1.6;
}

.tech .submitted-by, .tech .submitted-to {
    flex: 1;
}

.tech .submitted-by h5, .tech .submitted-to h5 {
    color: var(--cp-accent);
    margin-bottom: 0.5rem;
    font-size: 14px;
    text-transform: uppercase;
}

.tech .name {
    font-weight: 600;
    font-size: 15px;
    color: #0f172a;
    margin-bottom: 0.25rem;
}

/* --------------------------------------
   TEMPLATE 3: FORMAL CLASSIC
   -------------------------------------- */
.classic {
    --cp-font-heading: 'Playfair Display', serif;
    --cp-font-body: 'Playfair Display', serif;
    --cp-text: #000000;
    --cp-bg: #ffffff;
    text-align: center;
    padding: 4rem;
}

.classic .page-border {
    position: absolute;
    top: 25px; left: 25px; right: 25px; bottom: 25px;
    border: 3px double #000000;
    pointer-events: none;
}

.classic .page-border::before {
    content: '';
    position: absolute;
    top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 1px solid #000000;
}

.classic .cover-header {
    margin-top: 1rem;
}

.classic .logo-placeholder {
    color: #000000;
    margin-bottom: 1rem;
}

.classic .t-uni-name {
    font-family: var(--cp-font-heading);
    font-size: 26px;
    font-weight: 700;
    text-transform: uppercase;
}

.classic .t-dept-name {
    font-family: var(--cp-font-body);
    font-size: 18px;
    font-style: italic;
    margin-top: 0.5rem;
}

.classic .cover-title {
    margin: 1rem 0;
}

.classic .badge {
    display: block;
    font-family: var(--cp-font-heading);
    font-size: 22px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 0;
    letter-spacing: 2px;
}

.classic .t-course-title {
    font-family: var(--cp-font-heading);
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 1rem;
}

.classic .t-exp-name {
    font-family: var(--cp-font-body);
    font-size: 22px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.classic .cover-info {
    font-family: var(--cp-font-body);
    font-size: 16px;
    margin: 2rem auto;
    width: 80%;
}

.classic .info-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 0.5rem;
}

.classic .info-row .label {
    font-weight: 600;
}

.classic .cover-submission {
    display: flex;
    justify-content: space-around;
    text-align: center;
    margin-top: 4rem;
    font-family: var(--cp-font-body);
    font-size: 16px;
    line-height: 1.5;
}

.classic .submitted-by h5, .classic .submitted-to h5 {
    font-size: 18px;
    font-weight: 700;
    font-style: italic;
    margin-bottom: 1rem;
    position: relative;
    display: inline-block;
}

.classic .submitted-by h5::after, .classic .submitted-to h5::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 20%;
    right: 20%;
    height: 1px;
    background: #000;
}

.classic .name {
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 0.25rem;
}


/* ======================================
   RESPONSIVE — TABLET (≤ 900px)
   ====================================== */
@media (max-width: 900px) {
    body { overflow: auto; }

    .mobile-topbar { display: flex; }

    .sidebar-close-btn { display: flex; align-items: center; justify-content: center; }

    /* Hide duplicate title in sidebar on mobile */
    .sidebar .sidebar-header h2 { display: none; }
    .sidebar .sidebar-header p  { display: none; }
    .sidebar-header-top { margin-bottom: 0; }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        padding-top: 56px;
    }

    .sidebar {
        position: fixed;
        top: 56px;       /* start BELOW the topbar */
        left: 0;
        height: calc(100% - 56px);
        width: 340px;
        max-width: 92vw;
        z-index: 50;
        transform: translateX(-110%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid rgba(255,255,255,0.12);
        overflow-y: auto;
        padding-top: 1.5rem;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Hide the close button row if header is hidden — show only close btn */
    .sidebar-header { gap: 0; }
    .sidebar-header-top {
        justify-content: flex-end;
        margin-bottom: 0.5rem;
    }

    .preview-area {
        width: 100%;
        padding: 1rem;
        min-height: calc(100vh - 56px);
        align-items: flex-start;
        justify-content: center;
        overflow: auto;
    }
}

/* ======================================
   RESPONSIVE — MOBILE (≤ 600px)
   ====================================== */
@media (max-width: 600px) {
    .sidebar { width: 100%; max-width: 100vw; }

    .preview-area {
        padding: 0.75rem 0.5rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .template-selector {
        gap: 0.5rem;
    }

    .template-btn {
        flex: 1 1 100%;
        font-size: 0.85rem;
        padding: 0.65rem 0.5rem;
    }

    .action-buttons {
        flex-direction: row;
        gap: 0.75rem;
    }

    button[class^="btn-"] {
        font-size: 0.9rem;
        padding: 0.85rem 0.5rem;
    }
}

/* Print Styles */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: none !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Hide all UI except the cover page */
    .mobile-topbar,
    .sidebar,
    .sidebar-overlay { display: none !important; }

    /* Reset mobile app-container padding */
    .app-container {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        width: 100% !important;
    }

    /* Preview area fills the page */
    .preview-area {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        background: none !important;
    }

    /* Scaler: reset JS-set dimensions */
    .preview-scaler {
        position: static !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Wrapper: exact A4, no transform/shadow */
    .preview-wrapper {
        position: static !important;
        transform: none !important;
        box-shadow: none !important;
        width: 210mm !important;
        height: 297mm !important;
        overflow: hidden !important;
        page-break-after: avoid;
        margin: 0 auto;
    }

    @page {
        size: A4 portrait;
        margin: 0;
    }
}
