/* ============================================
   CV Builder - Page Specific Styles
   ============================================ */

/* Builder Main Layout */
.builder-main {
    min-height: calc(100vh - var(--header-height) - 60px);
    background-color: var(--color-gray-50);
    padding: var(--spacing-md);
}

@media (min-width: 768px) {
    .builder-main {
        padding: var(--spacing-lg);
    }
}

.builder-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
    max-width: 1400px;
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .builder-container {
        grid-template-columns: 1fr 1fr;
    }
}

/* Form Section */
.builder-form {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

.form-header {
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--color-gray-200);
}

.form-header h1 {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--spacing-xs);
}

.form-header p {
    color: var(--color-gray-500);
    font-size: var(--font-size-sm);
}

.change-template-link {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-gray-100);
    border-radius: var(--radius-full);
    color: var(--color-gray-600);
    font-size: var(--font-size-sm);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.change-template-link:hover {
    background: var(--color-primary);
    color: white;
}

body.dark-theme .change-template-link {
    background: #2a3a5a;
    color: #94a3b8;
}

body.dark-theme .change-template-link:hover {
    background: var(--color-primary);
    color: white;
}

/* Form Sections */
.form-section {
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--color-gray-100);
}

.form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--font-size-lg);
    margin-bottom: var(--spacing-md);
    color: var(--color-gray-800);
}

.section-icon {
    font-size: var(--font-size-xl);
}

.section-hint {
    font-size: var(--font-size-sm);
    color: var(--color-gray-500);
    margin-bottom: var(--spacing-md);
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
}

@media (min-width: 640px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Form Groups */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-group label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-gray-700);
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: inherit;
    font-size: var(--font-size-base);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-md);
    background-color: var(--color-white);
    transition: all var(--transition-fast);
    min-height: 44px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--color-gray-400);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-gray-500);
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-error);
    display: none;
}

.form-error.show {
    display: block;
}

.char-count {
    font-size: var(--font-size-xs);
    color: var(--color-gray-400);
    text-align: right;
}

/* Repeatable Items */
.repeatable-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.repeatable-item {
    background: var(--color-gray-50);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    position: relative;
}

.repeatable-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.repeatable-item-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-gray-700);
}

.btn-remove {
    background: none;
    border: none;
    color: var(--color-error);
    font-size: var(--font-size-sm);
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.btn-remove:hover {
    background: rgba(239, 68, 68, 0.1);
}

.repeatable-item .form-grid {
    margin-bottom: var(--spacing-sm);
}

/* Date Range */
.date-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

/* Add Button */
.btn-add {
    width: 100%;
    border-style: dashed;
}

/* Preview Section */
.builder-preview {
    position: relative;
}

@media (min-width: 1024px) {
    .builder-preview {
        position: sticky;
        top: calc(var(--header-height) + var(--spacing-lg));
        height: fit-content;
        max-height: calc(100vh - var(--header-height) - var(--spacing-xl));
    }
}

.preview-header {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    background: var(--color-white);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

@media (min-width: 640px) {
    .preview-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.preview-header h2 {
    font-size: var(--font-size-lg);
    margin: 0;
}

.preview-actions {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.export-hint {
    font-size: var(--font-size-xs);
    color: var(--color-gray-500);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

/* Mobile Preview Toggle */
.mobile-preview-toggle {
    display: block;
    width: 100%;
    margin-bottom: var(--spacing-md);
}

@media (min-width: 1024px) {
    .mobile-preview-toggle {
        display: none;
    }
}

/* Preview Wrapper */
.preview-wrapper {
    background: var(--color-gray-200);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    overflow: auto;
    max-height: 70vh;
}

@media (min-width: 1024px) {
    .preview-wrapper {
        max-height: calc(100vh - var(--header-height) - 200px);
    }
}

/* Mobile: Hidden by default */
@media (max-width: 1023px) {
    .preview-wrapper {
        display: none;
    }
    
    .preview-wrapper.show {
        display: block;
    }
}

/* CV Preview (A4 Style) */
.cv-preview {
    background: var(--color-white);
    width: 100%;
    max-width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 15mm 20mm;
    box-shadow: var(--shadow-lg);
    font-size: 10pt;
    line-height: 1.5;
    color: var(--color-gray-800);
}

/* CV Header */
.cv-header {
    text-align: center;
    margin-bottom: 8mm;
    padding-bottom: 6mm;
    border-bottom: 2px solid var(--color-primary);
}

.cv-name {
    font-size: 24pt;
    font-weight: 700;
    color: var(--color-gray-900);
    margin-bottom: 2mm;
}

.cv-title {
    font-size: 12pt;
    color: var(--color-primary);
    margin-bottom: 4mm;
}

.cv-contact {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4mm;
    font-size: 9pt;
    color: var(--color-gray-600);
}

.cv-contact-item {
    display: flex;
    align-items: center;
    gap: 1mm;
}

.cv-contact-item::before {
    content: '•';
    color: var(--color-gray-400);
    margin-right: 1mm;
}

.cv-contact-item:first-child::before {
    display: none;
}

/* CV Sections */
.cv-section {
    margin-bottom: 6mm;
}

.cv-section-title {
    font-size: 11pt;
    font-weight: 700;
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3mm;
    padding-bottom: 1.5mm;
    border-bottom: 1px solid var(--color-gray-200);
}

.cv-summary {
    font-size: 10pt;
    color: var(--color-gray-700);
    text-align: justify;
}

/* CV Entry (Experience/Education) */
.cv-entry {
    margin-bottom: 4mm;
}

.cv-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1mm;
}

.cv-entry-title {
    font-weight: 600;
    font-size: 10pt;
    color: var(--color-gray-900);
}

.cv-entry-subtitle {
    font-size: 9pt;
    color: var(--color-gray-600);
}

.cv-entry-date {
    font-size: 9pt;
    color: var(--color-gray-500);
    white-space: nowrap;
}

.cv-entry-description {
    font-size: 9pt;
    color: var(--color-gray-700);
    margin-top: 1mm;
}

/* CV Skills */
.cv-skills {
    display: flex;
    flex-wrap: wrap;
    gap: 2mm;
}

.cv-skill-tag {
    background: var(--color-gray-100);
    padding: 1mm 3mm;
    border-radius: 2mm;
    font-size: 9pt;
    color: var(--color-gray-700);
}

/* CV Languages */
.cv-language {
    display: flex;
    justify-content: space-between;
    padding: 1mm 0;
    border-bottom: 1px dotted var(--color-gray-200);
}

.cv-language:last-child {
    border-bottom: none;
}

.cv-language-name {
    font-weight: 500;
}

.cv-language-level {
    color: var(--color-gray-500);
}

/* Builder Footer */
.builder-footer {
    background: var(--color-gray-100);
    padding: var(--spacing-md);
    text-align: center;
}

.builder-footer p {
    font-size: var(--font-size-sm);
    color: var(--color-gray-600);
    margin: 0;
}

/* Validation States */
input.invalid,
textarea.invalid {
    border-color: var(--color-error);
}

input.valid,
textarea.valid {
    border-color: var(--color-success);
}

/* Animation for adding items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.repeatable-item {
    animation: slideIn 0.3s ease;
}

/* Language Select Styling */
.language-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--spacing-lg);
    color: var(--color-gray-400);
    font-size: var(--font-size-sm);
}

/* Responsive Adjustments for CV Preview on Mobile */
@media (max-width: 640px) {
    .cv-preview {
        padding: 8mm 10mm;
        font-size: 9pt;
    }
    
    .cv-name {
        font-size: 18pt;
    }
    
    .cv-title {
        font-size: 10pt;
    }
    
    .cv-contact {
        flex-direction: column;
        gap: 1mm;
    }
    
    .cv-contact-item::before {
        display: none;
    }
    
    .cv-entry-header {
        flex-direction: column;
    }
    
    .cv-entry-date {
        margin-top: 1mm;
    }
}

/* Print Overrides */
@media print {
    .builder-main {
        padding: 0;
        background: white;
    }
    
    .builder-form,
    .preview-header,
    .export-hint,
    .mobile-preview-toggle,
    .builder-footer,
    .header,
    .modal-overlay {
        display: none !important;
    }
    
    .builder-container {
        display: block;
    }
    
    .preview-wrapper {
        display: block !important;
        background: none;
        padding: 0;
        max-height: none;
        overflow: visible;
    }
    
    .cv-preview {
        box-shadow: none;
        margin: 0;
        padding: 10mm 15mm;
    }
}

/* ============================================
   Modal Styles
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing-md);
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow: auto;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--color-gray-200);
}

.modal-header h3 {
    margin: 0;
    font-size: var(--font-size-lg);
    color: var(--color-gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    color: var(--color-gray-500);
    cursor: pointer;
    padding: var(--spacing-xs);
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-gray-100);
    color: var(--color-gray-900);
}

.modal-body {
    padding: var(--spacing-lg);
}

/* Color Picker Styles */
.color-picker-group {
    margin-bottom: var(--spacing-lg);
}

.color-picker-group label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--color-gray-800);
}

.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.color-input-wrapper input[type="color"] {
    width: 60px;
    height: 44px;
    padding: 2px;
    border: 2px solid var(--color-gray-300);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: none;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.color-value {
    font-family: monospace;
    font-size: var(--font-size-sm);
    color: var(--color-gray-600);
    background: var(--color-gray-100);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
}

.color-hint {
    font-size: var(--font-size-xs);
    color: var(--color-gray-500);
    margin-top: var(--spacing-xs);
}

/* ============================================
   Dark Theme Styles
   ============================================ */

body.dark-theme {
    --color-white: #1a1a2e;
    --color-gray-50: #16213e;
    --color-gray-100: #1f2b47;
    --color-gray-200: #2a3a5a;
    --color-gray-300: #3d4f6f;
    --color-gray-400: #6b7a99;
    --color-gray-500: #8b9ab8;
    --color-gray-600: #a8b5cc;
    --color-gray-700: #c5cfe0;
    --color-gray-800: #e1e7f0;
    --color-gray-900: #f5f7fa;
}

body.dark-theme .header {
    background-color: #16213e;
    border-bottom-color: #2a3a5a;
}

body.dark-theme .logo {
    color: #f5f7fa;
}

body.dark-theme .btn-secondary {
    background-color: #2a3a5a;
    color: #c5cfe0;
}

body.dark-theme .btn-secondary:hover {
    background-color: #3d4f6f;
}

body.dark-theme .builder-form {
    background: #1f2b47;
}

body.dark-theme .form-section {
    border-bottom-color: #2a3a5a;
}

body.dark-theme .form-header {
    border-bottom-color: #2a3a5a;
}

body.dark-theme .form-group input,
body.dark-theme .form-group textarea,
body.dark-theme .form-group select {
    background-color: #16213e;
    border-color: #3d4f6f;
    color: #e1e7f0;
}

body.dark-theme .form-group input::placeholder,
body.dark-theme .form-group textarea::placeholder {
    color: #6b7a99;
}

body.dark-theme .repeatable-item {
    background: #16213e;
    border-color: #2a3a5a;
}

body.dark-theme .preview-header {
    background: #1f2b47;
}

body.dark-theme .preview-wrapper {
    background: #0f0f23;
}

body.dark-theme .builder-footer {
    background: #16213e;
}

body.dark-theme .modal {
    background: #1f2b47;
}

body.dark-theme .modal-header {
    border-bottom-color: #2a3a5a;
}

body.dark-theme .modal-close:hover {
    background: #2a3a5a;
}

body.dark-theme .color-value {
    background: #16213e;
    color: #a8b5cc;
}

/* CV Preview stays light in dark theme for print accuracy */
body.dark-theme .cv-preview {
    background: #ffffff;
    color: #1e293b;
}

body.dark-theme .cv-preview .cv-name {
    color: #1e293b;
}

body.dark-theme .cv-preview .cv-section-title {
    color: var(--cv-heading-color, #2563eb);
}

body.dark-theme .cv-preview .cv-entry-title {
    color: #1e293b;
}

body.dark-theme .cv-preview .cv-skill-tag {
    background: #f1f5f9;
    color: #475569;
}

/* ============================================
   CV Custom Colors (applied via JS)
   ============================================ */

.cv-preview {
    --cv-heading-color: #2563eb;
    --cv-text-color: #1e293b;
}

.cv-header {
    border-bottom-color: var(--cv-heading-color);
}

.cv-title {
    color: var(--cv-heading-color);
}

.cv-section-title {
    color: var(--cv-heading-color);
}

.cv-name,
.cv-entry-title {
    color: var(--cv-text-color);
}

.cv-summary,
.cv-entry-description {
    color: var(--cv-text-color);
    opacity: 0.85;
}

/* ============================================
   Header Nav Responsive
   ============================================ */

.header .nav {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .header .nav {
        gap: var(--spacing-xs);
    }
    
    .header .nav .btn-sm {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-xs);
    }
}

/* ============================================
   Template Selector Styles
   ============================================ */

.template-selector-section {
    background: var(--color-gray-50);
    margin: calc(-1 * var(--spacing-lg));
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-sm);
}

@media (max-width: 900px) {
    .template-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 500px) {
    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: var(--color-white);
    border: 2px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.template-card:hover {
    border-color: var(--color-primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.template-card.active {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.05);
}

.template-card.active::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--color-primary);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-card {
    position: relative;
}

.template-preview {
    width: 100%;
    aspect-ratio: 210/297;
    background: white;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

/* Template Preview Thumbnails */
.tp-default {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}
.tp-default::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    height: 3px;
    background: #2563eb;
}
.tp-default::after {
    content: '';
    position: absolute;
    top: 25%;
    left: 10%;
    right: 10%;
    height: 60%;
    background: repeating-linear-gradient(
        180deg,
        #e2e8f0 0px,
        #e2e8f0 2px,
        transparent 2px,
        transparent 8px
    );
}

.tp-sage {
    display: grid;
    grid-template-columns: 35% 1fr;
}
.tp-sage::before {
    content: '';
    background: #a8b5a0;
}
.tp-sage::after {
    content: '';
    background: white;
}

.tp-navy {
    background: white;
}
.tp-navy::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 25%;
    background: #1e3a5f;
}

.tp-blue-frame::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    height: 10%;
    border: 2px solid #4a90d9;
}

.tp-gold::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 0;
    right: 0;
    height: 3px;
    background: #8b7355;
}

.tp-blue-pro::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 10%;
    right: 10%;
    height: 8%;
    background: #0066b3;
}

.tp-navy-side {
    display: grid;
    grid-template-columns: 40% 1fr;
}
.tp-navy-side::before {
    content: '';
    background: #1e3a5f;
}
.tp-navy-side::after {
    content: '';
    background: white;
}

.tp-creative {
    background: white;
}
.tp-creative::before {
    content: '';
    position: absolute;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 10%;
    background: #333;
}
.tp-creative::after {
    content: '';
    position: absolute;
    top: 3%;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border: 1px solid #333;
    border-radius: 50%;
}

.tp-classic {
    background: white;
}
.tp-classic::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 10%;
    right: 10%;
    height: 2px;
    background: #222;
}

.tp-elegant {
    background: linear-gradient(180deg, #fdf5f3 0%, #fff 100%);
}
.tp-elegant::before {
    content: '';
    position: absolute;
    top: 18%;
    left: 30%;
    right: 30%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #e8ddd8, transparent);
}

.template-name {
    font-size: var(--font-size-xs);
    color: var(--color-gray-600);
    text-align: center;
    font-weight: 500;
}

/* Dark theme adjustments for template selector */
body.dark-theme .template-selector-section {
    background: #16213e;
}

body.dark-theme .template-card {
    background: #1f2b47;
    border-color: #2a3a5a;
}

body.dark-theme .template-card:hover {
    border-color: var(--color-primary-light);
}

body.dark-theme .template-card.active {
    background: rgba(37, 99, 235, 0.15);
}

body.dark-theme .template-preview {
    border-color: #2a3a5a;
}

body.dark-theme .template-name {
    color: #a8b5cc;
}

