/**
 * Event Registration Scanner - Frontend Styles
 * Mobile-first responsive design
 */

/* CSS Variables */
:root {
    --ers-primary: #2271b1;
    --ers-primary-dark: #135e96;
    --ers-success: #00a32a;
    --ers-success-light: #d6f4d8;
    --ers-error: #d63638;
    --ers-error-light: #fcf0f1;
    --ers-warning: #dba617;
    --ers-gray-light: #f6f7f7;
    --ers-gray: #dcdcde;
    --ers-gray-dark: #646970;
    --ers-text: #1d2327;
    --ers-border-radius: 8px;
    --ers-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Reset and Base */
.ers-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    max-width: 500px;
    margin: 0 auto;
    padding: 16px;
    box-sizing: border-box;
    color: var(--ers-text);
    min-height: 100vh;
}

.ers-container * {
    box-sizing: border-box;
}

/* Header */
.ers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--ers-gray);
}

.ers-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.ers-user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.875rem;
}

.ers-logout-link {
    color: var(--ers-error);
    text-decoration: none;
    font-size: 0.75rem;
}

/* Event Info */
.ers-event-info {
    background: var(--ers-gray-light);
    padding: 12px 16px;
    border-radius: var(--ers-border-radius);
    margin-bottom: 16px;
    text-align: center;
    font-weight: 500;
}

.ers-event-info .ers-loading {
    color: var(--ers-gray-dark);
}

/* Stats Row */
.ers-stats {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.ers-stat {
    flex: 1;
    background: var(--ers-gray-light);
    padding: 12px 8px;
    border-radius: var(--ers-border-radius);
    text-align: center;
}

.ers-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.ers-stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--ers-gray-dark);
    margin-top: 4px;
}

.ers-stat.ers-stat-success .ers-stat-value {
    color: var(--ers-success);
}

.ers-stat.ers-stat-error .ers-stat-value {
    color: var(--ers-error);
}

/* Scanner View */
.ers-scanner-wrapper {
    text-align: center;
}

.ers-scanner-view {
    background: #000;
    border-radius: var(--ers-border-radius);
    overflow: hidden;
    margin-bottom: 20px;
    aspect-ratio: 1 / 1;
    -webkit-aspect-ratio: 1 / 1;
    max-height: 350px;
    max-width: 350px;
    margin-left: auto;
    margin-right: auto;
    display: none;
    position: relative;
}

/* Fallback for browsers that don't support aspect-ratio (older iOS) */
@supports not (aspect-ratio: 1 / 1) {
    .ers-scanner-view {
        width: 100%;
        max-width: 350px;
        height: 0;
        padding-bottom: 100%; /* Creates 1:1 aspect ratio */
        position: relative;
    }

    .ers-scanner-view > * {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

.ers-scanner-view.active {
    display: block;
}

#ers-qr-reader {
    width: 100%;
    height: 100%;
}

#ers-qr-reader video {
    border-radius: var(--ers-border-radius);
    object-fit: cover;
    width: 100% !important;
    height: 100% !important;
}

/* html5-qrcode overrides */
#ers-qr-reader img[alt="Info icon"],
#ers-qr-reader__scan_region > br,
#ers-qr-reader__dashboard_section_swaplink {
    display: none !important;
}

#ers-qr-reader__scan_region {
    border: none !important;
}

/* Force square scan region on all devices including Apple */
#ers-qr-reader__scan_region video {
    object-fit: cover !important;
}

/* QR scan box (the square scanning area) */
#ers-qr-reader__scan_region svg {
    width: 250px !important;
    height: 250px !important;
}

/* Apple device specific fixes */
@supports (-webkit-touch-callout: none) {
    .ers-scanner-view {
        /* Ensure square aspect on iOS Safari */
        width: 100%;
        max-width: 350px;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    #ers-qr-reader,
    #ers-qr-reader video,
    #ers-qr-reader__scan_region {
        aspect-ratio: 1 / 1 !important;
    }
}

/* Buttons */
.ers-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--ers-border-radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-decoration: none;
}

.ers-button:active {
    transform: scale(0.98);
}

.ers-button-primary {
    background: var(--ers-primary);
    color: #fff;
}

.ers-button-primary:hover {
    background: var(--ers-primary-dark);
}

.ers-button-secondary {
    background: var(--ers-gray-light);
    color: var(--ers-text);
    border: 1px solid var(--ers-gray);
}

.ers-button-secondary:hover {
    background: var(--ers-gray);
}

.ers-button-large {
    width: 100%;
    padding: 16px 24px;
    font-size: 1.125rem;
}

.ers-button .dashicons {
    font-size: 1.25rem;
    width: 1.25rem;
    height: 1.25rem;
}

/* Manual Entry */
.ers-manual-entry {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--ers-gray);
}

.ers-manual-entry p {
    margin: 0 0 12px 0;
    color: var(--ers-gray-dark);
}

.ers-manual-form {
    display: flex;
    gap: 8px;
}

.ers-manual-form input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--ers-gray);
    border-radius: var(--ers-border-radius);
    font-size: 1rem;
}

.ers-manual-form input:focus {
    outline: none;
    border-color: var(--ers-primary);
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.2);
}

/* Result Display */
.ers-result {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 9999;
}

.ers-result-content {
    background: #fff;
    border-radius: 16px;
    padding: 32px 24px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: var(--ers-shadow);
    animation: ers-slide-up 0.3s ease;
}

@keyframes ers-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ers-result-icon {
    font-size: 64px;
    line-height: 1;
    margin-bottom: 16px;
}

.ers-result.success .ers-result-icon::before {
    content: "✓";
    color: var(--ers-success);
}

.ers-result.error .ers-result-icon::before {
    content: "✕";
    color: var(--ers-error);
}

.ers-result-title {
    margin: 0 0 12px 0;
    font-size: 1.5rem;
}

.ers-result.success .ers-result-title {
    color: var(--ers-success);
}

.ers-result.error .ers-result-title {
    color: var(--ers-error);
}

.ers-result-message {
    margin-bottom: 16px;
    color: var(--ers-gray-dark);
}

/* Visitor Info */
.ers-visitor-info {
    background: var(--ers-gray-light);
    border-radius: var(--ers-border-radius);
    padding: 16px;
    margin-bottom: 20px;
    text-align: left;
}

.ers-visitor-info-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--ers-gray);
}

.ers-visitor-info-item:last-child {
    border-bottom: none;
}

.ers-visitor-info-label {
    display: block;
    font-size: 0.75rem;
    color: var(--ers-gray-dark);
    margin-bottom: 4px;
}

.ers-visitor-info-value {
    display: block;
    font-weight: 500;
}

.ers-visit-count {
    margin-top: 16px;
    padding: 12px;
    background: var(--ers-success-light);
    border-radius: var(--ers-border-radius);
    color: var(--ers-success);
    font-weight: 600;
}

/* Login Form */
.ers-login-wrapper {
    text-align: center;
    padding-top: 60px;
}

.ers-logo {
    margin-bottom: 24px;
}

.ers-logo .dashicons {
    font-size: 64px;
    width: 64px;
    height: 64px;
    color: var(--ers-primary);
}

.ers-login-wrapper h2 {
    margin: 0 0 8px 0;
}

.ers-login-wrapper p {
    color: var(--ers-gray-dark);
    margin-bottom: 24px;
}

#ers-login-form {
    text-align: left;
}

#ers-login-form p {
    margin-bottom: 16px;
}

#ers-login-form label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
}

#ers-login-form input[type="text"],
#ers-login-form input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--ers-gray);
    border-radius: var(--ers-border-radius);
    font-size: 1rem;
}

#ers-login-form input[type="submit"] {
    width: 100%;
    padding: 14px;
    background: var(--ers-primary);
    color: #fff;
    border: none;
    border-radius: var(--ers-border-radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

#ers-login-form input[type="submit"]:hover {
    background: var(--ers-primary-dark);
}

/* Message Box */
.ers-message {
    text-align: center;
    padding: 40px 24px;
}

.ers-message .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
}

.ers-message-error .dashicons {
    color: var(--ers-error);
}

.ers-message h2 {
    margin: 0 0 8px 0;
}

.ers-message p {
    color: var(--ers-gray-dark);
    margin-bottom: 24px;
}

/* Processing State */
.ers-processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.ers-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--ers-gray);
    border-top-color: var(--ers-primary);
    border-radius: 50%;
    animation: ers-spin 1s linear infinite;
}

@keyframes ers-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 480px) {
    .ers-container {
        padding: 12px;
    }

    .ers-header h1 {
        font-size: 1.25rem;
    }

    .ers-result-content {
        padding: 24px 16px;
    }
}
