:root {
    /* Palette */
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-light: #eff6ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #22c55e;

    /* Components */
    --header-h: 64px;
    --nav-h: 80px;

    /* Radius */
    --r-xl: 24px;
    --r-lg: 16px;
    --r-md: 12px;

    /* Glass */
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-blur: blur(12px);

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

/* Touch optimization for interactive elements */
button,
a,
input,
select,
.nav-item,
.fab-scan,
.hero-btn,
.icon-btn {
    touch-action: manipulation;
}

html {
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body.app-shell {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: block;
}


/* --- App Container (shown after login) --- */
.app-container {
    display: contents;
    /* Don't create a box, just group elements */
}

.app-container[hidden] {
    display: none !important;
}

body.auth-loading .app-container,
body.auth-loading .nav-container {
    visibility: hidden;
    pointer-events: none;
}

/* --- Header --- */
header {
    height: var(--header-h);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    box-sizing: content-box;
}

body.app-shell header {
    position: sticky;
}


.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 19px;
    color: var(--brand);
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--brand-light);
    color: var(--brand);
    border-radius: 8px;
    display: grid;
    place-items: center;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-sub);
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
}

.icon-btn:active {
    background: var(--bg);
    color: var(--text-main);
}

/* --- Main Content --- */
main {
    flex: 1;
    margin-top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    padding: 16px;
    padding-bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    width: 100%;
    box-sizing: border-box;
}

body.app-shell main {
    margin-top: 0;
    overflow: visible;
}



.view-section {
    display: none;
    animation: viewEnter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-section.active {
    display: block;
}

@keyframes viewEnter {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}


/* --- Hero / Empty State --- */
.hero-scan {
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: white;
    border-radius: var(--r-xl);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.4);
    position: relative;
    overflow: hidden;
}

.hero-scan::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 60%);
    pointer-events: none;
}

.hero-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 4px 0;
}

.hero-sub {
    opacity: 0.9;
    font-size: 13px;
    margin: 0;
}

.scan-action-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}

.hero-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 16px;
    border-radius: 99px;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    gap: 6px;
}

.hero-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.98);
}

/* --- Item Cards (Ulaz) --- */
.item-card {
    background: white;
    border-radius: var(--r-lg);
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid transparent;
}

.item-card:active {
    border-color: var(--brand);
    background: var(--brand-light);
}

.qty-box {
    width: 44px;
    height: 44px;
    background: #f1f5f9;
    color: var(--text-main);
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 17px;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-meta {
    font-size: 12px;
    color: var(--text-sub);
    display: flex;
    gap: 8px;
}

/* --- Supply Search & Result --- */
.search-bar {
    position: relative;
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    padding: 14px 14px 14px 44px;
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    font-size: 16px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
    transition: all 0.2s;
}

.search-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-light);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-sub);
    pointer-events: none;
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: #e2e8f0;
    border: none;
    color: var(--text-sub);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.search-clear:active {
    background: #cbd5e1;
}

/* Suggestions Dropdown */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--r-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    margin-top: 8px;
    z-index: 200;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    display: none;
}

.suggestions-list.active {
    display: block;
}

.suggestion-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: #f8fafc;
}

.sugg-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.sugg-meta {
    font-size: 12px;
    color: var(--text-sub);
    display: flex;
    justify-content: space-between;
}

.sugg-price {
    font-weight: 700;
    color: var(--brand);
}

.supply-card {
    background: white;
    border-radius: var(--r-xl);
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.supply-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.supply-code {
    font-family: monospace;
    font-size: 13px;
    color: var(--text-sub);
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 6px;
}

.stock-grid {
    margin-top: 20px;
    display: grid;
    gap: 10px;
}

.stock-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #f8fafc;
    border-radius: 10px;
}

.stock-loc {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-sub);
}

.stock-val {
    font-weight: 700;
    color: var(--text-main);
}

.stock-val.pos {
    color: var(--success);
}

.stock-val.neg {
    color: var(--danger);
    opacity: 0.5;
}

/* --- Bottom Nav --- */
.nav-container {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 400px;
    height: var(--nav-h);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-radius: 24px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    z-index: 100;
    padding-bottom: 4px;
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-sub);
    font-size: 11px;
    font-weight: 600;
    width: 60px;
}

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

.nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 2px;
}

/* Floating Scan Button in Center of Nav */
.fab-scan {
    width: 56px;
    height: 56px;
    background: var(--text-main);
    color: white;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin-bottom: 24px;
    /* Pop out */
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.3);
    border: 4px solid var(--surface);
    transition: transform 0.15s;
}

.fab-scan:active {
    transform: scale(0.92);
}

/* --- Dialogs (Modern) --- */
dialog {
    padding: 0;
    border: none;
    background: transparent;
    max-width: 90vw;
    width: 360px;
    margin: auto;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

dialog form {
    background: white;
    border-radius: var(--r-xl);
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: center;
    max-height: 90svh;
    overflow-y: auto;
}

.modal-title {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 4px;
}

.modal-input {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 18px;
    text-align: center;
    font-weight: 600;
    font-family: monospace;
    background: #f8fafc;
}

.modal-input:focus {
    border-color: var(--brand);
    background: white;
}

.modal-btn {
    background: var(--brand);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
    width: 100%;
    font-size: 16px;
    cursor: pointer;
}

.modal-btn:active {
    opacity: 0.9;
    transform: scale(0.98);
}

.modal-btn.secondary {
    background: #f1f5f9;
    color: var(--text-main);
    margin-top: 0;
}

/* Utilities */
[hidden],
.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.4 !important;
    pointer-events: none !important;
}

/* --- Login Overlay --- */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    background: var(--bg);
    display: flex;
    align-items: flex-start;
    overflow-y: auto;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.login-overlay[hidden] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: flex !important;
    /* Override default hidden to allow transition */
}


/* --- Toast Notifications --- */
#toastContainer {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    max-width: 90vw;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    animation: toastIn 0.3s ease-out;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    color: white;
    font-weight: 600;
    background: #334155;
}

.toast.ok {
    background: var(--success);
}

.toast.err {
    background: var(--danger);
}

.toast.toast-draft {
    background: #1e40af;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 320px;
}

.toast-discard-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: white;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}

.toast-discard-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Confirm Dialog (Specifics) --- */
/* Base dialog styles apply to #confirmDialog too */
.dlg-header {
    text-align: center;
}

#dlgNameDisplay {
    font-size: clamp(13px, 4.5vw, 18px);
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 4px;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
}

.dlg-header .meta {
    font-size: 13px;
    color: var(--text-sub);
    display: flex;
    justify-content: center;
    gap: 12px;
}

.qty-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 8px 0;
}

.qty-btn {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: white;
    color: var(--brand);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.qty-btn:active {
    background: var(--brand-light);
    transform: scale(0.95);
}

.qty-btn.small {
    width: 36px;
    height: 36px;
    font-size: 10px;
    font-weight: 700;
    gap: 2px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-sub);
}

.qty-value {
    font-size: 28px;
    font-weight: 800;
    width: 60px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* --- Global Scanner Overlay --- */
.scanner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 3000;
    display: flex;
    flex-direction: column;
}

.scanner-header {
    height: 80px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 3002;
}

.close-scanner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    display: grid;
    place-items: center;
    backdrop-filter: blur(8px);
}

.scanner-ctrl {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    display: grid;
    place-items: center;
    backdrop-filter: blur(8px);
    transition: all 0.2s;
}

.scanner-ctrl.active {
    background: rgba(255, 204, 0, 0.9);
    color: #1a1a1a;
    border-color: rgba(255, 204, 0, 1);
}


.scanner-viewfinder {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-mount {
    width: 100% !important;
    height: 100% !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* Force library video to fill container */
.camera-mount video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* Hide library's scan region indicator visually but keep it in layout */
#qr-shaded-region {
    opacity: 0 !important;
    pointer-events: none !important;
}

.viewfinder-frame {
    position: absolute;
    width: 300px;
    height: 140px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    z-index: 3001;
    box-shadow: 0 0 0 5000px rgba(0, 0, 0, 0.6);
}

.viewfinder-frame::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 3px solid var(--brand);
    border-radius: 20px;
    animation: scanPulse 2s infinite ease-in-out;
}

.viewfinder-frame.scan-success {
    border-color: var(--success);
    animation: none;
}

.viewfinder-frame.scan-success::before {
    border-color: var(--success);
    animation: scanFlash 0.5s ease-out forwards;
}

@keyframes scanFlash {
    0% {
        opacity: 1;
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
    }
    60% {
        opacity: 1;
        transform: scale(1.06);
        box-shadow: 0 0 0 12px rgba(34, 197, 94, 0);
    }
    100% {
        opacity: 0.6;
        transform: scale(1.04);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}


@keyframes scanPulse {
    0% {
        opacity: 0.3;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.02);
    }

    100% {
        opacity: 0.3;
        transform: scale(1);
    }
}

.scanner-footer {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 3002;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}

.scanner-hint {
    color: white;
    font-size: 15px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(8px);
}
