:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg-color: #020617;
    --card-bg: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #1e293b;
    --primary-color: #818cf8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(79, 70, 229, 0.05) 0px, transparent 50%);
    color: var(--text-main);
    transition: background-color 0.3s ease;
    line-height: 1.5;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    height: 100vh;
}

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
        height: auto;
        gap: 1.5rem;
    }

    .preview-section {
        position: relative;
        top: 0;
        height: auto;
    }

    .resume-paper {
        transform-origin: top center;
    }
}

@media (max-width: 640px) {
    .app-container {
        padding: 1rem;
    }

    .form-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .form-header>div {
        width: 100%;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .res-btn-group {
        flex-direction: column;
    }
}

/* Form Section */
.form-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 1rem;
}

.section-card {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.section-title {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

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

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

input,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    cursor: pointer;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--border-color);
}

.add-btn {
    margin-top: 1rem;
    width: 100%;
    justify-content: center;
    border-style: dashed;
}

/* Preview Section */
.preview-section {
    position: sticky;
    top: 2rem;
    height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    align-items: center;
}

#captureArea {
    width: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

.resume-paper {
    background: white;
    width: 210mm;
    height: 296mm;
    /* Strictly 296mm to avoid 297mm overflow */
    max-height: 296mm;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    overflow: hidden !important;
    /* Force content to stay inside */
    position: relative;
    padding: 0;
    color: #1e293b;
    transform-origin: top center;
    page-break-after: avoid;
    /* Prevent new page after this */
}

@media (max-width: 1400px) {
    .resume-paper {
        transform: scale(0.75);
        margin-bottom: -250px;
    }
}

@media (max-width: 1200px) {
    .resume-paper {
        transform: scale(0.60);
        margin-bottom: -400px;
    }

    .app-container {
        gap: 1.5rem;
    }
}

/* Modern Resume Template Styles */
.resume-container {
    height: 100%;
    min-height: 296mm;
    max-height: 296mm;
    display: flex;
    /* Switched to flex for better capture compatibility */
    width: 100%;
}

.sidebar {
    background: #1e293b;
    color: white;
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 32%;
    height: 100%;
}

.main-content {
    width: 68%;
    padding: 2.5rem 2.5rem;
    /* Reduced padding slightly to fit content */
    background: #fff;
    height: 100%;
    overflow: hidden;
}

/* Sidebar is now flex-based above */

.profile-img-container {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 1.5rem;
    background: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar h2 {
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 2rem;
    color: white;
}

.sidebar-section {
    width: 100%;
    margin-bottom: 2rem;
}

.sidebar-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.sidebar-content {
    font-size: 0.85rem;
    word-break: break-word;
}

/* Main content now flex-based above */

.resume-header {
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
}

.resume-header h1 {
    font-size: 2.5rem;
    color: #0f172a;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.resume-header p {
    color: var(--primary-color);
    font-weight: 600;
    letter-spacing: 2px;
}

.resume-section {
    margin-bottom: 1.5rem;
}

.resume-section-title {
    font-size: 1.1rem;
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.experience-item,
.education-item {
    margin-bottom: 1rem;
}

.item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.item-title {
    font-weight: 700;
    color: #0f172a;
}

.item-date {
    font-size: 0.85rem;
    color: #64748b;
}

.item-desc {
    font-size: 0.9rem;
    color: #334155;
}

/* UI Elements */
.theme-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-main);
}

.hidden-inputs {
    position: fixed;
    top: -100px;
    visibility: hidden;
}

.upload-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.2rem;
    text-align: center;
    font-size: 0.7rem;
    cursor: pointer;
}

@media print {
    body {
        background: white;
    }

    .form-section,
    .preview-controls,
    .theme-toggle {
        display: none !important;
    }

    .app-container {
        display: block;
        padding: 0;
        margin: 0;
    }

    .preview-section {
        position: static;
        height: auto;
        padding: 0;
    }

    .resume-paper {
        box-shadow: none;
        transform: scale(1) !important;
        width: 210mm !important;
        height: 296mm !important;
        max-height: 296mm !important;
        margin: 0 !important;
        position: relative !important;
        display: block !important;
        visibility: visible !important;
        overflow: hidden !important;
        page-break-after: avoid !important;
    }

    /* Target all elements to avoid breaking if possible */
    * {
        page-break-inside: auto;
    }
}

/* Printing logic to fix mobile capture */
body.is-exporting {
    overflow: hidden !important;
    height: 100vh !important;
}

body.is-exporting .resume-paper {
    transform: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 99999 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
}

/* Fix for page breaks in PDF */
.resume-section {
    page-break-inside: avoid;
    break-inside: avoid;
}

.experience-item,
.education-item,
.project-entry {
    page-break-inside: avoid;
    break-inside: avoid;
}

/* Font Moods */
.font-classic {
    font-family: 'Playfair Display', serif;
}

.font-modern {
    font-family: 'Inter', sans-serif;
}

.font-elegant {
    font-family: 'Outfit', sans-serif;
}

/* Skill Bars */
.skill-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 4px;
}

.skill-bar-fill {
    height: 100%;
    background: white;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.main-content .skill-bar-container {
    background: #e2e8f0;
}

.main-content .skill-bar-fill {
    background: var(--primary-color);
}

/* QR Code */
#qrCodeContainer {
    position: absolute;
    bottom: 2rem;
    right: 3rem;
    width: 80px;
    height: 80px;
}

.sidebar #qrCodeContainer {
    position: static;
    margin-top: 2rem;
    width: 100px;
    height: 100px;
}

/* ATS Suggestions Box */
.ats-box {
    background: rgba(79, 70, 229, 0.05);
    border: 1px dashed var(--primary-color);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.85rem;
}

.keyword-tag {
    display: inline-block;
    padding: 2px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin: 2px;
    cursor: pointer;
    transition: all 0.2s;
}

.keyword-tag:hover {
    background: var(--primary-color);
    color: white;
}

.lang-entry,
.skill-entry {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Button Group */
.btn-group {
    display: flex;
    gap: 10px;
}

@media (max-width: 1024px) {

    /* Already handled in previous block, adding specific overrides if needed */
    .resume-paper {
        transform: scale(0.65);
        margin-bottom: -350px;
    }
}

@media (max-width: 768px) {
    .resume-paper {
        transform: scale(0.55);
        margin-bottom: -450px;
    }

    .btn-group {
        flex-direction: column;
    }

    .lang-entry,
    .skill-entry {
        flex-wrap: wrap;
    }

    .lang-entry input,
    .lang-entry select,
    .skill-entry input,
    .skill-entry input[type="range"] {
        flex: 1 1 100%;
        width: 100%;
    }
}

@media (max-width: 600px) {
    .resume-paper {
        transform: scale(0.45);
        margin-bottom: -600px;
    }
}

@media (max-width: 450px) {
    .resume-paper {
        transform: scale(0.38);
        margin-bottom: -680px;
    }

    .section-title {
        font-size: 1.1rem;
    }

    h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 360px) {
    .resume-paper {
        transform: scale(0.32);
        margin-bottom: -750px;
    }
}