/* Ormeo Identity - Hosted Login Styles */
/* BankID UI Guidelines Compliant */
/* WCAG 2.1 AA Compliant - July 2025 Requirements */

/* CSS Custom Properties (set by layout based on tenant config) */
:root {
    --primary-color: #235971;
    --primary-hover: #1a4558;
    --secondary-color: #ffffff;
    --secondary-hover: #f5f5f5;
    --background-color: #f5f5f5;
    --card-background: #ffffff;
    --text-color: #1a1a1a;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --border-radius: 8px;
    --border-radius-lg: 16px;
    --accent-color: #235971;
    --button-text: #ffffff;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Fixed colors (not customizable) */
    --success-color: #22a352;
    --error-color: #d93025;
    --warning-bg: #fff8e6;
    --warning-border: #f5c518;
    --warning-text: #8a6d00;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--background-color);
}

/* Test Mode Banner */
.test-mode-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.test-mode-banner__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.test-mode-banner__text {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Adjust layout when test banner is present */
body:has(.test-mode-banner) {
    overflow: hidden;
}

body:has(.test-mode-banner) .container {
    padding-top: 60px; /* 40px for banner + 20px normal padding */
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
}

/* Visually hidden but accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Container */
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 460px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 20px 0;
}

.logo {
    max-width: 200px;
    max-height: 80px;
    height: auto;
}

.tenant-name {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Container */
.login-container {
    width: 100%;
}

/* Sections */
.section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 32px 24px;
    background: var(--card-background);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-color);
}

/* Focus styles for headings (used with tabindex="-1") */
.section h2:focus,
.status-message:focus {
    outline: none;
}

/* BankID Logo - Guidelines compliance */
.bankid-logo {
    margin: 0 auto 24px auto;
    width: 100px;
    height: 83px;
    background-image: url('/img/BankID_logo.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.bankid-logo--small {
    width: 80px;
    height: 66px;
}

/* Provider Selection Options */
.provider-intro {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.provider-options {
    width: 100%;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-provider-card {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    padding: 20px;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.btn-provider-card:hover {
    border-color: var(--primary-color);
    background: var(--secondary-hover);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.btn-provider-card:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(35, 89, 113, 0.2);
}

.btn-provider-card:focus-visible {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(35, 89, 113, 0.3);
}

.btn-provider-card:active {
    transform: scale(0.99);
}

/* Provider Icon */
.provider-icon {
    width: 44px;
    height: 44px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
    border-radius: calc(var(--border-radius) * 1.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

.provider-icon-bankid {
    background-color: #fff;
    background-image: url('/img/BankID_logo.svg');
    background-size: 36px;
}

.provider-icon-freja {
    background-color: #006341;
    background-image: url('/img/freja_logo.svg');
    background-size: 36px;
}

.provider-icon-microsoft {
    background-color: #fff;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 21"><rect x="1" y="1" width="9" height="9" fill="%23f25022"/><rect x="1" y="11" width="9" height="9" fill="%2300a4ef"/><rect x="11" y="1" width="9" height="9" fill="%237fba00"/><rect x="11" y="11" width="9" height="9" fill="%23ffb900"/></svg>');
    background-size: 28px;
}

.provider-icon-forsakringskassan {
    background-color: #004b87;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><text x="16" y="22" font-family="Arial" font-size="16" font-weight="bold" fill="white" text-anchor="middle">FK</text></svg>');
    background-size: 32px;
}

/* Provider Info */
.provider-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.provider-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-color);
}

.provider-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Arrow */
.provider-arrow {
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: transform 0.2s, color 0.2s;
}

.btn-provider-card:hover .provider-arrow {
    color: var(--primary-color);
    transform: translateX(3px);
}

/* Device Selection Options */
.device-options {
    width: 100%;
    margin-top: 24px;
}

.option-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 8px;
    margin-bottom: 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
    width: 100%;
}

.btn:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.btn:focus:not(:focus-visible) {
    outline: none;
}

.btn:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-icon {
    flex-shrink: 0;
}

/* BankID styled button (uses accessible button background for WCAG compliance) */
.btn-bankid {
    background-color: var(--button-background, var(--primary-color));
    color: var(--button-text);
    border: 2px solid var(--button-background, var(--primary-color));
}

.btn-bankid:hover {
    background-color: var(--button-background-hover, var(--primary-color));
    border-color: var(--button-background-hover, var(--primary-color));
}

.btn-bankid:active {
    opacity: 0.95;
}

/* Primary button (uses accessible button background for WCAG compliance) */
.btn-primary {
    background-color: var(--button-background, var(--primary-color));
    color: var(--button-text);
}

.btn-primary:hover {
    background-color: var(--button-background-hover, var(--primary-color));
}

/* Secondary button */
.btn-secondary {
    background-color: var(--card-background);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

/* Cancel button */
.btn-cancel {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    margin-top: 16px;
    padding: 12px 20px;
    width: auto;
}

.btn-cancel:hover {
    background-color: var(--secondary-hover);
    border-color: var(--border-color);
}

/* Link button */
.btn-link {
    background: none;
    color: var(--accent-color);
    padding: 8px 16px;
    text-decoration: underline;
    width: auto;
    border: none;
}

.btn-link:hover {
    opacity: 0.8;
}

/* Status Container */
.status-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
}

/* Status Messages */
.status-message {
    color: var(--text-color);
    font-size: 1rem;
    line-height: 1.5;
    max-width: 300px;
}

/* Spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* QR Code Section */
.qr-instructions {
    margin-bottom: 20px;
}

.qr-instructions p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* QR Code Button (WCAG: must be a button for accessibility) */
.qr-button {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 16px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    margin: 16px 0;
    min-width: 232px;
    min-height: 232px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

.qr-button:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.qr-button:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.qr-button:focus:not(:focus-visible) {
    outline: none;
}

.qr-button:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.qr-button:active {
    transform: scale(0.98);
}

.qr-code-inner {
    line-height: 0;
}

.qr-code-inner img,
.qr-code-inner canvas {
    display: block;
}

/* QR Timer */
.qr-timer {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 12px 0;
    padding: 8px 16px;
    background: var(--secondary-hover);
    border-radius: 20px;
}

/* Same Device Actions */
.same-device-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

/* QR Actions */
.qr-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

/* Timeout Warning - WCAG 2.2.1 Timing Adjustable */
.timeout-warning {
    background-color: var(--warning-bg);
    border: 2px solid var(--warning-border);
    border-radius: var(--border-radius);
    padding: 16px;
    margin: 16px 0;
    width: 100%;
}

.timeout-warning p {
    color: var(--warning-text);
    font-weight: 500;
    margin-bottom: 12px;
}

.timeout-warning .btn-secondary {
    width: 100%;
}

.extend-hint {
    font-size: 0.8rem;
    color: var(--warning-text);
    margin-top: 8px;
    font-style: italic;
}

/* Fullscreen QR Modal */
.qr-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    overflow: auto;
}

.qr-fullscreen-content {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 24px;
    border-radius: var(--border-radius-lg);
    border: none;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    max-width: 90vw;
    max-height: 70vh;
}

.qr-fullscreen-content:hover {
    box-shadow: 0 8px 32px rgba(255, 255, 255, 0.2);
}

.qr-fullscreen-content:focus {
    outline: 3px solid #4db8ff;
    outline-offset: 4px;
}

.qr-fullscreen-content:focus:not(:focus-visible) {
    outline: none;
}

.qr-fullscreen-content:focus-visible {
    outline: 3px solid #4db8ff;
    outline-offset: 4px;
}

.qr-fullscreen-content:active {
    transform: scale(0.98);
}

.qr-code-fullscreen-inner {
    line-height: 0;
}

.qr-code-fullscreen-inner img,
.qr-code-fullscreen-inner canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.fullscreen-hint {
    color: #fff;
    font-size: 0.9rem;
    margin-top: 20px;
    opacity: 0.8;
}

.qr-timer-fullscreen {
    font-size: 1rem;
    color: #fff;
    margin-top: 16px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 24px;
}

.timeout-warning-fullscreen {
    margin-top: 16px;
}

.timeout-warning-fullscreen .btn-secondary {
    background: #fff;
    min-width: 200px;
}

/* Success Section */
.success-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 32px 24px;
    background: var(--card-background);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.success-icon {
    width: 64px;
    height: 64px;
    background-color: var(--success-color);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 20px;
}

.success-container h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-color);
}

.welcome-message {
    color: var(--text-color);
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.personal-number {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: monospace;
    margin-bottom: 16px;
}

.info-message {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Error Section */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 32px 24px;
    background: var(--card-background);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.error-icon {
    width: 64px;
    height: 64px;
    color: var(--error-color);
    margin-bottom: 20px;
}

.error-icon svg {
    width: 100%;
    height: 100%;
}

.error-container h2,
.section .error-icon + h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-color);
}

.error-message {
    color: var(--text-color);
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 20px;
    max-width: 320px;
}

.error-code {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-family: monospace;
    margin-bottom: 20px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0 16px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.footer-security {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.footer-lock-icon {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

.footer-brand {
    margin-top: 4px;
}

.footer-company {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    transition: color 0.2s;
}

.footer-company:hover {
    color: var(--accent-color);
}

.footer-company:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.footer-badges {
    margin-top: 8px;
}

.wcag-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--secondary-hover);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.wcag-icon {
    width: 12px;
    height: 12px;
    stroke: var(--success-color);
}

/* Dark mode footer */
html[data-theme="dark"] .wcag-badge {
    background: #2a2a2a;
    border-color: #3a3a3a;
}

/* Accessibility - Focus visible */
:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Skip link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: var(--button-text);
    padding: 8px;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        border-top-color: var(--primary-color);
        opacity: 0.7;
    }

    .btn,
    .qr-button,
    .qr-fullscreen-content {
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .section,
    .success-container,
    .error-container {
        border: 2px solid #000;
    }

    .btn {
        border: 2px solid currentColor;
    }

    .btn-bankid {
        background-color: #000;
        border-color: #000;
    }

    .timeout-warning {
        border: 2px solid #000;
    }

    .qr-button {
        border: 2px solid #000;
    }

    .qr-fullscreen-content {
        border: 2px solid #000;
    }
}

/* Zoom and scale support - ensure QR visible at 200% */
@media (min-resolution: 192dpi), (min-resolution: 2dppx) {
    .qr-button {
        min-width: 200px;
        min-height: 200px;
    }
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    .section,
    .success-container,
    .error-container {
        padding: 24px 20px;
        border-radius: var(--border-radius);
    }

    .btn {
        padding: 14px 20px;
    }

    .btn-cancel {
        width: 100%;
    }

    /* Provider cards on mobile */
    .btn-provider-card {
        padding: 16px;
        gap: 12px;
    }

    .provider-icon {
        width: 40px;
        height: 40px;
    }

    .provider-icon-bankid,
    .provider-icon-freja {
        background-size: 32px;
    }

    .provider-icon-microsoft {
        background-size: 24px;
    }

    .provider-name {
        font-size: 0.95rem;
    }

    .provider-desc {
        font-size: 0.8rem;
    }

    .provider-arrow {
        display: none;
    }

    .qr-button {
        min-width: 200px;
        min-height: 200px;
        padding: 12px;
    }

    .qr-fullscreen-content {
        padding: 16px;
    }
}

/* Small window support - ensure scrollable */
@media (max-height: 600px) {
    .main {
        align-items: flex-start;
        padding-top: 20px;
    }

    .qr-button {
        min-height: 180px;
        min-width: 180px;
    }
}

/* Large window support */
@media (min-width: 768px) {
    .qr-button {
        min-width: 264px;
        min-height: 264px;
    }

    .qr-fullscreen-content {
        padding: 32px;
    }
}

/* Dark mode support (when enabled via data-theme) */
html[data-theme="dark"],
html[data-theme="dark"] body {
    --secondary-hover: #2a2a2a;
    color-scheme: dark;
}

html[data-theme="dark"] .section,
html[data-theme="dark"] .success-container,
html[data-theme="dark"] .error-container {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

html[data-theme="dark"] .qr-button {
    background: #fff;
    border-color: #333;
}

html[data-theme="dark"] .qr-timer {
    background: #2a2a2a;
}

html[data-theme="dark"] .btn-provider-card {
    border-color: #3a3a3a;
}

html[data-theme="dark"] .btn-provider-card:hover {
    background: #2a2a2a;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] .btn-bankid {
    background-color: transparent;
    color: #f0f0f0;
    border-color: rgba(255, 255, 255, 0.4);
}

html[data-theme="dark"] .btn-bankid:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.6);
}

html[data-theme="dark"] .btn-primary {
    background-color: transparent;
    color: #f0f0f0;
    border-color: rgba(255, 255, 255, 0.4);
}

html[data-theme="dark"] .btn-primary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.6);
}

html[data-theme="dark"] .provider-icon-bankid {
    background-color: transparent;
    background-image: url('/img/BankID_logo_white.svg');
}

html[data-theme="dark"] .bankid-logo {
    background-image: url('/img/BankID_logo_white.svg');
}

html[data-theme="dark"] .provider-icon-microsoft {
    background-color: #2a2a2a;
}

/* Also support system dark mode preference when DarkModeEnabled */
@media (prefers-color-scheme: dark) {
    html[data-theme="dark"] {
        /* Styles already applied above */
    }
}

/* Print styles */
@media print {
    .btn,
    .qr-button,
    .spinner,
    .timeout-warning,
    .qr-fullscreen {
        display: none;
    }

    .section {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
