/* ============================================
   QR Scanner Light — Apple-Inspired Design
   Inspired by Apple.com Human Interface Guidelines
   ============================================ */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
    --apple-bg: #f5f5f7;
    --apple-surface: rgba(255, 255, 255, 0.72);
    --apple-surface-solid: #ffffff;
    --apple-text-primary: #1d1d1f;
    --apple-text-secondary: #86868b;
    --apple-text-tertiary: #aeaeb2;
    --apple-blue: #007aff;
    --apple-green: #34c759;
    --apple-red: #ff3b30;
    --apple-orange: #ff9500;
    --apple-separator: rgba(60, 60, 67, 0.08);
    --apple-radius-lg: 22px;
    --apple-radius-md: 16px;
    --apple-radius-sm: 12px;
    --apple-radius-pill: 980px;
    --apple-shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --apple-shadow-md: 0 4px 14px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    --apple-shadow-lg: 0 20px 40px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
    --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
                  "Helvetica Neue", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --apple-ease: cubic-bezier(0.25, 1, 0.5, 1);
    --apple-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Main Container --- */
#qrl-container {
    max-width: 520px;
    margin: 48px auto;
    text-align: center;
    font-family: var(--apple-font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding: 32px 28px 28px;
    background: var(--apple-surface);
    border-radius: var(--apple-radius-lg);
    box-shadow: var(--apple-shadow-lg);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.55);
    position: relative;
    overflow: hidden;
}

/* Subtle top-edge highlight like Apple cards */
#qrl-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.8) 30%,
        rgba(255,255,255,0.8) 70%,
        transparent 100%
    );
    pointer-events: none;
}

/* --- Camera Reader --- */
#reader {
    background: #000;
    border-radius: var(--apple-radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
    width: 100%;
    border: 2px solid var(--apple-separator);
    transition: border-color 0.45s var(--apple-ease),
                box-shadow 0.45s var(--apple-ease),
                transform 0.45s var(--apple-ease);
    box-shadow: var(--apple-shadow-md);
}

/* --- Camera Glow Effects --- */
#reader.glow-success {
    border-color: rgba(52, 199, 89, 0.5) !important;
    box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.15),
                0 8px 24px rgba(52, 199, 89, 0.2);
    animation: ringPulseGreen 2s var(--apple-ease) infinite;
}

#reader.glow-error {
    border-color: rgba(255, 59, 48, 0.5) !important;
    box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.15),
                0 8px 24px rgba(255, 59, 48, 0.2);
    animation: ringPulseRed 2s var(--apple-ease) infinite;
}

@keyframes ringPulseGreen {
    0%   { box-shadow: 0 0 0 0 rgba(52,199,89,0.35); }
    70%  { box-shadow: 0 0 0 12px rgba(52,199,89,0); }
    100% { box-shadow: 0 0 0 0 rgba(52,199,89,0); }
}

@keyframes ringPulseRed {
    0%   { box-shadow: 0 0 0 0 rgba(255,59,48,0.35); }
    70%  { box-shadow: 0 0 0 12px rgba(255,59,48,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,59,48,0); }
}

#reader.glow-blue {
    border-color: rgba(0, 122, 255, 0.5) !important;
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15),
                0 8px 24px rgba(0, 122, 255, 0.2);
    animation: ringPulseBlue 2s var(--apple-ease) infinite;
}

@keyframes ringPulseBlue {
    0%   { box-shadow: 0 0 0 0 rgba(0, 122, 255, 0.35); }
    70%  { box-shadow: 0 0 0 12px rgba(0, 122, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 122, 255, 0); }
}

/* --- Result Indicator Circle --- */
#result-indicator {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 20px auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    background: var(--apple-bg);
    color: var(--apple-text-tertiary);
    transition: all 0.5s var(--apple-ease-spring);
    box-shadow: inset 0 0 0 1px var(--apple-separator);
}

#result-indicator.success {
    background: var(--apple-green);
    color: #fff;
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(52, 199, 89, 0.35),
                inset 0 1px 0 rgba(255,255,255,0.2);
    animation: popIn 0.4s var(--apple-ease-spring);
}

#result-indicator.error {
    background: var(--apple-red);
    color: #fff;
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(255, 59, 48, 0.35),
                inset 0 1px 0 rgba(255,255,255,0.2);
    animation: popIn 0.4s var(--apple-ease-spring);
}

@keyframes popIn {
    0%   { transform: scale(0.8); opacity: 0.5; }
    60%  { transform: scale(1.12); }
    100% { transform: scale(1.08); opacity: 1; }
}

#result-indicator.info {
    background: var(--apple-blue);
    color: #fff;
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.35),
                inset 0 1px 0 rgba(255,255,255,0.2);
    animation: popIn 0.4s var(--apple-ease-spring);
}

/* --- Status Text --- */
.status-message {
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin: 8px 0 20px;
    line-height: 1.15;
    color: var(--apple-text-primary);
    transition: color 0.35s ease, transform 0.35s var(--apple-ease-spring);
}

.text-success {
    color: var(--apple-green) !important;
}

.text-error {
    color: var(--apple-red) !important;
}

.text-info {
    color: var(--apple-blue) !important;
}

/* --- Status Box (Waiting / Checking state) --- */
.status-box,
#status-box {
    font-size: 15px;
    font-weight: 500;
    color: var(--apple-text-secondary);
    margin: 8px 0 16px;
    padding: 10px 20px;
    background: var(--apple-bg);
    border-radius: var(--apple-radius-pill);
    display: inline-block;
    letter-spacing: -0.01em;
    transition: all 0.3s var(--apple-ease);
    border: 1px solid var(--apple-separator);
}

/* --- Debug Toggle Button --- */
.debug-toggle,
#qrl-container > button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    padding: 8px 18px;
    font-family: var(--apple-font);
    font-size: 13px;
    font-weight: 500;
    color: var(--apple-blue);
    background: transparent;
    border: 1.5px solid rgba(0, 122, 255, 0.25);
    border-radius: var(--apple-radius-pill);
    cursor: pointer;
    transition: all 0.25s var(--apple-ease);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

.debug-toggle:hover,
#qrl-container > button:hover {
    background: rgba(0, 122, 255, 0.08);
    border-color: rgba(0, 122, 255, 0.4);
    transform: translateY(-1px);
}

.debug-toggle:active,
#qrl-container > button:active {
    transform: scale(0.97);
    background: rgba(0, 122, 255, 0.12);
}

/* --- Debug Info Panel --- */
#debug-info {
    margin-top: 16px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.65;
    color: var(--apple-text-secondary);
    text-align: left;
    background: var(--apple-bg);
    padding: 16px 20px;
    border-radius: var(--apple-radius-sm);
    border: 1px solid var(--apple-separator);
    display: none;
    animation: fadeSlideIn 0.3s var(--apple-ease);
}

#debug-info strong {
    color: var(--apple-text-primary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#debug-info span {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    color: var(--apple-text-primary);
    background: rgba(0,0,0,0.03);
    padding: 2px 6px;
    border-radius: 4px;
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Camera Error Message --- */
#reader p {
    font-family: var(--apple-font) !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    color: var(--apple-red) !important;
    padding: 32px 20px !important;
    line-height: 1.5 !important;
    letter-spacing: -0.01em !important;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    #qrl-container {
        margin: 20px 16px;
        padding: 24px 20px 20px;
        border-radius: var(--apple-radius-md);
    }

    .status-message {
        font-size: 26px;
    }

    #result-indicator {
        width: 68px;
        height: 68px;
        font-size: 30px;
    }
}

/* --- Override html5-qrcode library internals --- */
#reader video {
    border-radius: var(--apple-radius-md) !important;
}

#reader img {
    border-radius: var(--apple-radius-md) !important;
}

#qr-shaded-region {
    border-color: rgba(255,255,255,0.3) !important;
}