/**
 * Barcode Scanner PWA
 * Styles
 */

:root {
    --bg: #f8f7f4;
    --bg-warm: #f3f1ec;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #9a9a9a;
    --accent: #10b981;
    --accent-light: #d1fae5;
    --accent-dark: #059669;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
    --border: rgba(0,0,0,0.06);
    --radius: 16px;
    --radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    gap: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* Logo & Menu */
.logo-wrapper {
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    flex-shrink: 0;
}

.logo-icon i {
    color: white;
    font-size: 1.25rem;
    line-height: 1;
}

.logo-text {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text);
}

.logo-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 200px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 100;
}

.logo-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background 0.15s ease;
}

.menu-item:hover,
.menu-item:focus {
    background: var(--bg-warm);
}

.menu-item i {
    width: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.menu-version {
    color: var(--text-muted);
    font-size: 0.8125rem;
    cursor: default;
}

.menu-version:hover {
    background: transparent;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.offline-badge {
    display: none;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: #fef3c7;
    color: #b45309;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

.offline-badge.visible { display: flex; }

.counter {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-dark);
    box-shadow: var(--shadow-sm);
}

/* Scanner */
.scanner-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.scanner-wrapper {
    position: relative;
    aspect-ratio: 16/9;
    background: #1a1a1a;
}

#reader {
    width: 100%;
    height: 100%;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

#reader__scan_region { border: none !important; }
#reader__scan_region > img,
#reader__dashboard_section,
#reader__header_message { display: none !important; }

.scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    width: 90%;
    height: 70%;
    border: 2px solid rgba(255,255,255,0.6);
    border-radius: 12px;
    position: relative;
}

.scan-line {
    position: absolute;
    left: 5%;
    right: 5%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: scanline 1.8s ease-in-out infinite;
}

@keyframes scanline {
    0%, 100% { top: 15%; opacity: 0.5; }
    50% { top: 80%; opacity: 1; }
}

.scanner-status {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    background: var(--bg-warm);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.active {
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.status-dot.error { background: #ef4444; }

.status-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Actions */
.actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
    flex-shrink: 0;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    min-height: 56px;
}

.action-btn:active {
    transform: scale(0.97);
    background: var(--bg-warm);
}

.action-btn i {
    font-size: 1.25rem;
    color: var(--accent);
}

/* Input Panel */
.input-panel {
    display: none;
    flex-direction: column;
    gap: 0.625rem;
    flex-shrink: 0;
}

.input-panel.visible {
    display: flex;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.barcode-card {
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    box-shadow: var(--shadow-sm);
}

.barcode-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.barcode-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 600;
    word-break: break-all;
}

.barcode-format {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: var(--accent-light);
    color: var(--accent-dark);
    border-radius: 6px;
    font-size: 0.6875rem;
    font-weight: 600;
}

/* Quantity */
.quantity-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.625rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.qty-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    padding-left: 0.375rem;
    min-width: 50px;
}

.qty-btn {
    width: 52px;
    height: 52px;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 1.5rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.qty-btn:active {
    background: var(--accent);
    color: white;
    transform: scale(0.95);
}

.qty-input {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.75rem;
    font-weight: 600;
    text-align: center;
    height: 52px;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.qty-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Main Buttons */
.main-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
}

.main-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 56px;
}

.main-btn:active { transform: scale(0.97); }

.main-btn.cancel {
    background: var(--bg-warm);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.main-btn.save {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.main-btn i { font-size: 1.125rem; }

/* Recent Scans */
.recent-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.scan-list {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow-y: auto;
    flex: 1;
    min-height: 80px;
}

.scan-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

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

.scan-item-barcode {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.875rem;
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scan-item-qty {
    background: var(--accent-light);
    color: var(--accent-dark);
    padding: 0.25rem 0.625rem;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.8125rem;
}

.empty-state {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.empty-state i {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.4;
}

/* Footer */
.footer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
    margin-top: 0.625rem;
    flex-shrink: 0;
}

.footer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    min-height: 48px;
}

.footer-btn:active {
    transform: scale(0.97);
    background: var(--bg-warm);
}

.footer-btn i {
    font-size: 1rem;
    color: var(--accent);
}

/* Modal */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    z-index: 100;
    align-items: flex-end;
    padding: 1rem;
}

.modal-backdrop.visible { display: flex; }

.modal-content {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.modal-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-dark);
    font-size: 1rem;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-input {
    width: 100%;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    margin-bottom: 1rem;
    -webkit-user-select: text;
    user-select: text;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
}

/* Install Banner */
.install-banner {
    display: none;
    position: fixed;
    bottom: max(1rem, env(safe-area-inset-bottom));
    left: 1rem;
    right: 1rem;
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    z-index: 90;
    animation: slideUp 0.3s ease;
}

.install-banner.visible { display: block; }

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.install-banner-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.install-banner-icon i {
    font-size: 1.25rem;
    color: white;
}

.install-banner-text {
    flex: 1;
}

.install-banner-text strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 0.125rem;
}

.install-banner-text small {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.install-banner-close {
    width: 32px;
    height: 32px;
    background: var(--bg-warm);
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.install-banner-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.875rem;
}

.install-banner-actions button {
    flex: 1;
    padding: 0.75rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

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

.install-btn-secondary {
    background: var(--bg-warm);
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    padding: 0.875rem 1.25rem;
    border-radius: 14px;
    font-size: 0.9375rem;
    font-weight: 600;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    border: 1px solid var(--border);
    max-width: calc(100% - 2rem);
}

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

.toast.success { border-color: var(--accent); }
.toast.success i { color: var(--accent); }
.toast.error { border-color: #ef4444; }
.toast.error i { color: #ef4444; }

/* Standalone mode */
@media all and (display-mode: standalone) {
    .install-banner { display: none !important; }
}
