:root {
    --bg-dark: #393F51; /* Westhill Dark */
    --text-light: #F1F2F2; /* Westhill Neutral */
    --accent-vibrant: #F05730; /* Westhill Primary Orange */
    --accent-glow: rgba(240, 87, 48, 0.4);
    --glass-bg: rgba(57, 63, 81, 0.6);
    --glass-border: rgba(241, 242, 242, 0.1);
    --danger: #F05730;
    --warning: #32BBE3; /* Westhill Light Blue */
    --success: #6ABF4B; /* Westhill Green */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Proxima Nova', 'Montserrat', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    touch-action: none; /* Prevent iOS Safari from interfering with pinch zoom */
}

.app-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Base Glassmorphism utility */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

/* Header */
.glass-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    z-index: 10;
}

.glass-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.pulse {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--accent-vibrant);
    box-shadow: 0 0 10px var(--accent-glow);
    animation: pulsing 2s infinite ease-in-out;
}

@keyframes pulsing {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0.8); opacity: 0.5; }
}

.status-indicator {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--glass-border);
}

.status-indicator.connected { color: var(--success); border-color: var(--success); }
.status-indicator.disconnected { color: var(--danger); border-color: var(--danger); }

/* Camera Viewport */
.camera-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none; /* Prevent native pinch-to-zoom from swallowing events */
    z-index: 1;
    background: #000;
    overflow: hidden;
}

#video-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Targeting Reticle */
#target-reticle {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    height: 250px;
    pointer-events: none;
    z-index: 2;
}

.corner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 4px solid var(--accent-vibrant);
    opacity: 0.8;
    transition: all 0.3s ease;
}

.corner.top-left { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 12px 0 0 0; }
.corner.top-right { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 12px 0 0; }
.corner.bottom-left { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 12px; }
.corner.bottom-right { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 12px 0; }

.scanning .corner {
    border-color: var(--success);
    transform: scale(0.9);
}

/* AI Feedback Panel */
.feedback-panel {
    position: absolute;
    top: 12%;
    left: 5%;
    width: 90%;
    padding: 15px 20px;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.feedback-panel h2 {
    font-size: 1.2rem;
    margin-bottom: 4px;
    color: var(--accent-vibrant);
}

.feedback-panel p {
    font-size: 0.95rem;
    line-height: 1.3;
    color: #cbd5e1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Allow expansion when clicked */
.feedback-panel.expanded {
    max-height: 60vh;
    overflow-y: auto;
}

.feedback-panel.expanded p {
    -webkit-line-clamp: unset;
}

.feedback-panel.high-severity h2 { color: var(--danger); text-shadow: 0 0 10px rgba(239, 68, 68, 0.4); }
.feedback-panel.med-severity h2 { color: var(--warning); }
.feedback-panel.low-severity h2 { color: var(--success); }

/* Controls */
.controls-panel {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 10;
    padding: 0 20px;
}

.btn {
    width: 100%;
    max-width: 320px;
    padding: 12px;
    border-radius: 30px;
    border: none;
    font-family: 'Proxima Nova', 'Montserrat', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s, background 0.3s;
    outline: none;
    backdrop-filter: blur(5px);
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.primary {
    background: var(--accent-vibrant);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.secondary {
    background: var(--bg-dark);
    color: white;
    border: 2px solid var(--accent-vibrant);
}

.outline {
    background: transparent;
    color: var(--text-light);
    border: 2px solid var(--glass-border);
}

/* Toast */
.toast {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(16, 185, 129, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 600;
    z-index: 999;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -10px);
}

/* Plumb Bubble Reticle */
#plumb-reticle {
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    z-index: 15;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.2);
    transition: opacity 0.3s;
}

#plumb-reticle.hidden {
    opacity: 0;
}

.plumb-bubble {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    background-color: var(--danger);
    border-radius: 50%;
    transform: translate(-50%, -50%); /* Base center */
    transition: transform 0.1s ease-out, background-color 0.2s;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

.plumb-bubble.level {
    background-color: var(--success);
}

.plumb-crosshair {
    position: absolute;
    background: rgba(255, 255, 255, 0.5);
}

.plumb-crosshair.horizontal {
    top: 50%;
    left: 10%;
    right: 10%;
    height: 2px;
    transform: translateY(-50%);
}

.plumb-crosshair.vertical {
    left: 50%;
    top: 10%;
    bottom: 10%;
    width: 2px;
    transform: translateX(-50%);
}

/* Shake Toast Warning */
.shake-toast {
    background: rgba(239, 68, 68, 0.9); /* Red */
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}