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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a1a;
    color: #fff;
    -webkit-user-select: none;
    user-select: none;
}

.screen {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ── Laadimisekraan ── */
#screen-loading {
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
}

.loading-content { text-align: center; }
.loading-content h1 { font-size: 1.5rem; margin: 1rem 0 0.5rem; }
.loading-content p { color: #aaa; font-size: 0.9rem; }

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #333;
    border-top-color: #4CAF50;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Peaekraan ── */
#screen-main {
    flex-direction: column;
}

/* Kaamera ala */
.camera-area {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #000;
    overflow: hidden;
}

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

#overlay-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Paksuse riba */
.top-bar {
    position: absolute;
    top: 8px;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding: 0 12px;
}

.thickness-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    padding: 6px 14px;
    border-radius: 20px;
}

.thickness-bar label {
    font-size: 0.85rem;
    color: #ccc;
}

.thickness-bar input {
    width: 56px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    padding: 4px 6px;
    text-align: center;
    outline: none;
    -webkit-user-select: auto;
    user-select: auto;
}

.thickness-bar input:focus {
    border-color: #4CAF50;
}

.thickness-bar .unit {
    font-size: 0.85rem;
    color: #aaa;
}

/* Tap juhis */
.tap-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 8;
    pointer-events: none;
    animation: tap-pulse 2s ease-in-out infinite;
}

.tap-hint.hidden { display: none; }

.tap-hint span {
    display: inline-block;
    background: rgba(255, 152, 0, 0.85);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 10px 24px;
    border-radius: 24px;
}

@keyframes tap-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Tuvastatud mõõdud */
.detected-dims {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    z-index: 10;
    text-align: center;
    pointer-events: none;
}

.detected-dims.hidden { display: none; }

#detected-text {
    display: inline-block;
    background: rgba(76, 175, 80, 0.85);
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    padding: 8px 20px;
    border-radius: 10px;
}

/* Kinnita nupp */
.confirm-bar {
    position: absolute;
    bottom: 10px;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    padding: 0 20px;
}

.confirm-bar.hidden { display: none; }

.btn-confirm {
    background: #4CAF50;
    color: #fff;
    border: none;
    border-radius: 24px;
    padding: 10px 32px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.btn-confirm:active {
    background: #388E3C;
    transform: scale(0.97);
}

/* ── Tabel ── */
.table-area {
    flex-shrink: 0;
    background: #222;
    max-height: 40vh;
    display: flex;
    flex-direction: column;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 6px;
    flex-shrink: 0;
}

.table-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.btn-clear {
    background: none;
    border: 1px solid #555;
    color: #aaa;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
}

.btn-clear:active { background: #333; }

.table-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 12px;
    -webkit-overflow-scrolling: touch;
}

#measurements-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

#measurements-table th {
    text-align: left;
    color: #888;
    font-weight: 500;
    padding: 4px 8px;
    border-bottom: 1px solid #333;
    font-size: 0.75rem;
}

#measurements-table td {
    padding: 8px;
    border-bottom: 1px solid #2a2a2a;
}

#measurements-table td:first-child {
    color: #888;
    width: 30px;
}

#measurements-table td:nth-child(2) {
    font-weight: 700;
    color: #4CAF50;
    font-size: 0.95rem;
}

#measurements-table td:nth-child(3) {
    color: #666;
    font-size: 0.75rem;
    text-align: right;
}

.table-empty {
    text-align: center;
    color: #555;
    font-size: 0.85rem;
    padding: 16px 0;
}

.table-empty.hidden { display: none; }

@keyframes row-flash {
    0% { background: rgba(76, 175, 80, 0.3); }
    100% { background: transparent; }
}

.row-new {
    animation: row-flash 1s ease-out;
}

/* ── Veateade ── */
.error-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
}

.error-overlay.hidden { display: none; }

.error-content {
    background: #2a2a2a;
    border-radius: 12px;
    padding: 24px;
    margin: 24px;
    text-align: center;
    max-width: 320px;
}

.error-content p {
    margin-bottom: 16px;
    font-size: 1rem;
    line-height: 1.4;
}

.btn-action {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}

.btn-green {
    background: #4CAF50;
    color: #fff;
}

.btn-green:active { background: #388E3C; }
