/* ==========================================================================
   BankID Accessibility Styles (Updated June 2025)
   ========================================================================== */

/* FOUC Prevention - Hide content until styles are loaded */
.bankid-loading {
    visibility: hidden;
    overflow: visible; /* Allow sticky elements to escape container bounds */
}

body.styles-loaded .bankid-loading {
    visibility: visible;
}

/* Main container styling to match sketch - definitive styles */
#bankid-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 30px; /* Increased padding to match qr-container */
    text-align: center;
    background: #f8f9fa; /* Background to match qr-container for consistency */
    border-radius: 12px; /* Border radius to match qr-container */
    box-shadow: none;
    border: 1px solid #e9ecef; /* Border to match qr-container */
    /* Add flexbox properties for perfect centering */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Changed from center to flex-start to allow sticky content to escape */
    align-items: center;
    position: relative; /* Positioning context for absolutely positioned children (spinner) */
    overflow: visible; /* Ensure sticky elements can escape the container bounds */
}

/* Title and description text styling */
.title-box {
    text-align: left;
    margin-bottom: 20px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.color-title {
    font-size: 28px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 20px;
}

/* Description text above QR code */
#message {
    text-align: left;
    max-width: 500px;
    margin: 0 auto 20px auto;
    font-size: 16px;
    color: #666;
    line-height: 1.5;
}

/* Enhanced QR code styling with accessibility - optimized for container fit */
.qr-code {
    width: 320px; /* Increased size for better scanning accessibility */
    height: 320px;
    display: none; /* Initially hidden, will be shown by JavaScript when ready */
    margin: 10px auto; /* Reduced margin to better fit container */
    background-color: #ffffff;
    border: 2px solid #e0e0e0; /* Subtle border for definition */
    border-radius: 8px; /* Rounded corners for modern look */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* Subtle shadow */
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    /* Ensure QR code fits well within container */
    max-width: calc(100% - 20px); /* Responsive sizing */
    max-height: calc(100% - 60px); /* Leave space for other elements */
    box-sizing: border-box;
}

/* Ensure QR code content scales properly */
.qr-code canvas,
.qr-code img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

/* When QR code is active/visible */
.qr-code.active {
    display: block;
}

/* Clickable QR code */
.clickable-qr-code {
    cursor: pointer;
}

.clickable-qr-code:hover,
.clickable-qr-code:focus {
    transform: scale(1.03); /* Slightly reduced scale to prevent overflow */
    border-color: #3699ff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Sticky QR code container - updated for larger size */
.sticky-qr-code {
    position: sticky;
    top: 20px;
    z-index: 100;
    background: white;
    max-width: 90%; /* More responsive */
    border: 2px solid #e0e0e0;
}

/* QR code with timer sticky container */
.qr-with-timer-sticky {
    position: relative;
    transition: all 0.3s ease;
    width: 100%;
    max-width: 400px;
    align-self: center;
}

/* Global sticky positioning when activated */
.qr-with-timer-sticky.sticky-active {
    position: fixed ;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: 380px;
    width: calc(100vw - 40px);
    border: 1px solid #e0e0e0;
    background-color: #ffffff;
    border-radius: 12px;
}

/* Timer display */
.timer-display {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    background: transparent;
    border: none;
    display: block;
    margin: 15px auto;
    text-align: center;
    padding: 0;
}

/* Progress bar for timer - matches QR code width */
.timer-progress {
    width: 320px;
    height: 10px;
    background: #ffffff;
    border-radius: 4px;
    margin: 20px auto;
    overflow: hidden;
}

.timer-progress-bar {
    height: 100%;
    background: #4285f4;
    border-radius: 4px;
    transition: width 1s linear;
    width: 100%;
}

/* Timer gets red color when less than 30 seconds remain */
.timer-display.urgent {
    background: #fff5f5;
    border-color: #f56565;
    color: #c53030;
}

/* Accessibility controls container */
.accessibility-controls {
    display: none; /* Hidden by default to match desired design */
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

/* Accessibility buttons */
.accessibility-btn {
    justify-content: flex-start;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.accessibility-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.accessibility-btn:focus {
    outline: none;
    border-color: #3699ff;
    box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.2);
}

.accessibility-btn:active {
    transform: translateY(0);
}

/* Specific button styles */
.btn-warning.accessibility-btn {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #212529;
}

.btn-warning.accessibility-btn:hover {
    background-color: #e0a800;
    border-color: #d39e00;
}

.btn-info.accessibility-btn {
    background-color: #17a2b8;
    border-color: #17a2b8;
    color: white;
}

.btn-info.accessibility-btn:hover {
    background-color: #138496;
    border-color: #117a8b;
}

.btn-secondary.accessibility-btn {
    background-color: #6c757d;
    border-color: #6c757d;
    color: white;
}

.btn-secondary.accessibility-btn:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

/* BankID buttons styling to match sketch */
.btn-bankid {
    background: #007bff;
    border: 1px solid #007bff;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 8px;
    transition: all 0.2s ease;
    min-width: 220px;
    justify-content: center;
}

.btn-bankid:hover {
    background: #0056b3;
    border-color: #0056b3;
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.25);
}

.btn-bankid:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.btn-bankid img {
    width: 24px;
    height: 24px;
}

/* Special styling for "this device" button in QR mode */
.btn-bankid.this-device {
    background: #f1f3f7;
    border: 1px solid #f1f3f7;
    color: #3699ff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0; /* No gap since no icon */
    margin: 0; /* Remove default margin from .btn-bankid */
}

.btn-bankid.this-device:hover {
    background: #e5ecf0;
    border-color: #e5ecf0;
    color: #2577cc;
    text-decoration: none;
}

.btn-bankid.this-device:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.2);
}

/* Secondary buttons (like Avbryt) */
.btn-secondary {
    background: #e5f0fe;
    border: 1px solid #e5f0fe;
    color: #3699ff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary:hover {
    background: #d1e7fd;
    border-color: #d1e7fd;
    color: #2577cc;
    text-decoration: none;
}

/* Bankid-root styling */
.bankid-root-class {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Loading spinner styling - perfectly centered in container */
.lds-ring {
    display: inline-block;
    position: absolute;
    width: 64px;
    height: 64px;
    /* Perfect centering using absolute positioning */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10; /* Ensure it appears above other elements */
    /* Additional centering insurance */
    margin: 0;
    padding: 0;
}

.lds-ring div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 51px;
    height: 51px;
    margin: 6px;
    border: 6px solid #007bff;
    border-radius: 50%;
    animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: #007bff transparent transparent transparent;
}

.lds-ring div:nth-child(1) { animation-delay: -0.45s; }
.lds-ring div:nth-child(2) { animation-delay: -0.3s; }
.lds-ring div:nth-child(3) { animation-delay: -0.15s; }

@keyframes lds-ring {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Layout improvements */
.sticky-qr-container {
    background: white;
    border-radius: 12px;
    padding: 30px 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    margin: 20px auto;
    max-width: 500px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Updated Layout Styles to Match Sketch (June 2025) */

/* Title and description should be outside QR container */
.title-box {
    text-align: left;
    margin-bottom: 20px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

#message {
    text-align: left;
    max-width: 500px;
    margin: 0 auto 20px auto;
    font-size: 16px;
    color: #666;
    line-height: 1.5;
}

/* QR Container - updated class name and styling */
.qr-container {
    max-width: 500px;
    margin: 0 auto 20px auto;
    padding: 30px;
    text-align: center;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #e9ecef;
    position: relative;
}

/* Timer display without gray background */
.timer-display {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    background: transparent;
    border: none;
    display: block;
    margin: 15px auto;
    text-align: center;
    padding: 0;
}

/* Extend button container and styling */
.extend-container {
    margin-top: 15px;
    text-align: center;
}

.extend-btn {
    background: #4285f4;
    border: 1px solid #4285f4;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
    margin: 0 auto;
    text-align: center;
    width: 320px;
}

.extend-btn:hover {
    background: #3367d6;
    border-color: #3367d6;
}

.extend-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2);
}

/* Horizontal separator - full width of container */
.qr-separator {
    width: 100%;
    max-width: 500px;
    margin: 25px auto;
    border-top: 1px solid #d7d9db;
}

/* Button container outside QR code - full width of parent container */
.button-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    justify-content: flex-start; /* Left-align buttons within container */
    align-items: center;
    flex-wrap: nowrap; /* Keep buttons on one row */
}

/* Button sizing - first button natural width, second takes remaining space */
.button-container .btn-secondary {
    flex: 0 0 auto; /* Natural width based on content */
    margin: 0;
}

.button-container .btn-bankid.this-device {
    flex: 1; /* Take up remaining space */
    margin: 0;
}

/* Responsive adjustments for new layout */
@media (max-width: 768px) {
    .title-box,
    #message,
    .qr-container {
        max-width: calc(100% - 40px);
        margin-left: 20px;
        margin-right: 20px;
    }
    
    /* QR code responsive sizing for mobile */
    .qr-code {
        width: min(280px, calc(100vw - 60px)); /* Responsive but not too small */
        height: min(280px, calc(100vw - 60px));
        margin: 10px auto;
        padding: 10px; /* Slightly reduced padding on mobile */
    }
    
    #bankid-container {
        min-height: 320px; /* Adjust container height for mobile */
        padding: 15px;
    }
    
    .timer-progress {
        width: min(280px, calc(100vw - 60px)); /* Match QR code width */
    }
    
    .button-container {
        width: 100%;
        max-width: calc(100% - 40px);
        margin: 0 auto;
        flex-direction: row; /* Keep buttons on one row */
        gap: 8px; /* Smaller gap on mobile */
    }
    
    .button-container .btn-secondary {
        flex: 0 0 auto; /* Natural width on mobile too */
        font-size: 12px; /* Smaller font on mobile */
        padding: 8px 12px; /* Smaller padding on mobile */
    }
    
    .button-container .btn-bankid.this-device {
        flex: 1; /* Take remaining space on mobile */
        font-size: 12px; /* Smaller font on mobile */
        padding: 8px 12px; /* Smaller padding on mobile */
    }
      .qr-separator {
        width: 100%;
        max-width: calc(100% - 40px);
        margin: 20px auto;
    }
    
    .btn-bankid {
        min-width: auto;
        width: 100%;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .qr-code {
        border: 3px solid #000;
        background-color: #fff;
    }
    
    .timer-display {
        border: 2px solid #000;
        background: #fff;
        color: #000;
    }
    
    .accessibility-controls {
        border: 2px solid #000;
        background: #fff;
    }
    
    .accessibility-btn {
        border: 2px solid #000;
    }
}

/* Accessibility improvements for high contrast mode */
@media (prefers-contrast: high) {
	.qr-code {
		border: 3px solid #000000;
		background-color: #ffffff;
		box-shadow: none;
	}
	
	#bankid-container {
		border: 2px solid #000000;
		background: #ffffff;
	}
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .clickable-qr-code,
    .accessibility-btn {
        transition: none;
    }
    
    .clickable-qr-code:hover,
    .clickable-qr-code:focus {
        transform: none;
    }
    
    .accessibility-btn:hover {
        transform: none;
    }
    
    .qr-fullscreen-modal,
    .qr-fullscreen-content {
        animation: none;
    }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
	.qr-code,
	.clickable-qr-code {
		transition: none;
	}
	
	.clickable-qr-code:hover,
	.clickable-qr-code:focus {
		transform: none;
	}
}

/* Enhanced focus styling for keyboard navigation */
.qr-code:focus-visible {
	outline: 3px solid #3699ff;
	outline-offset: 2px;
}

/* Large text support - scale up QR code for users with large text */
@media (min-resolution: 1.5dppx) {
	.qr-code canvas,
	.qr-code img {
		image-rendering: -webkit-optimize-contrast;
		image-rendering: crisp-edges;
	}
}

/* Focus indicators for better keyboard navigation */
.accessibility-controls:focus-within {
    outline: 2px solid #3699ff;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .accessibility-controls,
    .qr-fullscreen-modal {
        display: none;
    }
    
    .sticky-qr-code {
        position: static;
        box-shadow: none;
    }
}
