/*
 * @contract CONTRACT:S2-IDENTITY-SURFACE-INTERNALS.1.0
 * @see ../../../architecture/CONTRACT-S2-IDENTITY-SURFACE-INTERNALS.1.0.md
 *
 * The former <style> block of index.html (S2 1.20), unchanged, followed by
 * id rules that replace the former style attributes. The id selectors outrank
 * the class rules by specificity, whatever the order; the JS el.style writes,
 * being inline CSSOM, still override them.
 */

    * {
        box-sizing: border-box;
    }
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        min-height: 100vh;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding: 10px;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    }
    .surface-card {
        background: white;
        border-radius: 20px;
        box-shadow: 0 20px 60px rgba(0,0,0,0.3);
        max-width: 400px;
        width: 100%;
        overflow: hidden;
    }

    /* Header */
    .surface-header {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
        color: white;
        padding: 10px 20px;
        text-align: center;
    }
    .surface-header .logo {
        font-size: 20px;
        font-weight: 700;
        margin-bottom: 2px;
    }
    .surface-header .logo span {
        background: linear-gradient(135deg, #667eea, #764ba2);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    .surface-header .subtitle {
        font-size: 13px;
        opacity: 0.7;
    }
    .requesting-app {
        margin-top: 6px;
        padding: 6px 16px;
        background: rgba(255,255,255,0.1);
        border-radius: 20px;
        font-size: 12px;
        display: inline-block;
    }
    .requesting-app strong {
        color: #a5b4fc;
    }

    /* Main content */
    .surface-body {
        padding: 12px 16px;
    }

    /* Camera feed */
    .camera-container {
        position: relative;
        border-radius: 12px;
        overflow: hidden;
        background: #2a2a3e;
        aspect-ratio: 4/3;
        margin: 0 auto 8px auto;
        max-height: 150px;
        max-width: 200px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .camera-container video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transform: scaleX(-1); /* Mirror */
    }
    /* Placeholder shown when camera is off */
    .camera-placeholder {
        position: absolute;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #6b7280;
        gap: 8px;
        z-index: 1;
    }
    .camera-placeholder .icon {
        font-size: 48px;
        opacity: 0.4;
    }
    .camera-placeholder .text {
        font-size: 12px;
        opacity: 0.6;
    }
    .camera-container.active .camera-placeholder {
        display: none;
    }
    .camera-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    .camera-container.active .camera-overlay {
        opacity: 1;
    }
    .face-guide {
        width: 100px;
        height: 130px;
        border: 2px dashed rgba(255,255,255,0.4);
        border-radius: 50% 50% 45% 45%;
    }
    .camera-status {
        position: absolute;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0,0,0,0.6);
        color: white;
        padding: 6px 14px;
        border-radius: 20px;
        font-size: 12px;
        opacity: 0;
        transition: opacity 0.3s;
    }
    .camera-container.active .camera-status {
        opacity: 1;
    }
    .camera-status.detecting {
        background: rgba(34, 197, 94, 0.8);
    }

    /* User info banner (returning user) */
    .user-banner {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
        padding: 8px 14px;
        border-radius: 10px;
        margin-bottom: 8px;
        text-align: center;
    }
    .user-banner .greeting {
        font-size: 15px;
        font-weight: 600;
        margin-bottom: 2px;
    }
    .user-banner .user-email {
        font-size: 13px;
        opacity: 0.9;
    }
    .user-banner .switch-link {
        font-size: 11px;
        color: rgba(255,255,255,0.8);
        text-decoration: underline;
        cursor: pointer;
        margin-top: 4px;
        display: inline-block;
    }
    .user-banner .switch-link:hover {
        color: white;
    }

    /* New user form */
    .enroll-form {
        margin-bottom: 12px;
    }
    .enroll-form label {
        font-size: 13px;
        font-weight: 600;
        color: #374151;
        margin-bottom: 4px;
        display: block;
    }
    .enroll-form input {
        width: 100%;
        padding: 10px 12px;
        border: 2px solid #e5e7eb;
        border-radius: 8px;
        font-size: 14px;
        transition: border-color 0.2s;
    }
    .enroll-form input:focus {
        outline: none;
        border-color: #667eea;
    }
    .enroll-form .privacy-note {
        font-size: 11px;
        color: #6b7280;
        margin-top: 8px;
        text-align: center;
    }
    .enroll-form .privacy-note strong {
        color: #374151;
    }

    /* Primary action button */
    .btn-primary-action {
        width: 100%;
        padding: 12px 20px;
        border: none;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    .btn-verify {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
    }
    .btn-verify:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
    }
    .btn-enroll {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
    }
    .btn-enroll:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
    }
    .btn-primary-action:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none !important;
        box-shadow: none !important;
    }
    .btn-primary-action .icon {
        font-size: 18px;
    }

    /* Status message */
    .status-message {
        text-align: center;
        padding: 8px 12px;
        border-radius: 8px;
        font-size: 13px;
        margin-top: 10px;
        display: none;
    }
    .status-message.visible { display: block; }
    .status-message.error {
        background: #fef2f2;
        color: #dc2626;
    }
    .status-message.success {
        background: #f0fdf4;
        color: #16a34a;
    }
    .status-message.info {
        background: #eff6ff;
        color: #2563eb;
    }

    /* Advanced/gear button */
    .advanced-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(255,255,255,0.2);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255,255,255,0.3);
        color: white;
        cursor: pointer;
        font-size: 18px;
        transition: all 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .advanced-toggle:hover {
        background: rgba(255,255,255,0.3);
        transform: scale(1.1);
    }
    .advanced-toggle.active {
        background: #ef4444;
        border-color: #ef4444;
    }

    /* Advanced panel */
    .advanced-panel {
        display: none;
        background: #1f2937;
        color: #e5e7eb;
        border-radius: 12px;
        padding: 16px;
        margin-top: 20px;
    }
    .advanced-panel.visible { display: block; }
    .advanced-panel h6 {
        color: #9ca3af;
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: 10px;
    }
    .advanced-panel .btn {
        font-size: 12px;
    }
    .advanced-panel .key-info {
        font-family: monospace;
        font-size: 10px;
        color: #9ca3af;
        margin-top: 8px;
    }

    /* Debug log (inside advanced) */
    #debug {
        background: #111827;
        color: #6ee7b7;
        border-radius: 8px;
        padding: 10px;
        font-size: 10px;
        font-family: monospace;
        max-height: 150px;
        overflow-y: auto;
        margin-top: 10px;
        display: none;
    }
    #debug.visible { display: block; }

    /* Hide elements based on state */
    .state-enrolled .enroll-form { display: none; }
    .state-enrolled .btn-enroll { display: none; }
    .state-new .user-banner { display: none; }
    .state-new .btn-verify { display: none; }

    /* Loading details zone — sits below action buttons, prevents layout shift */
    .loading-details {
        margin-top: 10px;
        min-height: 0;
    }

    /* Model init / progress section */
    .model-init-section {
        display: none;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 10px 14px;
        margin-bottom: 8px;
        text-align: center;
    }
    .model-init-section.visible { display: block; }
    .model-init-explainer {
        font-size: 13px;
        font-weight: 500;
        color: #475569;
        margin-bottom: 10px;
    }
    .model-init-explainer small {
        display: block;
        font-size: 11px;
        font-weight: 400;
        color: #94a3b8;
        margin-top: 2px;
    }
    .model-progress-bar {
        width: 100%;
        height: 8px;
        background: #e2e8f0;
        border-radius: 4px;
        overflow: hidden;
        margin-bottom: 6px;
    }
    .model-progress-fill {
        height: 100%;
        width: 0%;
        background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        border-radius: 4px;
        transition: width 0.3s ease;
    }
    .model-progress-text {
        font-size: 11px;
        color: #64748b;
        margin-bottom: 8px;
    }
    /* Legacy model-load-status (kept for compat) */
    .model-load-status {
        text-align: center;
        font-size: 11px;
        color: #6b7280;
        margin-top: -8px;
        margin-bottom: 8px;
        display: none;
    }
    .model-load-status.visible { display: block; }
    .model-load-status.loading { color: #667eea; }
    .model-load-status.ready { color: #10b981; }
    .model-load-status.error { color: #dc2626; }

    /* Loading state */
    .loading .camera-container::after {
        content: 'Starting camera...';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: white;
        font-size: 14px;
    }

    /* Step Progress Indicator */
    .step-progress {
        display: none;
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 0;
        margin-bottom: 8px;
        padding: 0 8px;
    }
    .step-progress.visible {
        display: flex;
    }
    .step-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        flex: 1;
        position: relative;
    }
    .step-circle {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        border: 2px solid #d1d5db;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 600;
        color: #9ca3af;
        background: white;
        position: relative;
        z-index: 1;
        transition: all 0.3s;
    }
    .step-circle.active {
        border-color: #667eea;
        color: #667eea;
        animation: pulse 1.5s ease-in-out infinite;
    }
    .step-circle.complete {
        border-color: #10b981;
        background: #10b981;
        color: white;
    }
    .step-circle.complete::after {
        content: '';
        width: 8px;
        height: 14px;
        border: solid white;
        border-width: 0 2px 2px 0;
        transform: rotate(45deg) translate(-1px, -1px);
    }
    .step-circle.complete span {
        display: none;
    }
    .step-connector {
        position: absolute;
        top: 14px;
        left: calc(50% + 14px);
        right: calc(-50% + 14px);
        height: 2px;
        background: #d1d5db;
        z-index: 0;
        transition: background 0.3s;
    }
    .step-connector.active,
    .step-connector.complete {
        background: #10b981;
    }
    .step-item:last-child .step-connector {
        display: none;
    }
    .step-label {
        font-size: 11px;
        color: #9ca3af;
        margin-top: 4px;
        text-align: center;
        transition: color 0.3s;
    }
    .step-label.active {
        color: #667eea;
        font-weight: 600;
    }
    .step-label.complete {
        color: #10b981;
    }
    @keyframes pulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4); }
        50% { box-shadow: 0 0 0 6px rgba(102, 126, 234, 0); }
    }

    /* Privacy Banner */
    .privacy-banner {
        display: flex;
        align-items: flex-start;
        gap: 8px;
        padding: 8px 10px;
        background: rgba(16, 185, 129, 0.08);
        border: 1px solid rgba(16, 185, 129, 0.25);
        border-radius: 10px;
        margin-bottom: 8px;
    }
    .privacy-icon {
        flex-shrink: 0;
        width: 20px;
        height: 20px;
        margin-top: 1px;
    }
    .privacy-text {
        font-size: 12px;
        color: #374151;
        line-height: 1.4;
    }
    .privacy-text strong {
        color: #059669;
    }
    .privacy-text span {
        color: #6b7280;
    }

    /* Verifying Overlay */
    .verifying-overlay {
        display: none;
        position: relative;
        background: rgba(255, 255, 255, 0.92);
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 12px;
        padding: 16px;
        border-radius: 12px;
        margin: 8px 0;
    }
    .verifying-overlay.visible {
        display: flex;
    }
    .verifying-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #e5e7eb;
        border-top: 3px solid #667eea;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
    .verifying-overlay .verifying-text {
        font-size: 15px;
        font-weight: 600;
        color: #374151;
    }
    .verifying-overlay .verifying-email {
        font-size: 13px;
        color: #6b7280;
    }

/* Former style attributes of index.html (S2 1.20). Id selectors, not the
   hidden attribute: Bootstrap's [hidden]{display:none!important} would beat
   the el.style.display writes that show these elements. */
#requesting-app { display: none; }
#surface-body { position: relative; }
#user-banner { display: none; }
#enroll-form { display: none; }
#user-name { margin-top: 6px; }
#btn-verify { display: none; }
#btn-enroll { display: none; }
#btn-capture { display: none; }
#signing-consent-gate { display: none; }
#model-info-display { display: none; }
#key-info-display { display: none; }
#debug-mode-options { margin-bottom: 8px; }
#debug-label-off { font-size: 11px; margin-right: 10px; }
#debug-label-normal { font-size: 11px; margin-right: 10px; }
#debug-label-verbose { font-size: 11px; }
