:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-sheet: rgba(30, 41, 59, 0.95);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --border-color: rgba(255, 255, 255, 0.1);
    --font-main: 'Outfit', sans-serif;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    /* App-like feel */
    width: 100vw;
    height: 100vh;
    height: 100svh;
    /* for mobile browsers */
}

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

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    background: linear-gradient(to bottom, rgba(15, 23, 42, 0.9) 0%, transparent 100%);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.logo i {
    color: var(--primary);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: var(--transition);
}

.icon-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
}

/* Scanner Area */
.scanner-container {
    flex: 1;
    position: relative;
    background-color: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

#reader {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide some default html5-qrcode ui elements */
#reader__dashboard_section_csr,
#reader__dashboard_section_swaplink {
    display: none !important;
}

/* Pastikan video memenuhi layar penuh tapi tidak merusak library */
#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* Biarkan canvas bawaan html5-qrcode tetap ada agar scanner area (qrbox) bekerja */
#reader canvas {
    /* Menghapus display: none agar library tidak error */
}

/* Custom Overlay */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
    box-shadow: inset 0 0 0 100vmax rgba(0, 0, 0, 0.5);
    /* Dimming around frame */
}

.scan-frame {
    width: 250px;
    height: 250px;
    position: relative;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.6);
}

.corner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 4px solid var(--accent);
}

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

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

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

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

.scan-line {
    position: absolute;
    width: 90%;
    height: 2px;
    background: var(--accent);
    left: 5%;
    box-shadow: 0 0 10px 2px rgba(16, 185, 129, 0.5);
    animation: scan 2s linear infinite;
}

@keyframes scan {
    0% {
        top: 0;
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        top: 100%;
        opacity: 0;
    }
}

.scan-hint {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    z-index: 10;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 8;
    color: var(--primary);
    font-size: 2.5rem;
    gap: 1rem;
}

.loading-overlay p {
    font-size: 1rem;
    color: var(--text-muted);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

/* Bottom Nav */
.bottom-nav {
    display: flex;
    justify-content: space-around;
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.nav-item i {
    font-size: 1.5rem;
}

.nav-item.active {
    color: var(--primary);
}

.upload-wrapper input[type="file"] {
    display: none;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

/* Bottom Sheet */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-sheet);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(110%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 20;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.bottom-sheet.open {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 12px auto;
}

.sheet-content {
    padding: 0 1.5rem 2rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

.result-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 1.5rem;
    gap: 0.5rem;
}

.icon-circle {
    width: 60px;
    height: 60px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.result-body {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

textarea#result-text {
    width: 100%;
    height: 80px;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    outline: none;
    line-height: 1.4;
}

/* Scrollbar for textarea */
textarea#result-text::-webkit-scrollbar {
    width: 4px;
}

textarea#result-text::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.result-actions:has(#btn-open[style*="display: flex"]) {
    /* CSS conditional grid */
    grid-template-columns: 1fr 1fr 1fr;
}

/* Fallback if :has not supported */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.action-btn.primary {
    background: var(--primary);
    color: white;
    grid-column: span 2;
    /* Default spread if open btn is alone row */
}

/* Better grid logic applied via JS based on btn-open visibility */
.results-grid-2 {
    grid-template-columns: 1fr 1fr;
}

.results-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.action-btn.primary {
    background: var(--primary);
    color: white;
}

.action-btn.primary:active {
    background: var(--primary-hover);
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.action-btn.secondary:active {
    background: rgba(255, 255, 255, 0.15);
}

.close-btn {
    width: 100%;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    padding: 0.8rem 1.5rem;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Make qr video fill container */
#reader video {
    object-fit: cover !important;
}