/* Enhanced CSS for vCard QR Generator - Security Enhanced Version */
:root {
    --primary-blue: #4facfe;
    --primary-purple: #764ba2;
    --accent-green: #11998e;
    --accent-light-green: #38ef7d;
    --success-color: #27ae60;
    --error-color: #e74c3c;
    --warning-color: #f39c12;
    --info-color: #3498db;
    --text-dark: #2c3e50;
    --text-muted: #7f8c8d;
    --border-light: #e1e8ed;
    --bg-white: #ffffff;
    --bg-light: #f8f9fa;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.2);
    --border-radius: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-lao: 'Noto Sans Lao', 'Phetsarath OT', 'Saysettha OT', sans-serif;
    --font-system: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Reset and Performance Optimizations */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-lao), var(--font-system);
    margin: 0;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-purple) 100%);
    min-height: 100vh;
    font-feature-settings: "liga", "kern";
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
    color: var(--text-dark);
}

/* Container with improved layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Enhanced Header */
.header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, #00f2fe 100%);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M20 20c0 5.5-4.5 10-10 10s-10-4.5-10-10 4.5-10 10-10 10 4.5 10 10zm10 0c0 5.5-4.5 10-10 10s-10-4.5-10-10 4.5-10 10-10 10 4.5 10 10z'/%3E%3C/g%3E%3C/svg%3E") repeat;
    pointer-events: none;
}
.header h1 {
    font-size: clamp(2rem, 4.2vw, 1.25rem);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    white-space: normal; 
    max-width: 100%;
    font-weight: 700;
    color: white
    line-height: 1.4; 
}

.header h3 {
color: white
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.header>* {
    position: relative;
    z-index: 1;
}


.header-logo {
    width: 120px;
    height: auto;
    margin-bottom: 1rem;
    transition: transform 0.3s ease;
}
/* Enhanced Status Messages */
.status-message {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    margin: 15px 0;
    font-size: 0.9rem;
    line-height: 1.4;
    border: 1px solid;
    transition: var(--transition);
}

.security-notice {
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.3);
    color: #2980b9;
}

.library-status {
    background: rgba(39, 174, 96, 0.1);
    border-color: rgba(39, 174, 96, 0.3);
    color: var(--success-color);
}

.library-status.loading {
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.3);
    color: var(--info-color);
}

.library-status.warning {
    background: rgba(243, 156, 18, 0.1);
    border-color: rgba(243, 156, 18, 0.3);
    color: var(--warning-color);
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    padding: 40px;
    align-items: start;
}

/* Form Styling */
.form-section {
    animation: slideInLeft 0.6s ease-out;
}

fieldset {
    border: 2px solid var(--border-light);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.8);
    transition: var(--transition);
    position: relative;
}

fieldset:hover {
    border-color: var(--primary-blue);
    box-shadow: 0 5px 15px rgba(79, 172, 254, 0.1);
}

fieldset:focus-within {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

legend {
    font-weight: 600;
    color: var(--text-dark);
    padding: 0 15px;
    font-size: 1.2rem;
    background: var(--bg-white);
}

/* Enhanced Form Rows */
.form-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 15px;
}

.form-row label {
    min-width: 180px;
    font-weight: 500;
    color: var(--text-dark);
    padding-top: 12px;
    line-height: 1.4;
}

.required {
    color: var(--error-color);
    font-weight: bold;
}

/* Enhanced Input Styling */
.input-wrapper {
    flex: 1;
    position: relative;
}

.form-row input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-light);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 14px;
    transition: var(--transition);
    background: var(--bg-white);
    line-height: 1.4;
}

.form-row input:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
    transform: translateY(-1px);
}

.form-row input:hover:not(:focus) {
    border-color: #bdc3c7;
}

.form-row input.invalid {
    border-color: var(--error-color);
    background-color: rgba(231, 76, 60, 0.05);
    animation: shake 0.3s ease-in-out;
}

.form-row input.valid {
    border-color: var(--success-color);
    background-color: rgba(39, 174, 96, 0.05);
}

.form-row input::placeholder {
    color: #999;
    opacity: 1;
}

/* Field hint styling */
.field-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
    opacity: 0;
    transform: translateY(-5px);
    transition: var(--transition);
}

.input-wrapper:focus-within .field-hint {
    opacity: 1;
    transform: translateY(0);
}

/* Enhanced Buttons */
.btn {
    border: none;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

.submit-btn {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-purple) 100%);
    color: white;
    padding: 15px 40px;
    font-size: 16px;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    display: block;
    margin: 20px auto 0;
    min-height: 50px;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.download-btn {
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-light-green) 100%);
    color: white;
    padding: 12px 30px;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
    margin-top: 20px;
    min-height: 44px;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(17, 153, 142, 0.6);
}

/* Download Buttons - Uniform Size & Responsive Layout */
.download-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

/* Uniform button group with equal sized buttons */
.download-btn-group-uniform {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

/* Uniform download buttons - same size */
.download-btn.uniform {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-purple) 100%);
    color: white;
    padding: 14px 20px;
    font-size: 13px;
    min-height: 50px;
    border-radius: 25px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

/* Second button gets different gradient */
.download-btn.uniform:nth-child(2) {
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-light-green) 100%);
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
}

.download-btn.uniform:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.6);
}

.download-btn.uniform:nth-child(2):hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(17, 153, 142, 0.6);
}

.download-btn.uniform:active {
    transform: translateY(0);
}

.download-btn.uniform:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Format Info */
.format-info {
    text-align: center;
    margin-top: 10px;
    padding: 10px;
    background: rgba(52, 152, 219, 0.1);
    border-radius: var(--border-radius);
    border: 1px solid rgba(52, 152, 219, 0.2);
}

.format-info small {
    color: var(--info-color);
    line-height: 1.4;
    font-size: 11px;
}

/* Loading states for uniform buttons */
.download-btn.uniform.loading {
    pointer-events: none;
    position: relative;
}

.download-btn.uniform.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* Progress animation for download */
@keyframes downloadProgress {
    0% { width: 0%; }
    100% { width: 100%; }
}

.download-btn.uniform.downloading::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.8);
    animation: downloadProgress 2s ease-in-out;
}

/* Enhanced focus states for better accessibility */
.download-btn.uniform:focus-visible {
    outline: 3px solid rgba(79, 172, 254, 0.6);
    outline-offset: 2px;
}

/* Keyboard shortcut hints */
.download-btn.uniform[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 8px;
    pointer-events: none;
    max-width: 250px;
    word-wrap: break-word;
    white-space: normal;
    text-align: center;
}

/* QR Section */
.qr-section {
    animation: slideInRight 0.6s ease-out;
}

.qr-container {
    text-align: center;
    padding: 30px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 15px;
    min-height: 450px; /* Increased for 400x400px QR Code */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    border: 2px dashed var(--border-light);
}

.qr-container:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-blue);
}

.qr-placeholder {
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1.6;
    text-align: center;
    max-width: 320px;
}

.qr-placeholder h3 {
    margin-bottom: 15px;
    color: var(--text-dark);
    font-size: 1.4rem;
}

.qr-placeholder p {
    margin-bottom: 15px;
}

.qr-placeholder small {
    display: block;
    margin-top: 15px;
    font-size: 0.9rem;
    color: #95a5a6;
    font-style: italic;
}

/* QR Code Image - Updated for 400x400px with security indicator */
.qr-code-image {
    max-width: 100%;
    width: 400px;
    height: 400px;
    border-radius: 15px;
    box-shadow: var(--shadow-lg);
    animation: fadeInScale 0.5s ease-out;
    margin-bottom: 20px;
    transition: var(--transition);
    border: 2px solid #f8f9fa;
    /* QR Code will be black (#000000) from JavaScript */
    position: relative;
}

.qr-code-image:hover {
    transform: scale(1.02);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

/* Security badge for QR code */
.qr-code-image::after {
    content: 'ðŸ”’';
    position: absolute;
    bottom: -10px;
    right: -10px;
    background: var(--success-color);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
}

/* Enhanced Messages */
.message {
    padding: 15px 20px;
    border-radius: var(--border-radius);
    margin: 20px 0;
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out;
    border: 1px solid;
    position: relative;
}

.message::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    border-radius: 2px 0 0 2px;
}

.success-message {
    color: var(--success-color);
    background: rgba(39, 174, 96, 0.1);
    border-color: rgba(39, 174, 96, 0.3);
    text-align: left;
    white-space: pre-line;
    max-width: 90%;
    word-wrap: break-word;
}

.success-message::before {
    background: var(--success-color);
}

.error-message {
    color: var(--error-color);
    background: rgba(231, 76, 60, 0.1);
    border-color: rgba(231, 76, 60, 0.3);
    text-align: center;
}

.error-message::before {
    background: var(--error-color);
}

.info-message {
    color: var(--info-color);
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.3);
    text-align: center;
}

.info-message::before {
    background: var(--info-color);
}

/* Loading Animation with Security Enhancement */
.loading {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
    position: relative;
}

/* Security-enhanced loading spinner */
.loading::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    border: 1px solid var(--success-color);
    border-radius: 50%;
    opacity: 0.3;
}

/* Loading spinner for buttons */
.loading-spinner-btn {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

/* vCard Preview */
.vcard-preview {
    background: var(--bg-light);
    border-radius: 10px;
    padding: 20px;
    margin-top: 20px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #495057;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.vcard-preview h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--text-dark);
    font-family: var(--font-system);
    font-size: 14px;
}

#vcard-content {
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.3;
}

/* Animations */
@keyframes slideInLeft {
    from {
        transform: translateX(-30px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(30px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Security pulse animation for important elements */
@keyframes securityPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(39, 174, 96, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0);
    }
}

.security-enhanced {
    animation: securityPulse 2s infinite;
}

/* Responsive Design - Updated for 400x400px QR Code */
@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 20px;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .form-row label {
        min-width: auto;
        padding-top: 0;
        text-align: left;
    }

    .header h1 {
        font-size: 2rem;
    }

    body {
        padding: 10px;
    }

    .qr-container {
        min-height: 350px;
        padding: 20px;
    }

    .qr-code-image {
        width: 320px;
        height: 320px;
    }

    /* Switch to vertical layout on tablets and small screens */
    .download-btn-group-uniform {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .download-btn.uniform {
        padding: 12px 18px;
        font-size: 12px;
        min-height: 46px;
    }

    .format-info {
        font-size: 10px;
        padding: 8px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 20px;
    }

    .main-content {
        padding: 15px;
    }

    fieldset {
        padding: 15px;
    }

    .form-row input {
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    .qr-code-image {
        width: 280px;
        height: 280px;
    }

    .submit-btn {
        padding: 15px 30px;
        font-size: 14px;
    }

    /* Mobile-specific button styling */
    .download-btn-group-uniform {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .download-btn.uniform {
        padding: 12px 16px;
        font-size: 11px;
        min-height: 48px; /* Better for touch */
        border-radius: 22px;
    }

    .format-info {
        font-size: 9px;
        padding: 6px;
    }

    .format-info small {
        font-size: 9px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media (prefers-contrast: high) {
    .form-row input {
        border-width: 3px;
    }

    .btn {
        border: 2px solid;
    }

    .container {
        border: 2px solid #000;
    }
}

/* Print Optimization */
@media print {
    body {
        background: white !important;
        padding: 0;
    }

    .container {
        box-shadow: none;
        border: 1px solid #000;
    }

    .header {
        background: #f8f9fa !important;
        color: #000 !important;
    }

    .submit-btn,
    .download-btn {
        display: none;
    }

    .form-section {
        display: none;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    /* Print QR code info */
    .qr-code-image::after {
        content: 'Secure QR Code - Generated with XSS Protection' !important;
        position: static;
        display: block;
        background: none;
        color: #000;
        font-size: 10px;
        margin-top: 10px;
        border: none;
        box-shadow: none;
    }
}

/* Better Lao text support */
.lao-text,
input[lang="lo"] {
    font-family: var(--font-lao);
    direction: ltr;
    text-align: left;
    unicode-bidi: embed;
}

/* Enhanced focus improvements for security */
.btn:focus-visible {
    outline: 3px solid var(--primary-blue);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(79, 172, 254, 0.2);
}

.btn:focus:not(:focus-visible) {
    outline: none;
}

/* Loading state improvements */
.btn.loading {
    pointer-events: none;
    position: relative;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* Security indicators */
.secure-indicator {
    color: var(--success-color);
    font-weight: bold;
}

.secure-indicator::before {
    content: 'ðŸ”’ ';
    margin-right: 4px;
}

/* Dark mode support for security elements */
@media (prefers-color-scheme: dark) {
    .security-enhanced {
        animation: securityPulse 2s infinite;
        filter: brightness(1.1);
    }
    
    .qr-code-image::after {
        background: var(--success-color);
        box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
    }

}






