/* Ruler App Styles */
body {
    overflow: hidden;
    /* Prevent scrolling while using ruler */
    touch-action: none;
    margin: 0;
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    /* Mobile friendly viewport height */
    position: relative;
    background: var(--bg-color);
    /* Ensure bg color on body too */
}

/* Float header above the ruler */
.app-header {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 50;
    pointer-events: none;
    /* Let touches pass through to ruler */
}

/* Restore pointer events for header children (links/buttons) */
.app-header * {
    pointer-events: auto;
}

.ruler-app {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
    /* Below header */
}

#ruler-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
    display: block;
    /* Remove inline-block gap */
}

.calibration-panel {
    position: absolute;
    bottom: calc(250px + env(safe-area-inset-bottom, 20px));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    width: 90%;
    max-width: 400px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 16px;
    transition: all 0.3s ease;
    z-index: 60;
    /* Higher than header */
    opacity: 0;
    pointer-events: none;
}

.calibration-panel.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.fab-btn {
    position: absolute;
    bottom: calc(180px + env(safe-area-inset-bottom, 20px));
    left: 50%;
    transform: translateX(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    cursor: pointer;
    z-index: 60;
    /* Higher than header */
    transition: transform 0.2s, background 0.2s;
}

.fab-btn:active {
    transform: translateX(-50%) scale(0.95);
    background: var(--border-color);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-color);
}

.panel-content .description {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 12px;
    line-height: 1.4;
}

.panel-content .small {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Card Guide visualization */
.card-guide-container {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.card-guide {
    height: 54px;
    /* Visa/Mastercard height approx */
    /* Width will be set by JS based on PPI */
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: width 0.1s;
    position: relative;
}

.card-guide::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px dashed rgba(255, 255, 255, 0.5);
    border-radius: 6px;
}

/* Slider Controls */
.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

input[type=range] {
    flex-grow: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.adj-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
}

.adj-btn:active {
    background: var(--border-color);
}

.ppi-display {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-color);
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.8rem;
    text-decoration: underline;
    cursor: pointer;
    margin-left: 8px;
}

/* Camera Feed */
#camera-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    display: none;
}

#ruler-canvas {
    position: relative;
    z-index: 1;
}

/* Camera Active State */
body.camera-active #camera-feed {
    display: block;
}

body.camera-active .ruler-app {
    background: transparent;
}

/* Camera Controls */
.camera-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-color);
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}