/*
 * scan_app.css
 * Styles for the WebRTC scanning client.
 * Designed to be embeddable in any website without conflicting with host styles.
 * All selectors are scoped under .scan-app-root to prevent leakage.
 */

/* ================================================================
   Reset & root container
   ================================================================ */

.scan-app-root *,
.scan-app-root *::before,
.scan-app-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.scan-app-root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
                 Arial, sans-serif;
    font-size: 14px;
    color: #222;
    background: #f4f4f4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ================================================================
   Start scan screen
   ================================================================ */

.scan-start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    width: 100%;
    max-width: 480px;
}

.scan-logo {
    width: 240px;
    margin-bottom: 2rem;
}

.scan-start-table {
    width: 100%;
    border-collapse: collapse;
}

.scan-start-table td {
    padding: 6px 4px;
}

.scan-start-table label {
    font-weight: 600;
    margin-right: 8px;
}

.scan-input {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 1rem;
    width: 120px;
}

.scan-input:focus {
    outline: none;
    border-color: #4caf50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.25);
}

/* Primary action button */
.scan-button-primary {
    display: block;
    width: 100%;
    padding: 14px;
    margin-top: 1.5rem;
    background: #4caf50;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.scan-button-primary:hover {
    background: #43a047;
}

.scan-button-primary:active {
    background: #388e3c;
}

.scan-button-primary:disabled {
    background: #aaa;
    cursor: not-allowed;
}

/* ================================================================
   Scanning screen
   ================================================================ */

.scan-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 1rem;
}

/* Visual scan area: video + overlays */
.scan-visual-area {
    position: relative;
    width: 640px;
    max-width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.scan-video {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}

/* Canvas overlay for drawing halo / guidance */
.scan-overlay-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}

/* TV noise image shown when disconnected */
.scan-tv-noise {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 10;
}

.scan-not-connected-msg {
    position: absolute;
    bottom: 12px;
    left: 0; right: 0;
    text-align: center;
    color: #fff;
    background: rgba(0,0,0,0.6);
    padding: 8px;
    font-size: 1rem;
    z-index: 11;
}

.scan-not-connected-msg a {
    color: #ffcc00;
    text-decoration: underline;
}

/* ================================================================
   Halo navigation indicators
   ================================================================ */

.halo-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: grid;
    grid-template-rows: 1fr 2fr 1fr;
    grid-template-columns: 1fr 2fr 1fr;
    pointer-events: none;
    z-index: 5;
}

.halo-top    { grid-row: 1; grid-column: 2; display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; }
.halo-bottom { grid-row: 3; grid-column: 2; display: flex; align-items: flex-end;   justify-content: center; padding-bottom: 6px; }
.halo-left   { grid-row: 2; grid-column: 1; display: flex; align-items: center;     justify-content: flex-start; padding-left: 6px; }
.halo-right  { grid-row: 2; grid-column: 3; display: flex; align-items: center;     justify-content: flex-end;   padding-right: 6px; }
.halo-center { grid-row: 2; grid-column: 2; display: flex; align-items: center;     justify-content: center; }

.halo-img {
    width: 48px;
    height: 48px;
    display: none;  /* shown via JS */
    filter: drop-shadow(0 1px 4px rgba(0,0,0,0.6));
}

/* ================================================================
   Control buttons bar
   ================================================================ */

.scan-button-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.scan-ctrl-btn {
    background: #fff;
    border: 2px solid #ccc;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-size: 0.85rem;
    font-weight: 600;
}

.scan-ctrl-btn:hover {
    border-color: #4caf50;
    box-shadow: 0 2px 8px rgba(76,175,80,0.3);
}

.scan-ctrl-btn:active {
    background: #e8f5e9;
}

.scan-ctrl-btn img {
    width: 32px;
    height: 32px;
}

/* ================================================================
   Progress bar
   ================================================================ */

.scan-progress-container {
    width: 100%;
    max-width: 640px;
    height: 12px;
    background: #ddd;
    border-radius: 6px;
    margin-top: 10px;
    overflow: hidden;
}

.scan-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4caf50, #81c784);
    border-radius: 6px;
    transition: width 0.4s ease;
}

.scan-progress-label {
    text-align: center;
    font-size: 0.85rem;
    color: #555;
    margin-top: 4px;
}

/* ================================================================
   User message
   ================================================================ */

.scan-user-message {
    margin-top: 10px;
    padding: 10px 16px;
    border-radius: 6px;
    width: 100%;
    font-size: 0.95rem;
    min-height: 44px;
}

.scan-user-message.info    { background: #e3f2fd; }
.scan-user-message.warning { background: #fff8e1; }
.scan-user-message.error   { background: #fce4ec; }
.scan-user-message.ok      { background: #e8f5e9; }

/* ================================================================
   Measurements table
   ================================================================ */

.scan-measurements-table {
    width: 100%;
    max-width: 640px;
    margin-top: 12px;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.scan-measurements-table th,
.scan-measurements-table td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: center;
}

.scan-measurements-table thead {
    background: #4caf50;
    color: #fff;
    font-weight: 600;
}

.scan-measurements-table tbody tr:nth-child(odd) {
    background: #f9f9f9;
}

.scan-measurements-table .highlight {
    font-weight: 700;
    color: #1b5e20;
}

/* VU-meter bars (offset indicator) */
.scan-vu-meter {
    display: block;
    width: 200px;
    height: 36px;
}

/* ================================================================
   Status bar
   ================================================================ */

.scan-status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 12px;
    background: #fffde7;
    border: 1px solid #ffe082;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #555;
    width: 100%;
    max-width: 640px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.scan-status-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

.scan-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #bbb;
}

.scan-status-dot.ok        { background: #4caf50; }
.scan-status-dot.connecting{ background: #ff9800; }
.scan-status-dot.error     { background: #f44336; }

/* ================================================================
   Responsive adjustments
   ================================================================ */

@media (max-width: 680px) {
    .scan-visual-area {
        width: 100vw;
        border-radius: 0;
    }

    .scan-measurements-table {
        font-size: 0.78rem;
    }

    .scan-vu-meter {
        width: 120px;
    }

    .scan-ctrl-btn {
        width: 48px;
        height: 48px;
    }
}

@media (max-height: 600px) and (orientation: landscape) {
    .scan-screen {
        padding: 0.25rem;
    }

    .scan-visual-area {
        height: 90vh;
        width: auto;
        aspect-ratio: unset;
    }
}
