/* ========================================
   APP MERCADINHO - STYLES
   ======================================== */

:root {
    --primary: #7C3AED;
    --primary-light: #A78BFA;
    --primary-dark: #5B21B6;
    --secondary: #F59E0B;
    --secondary-light: #FCD34D;
    --success: #10B981;
    --success-light: #34D399;
    --danger: #EF4444;
    --danger-light: #F87171;
    --bg: #0F0E17;
    --bg-card: #1A1928;
    --bg-card-hover: #232237;
    --bg-input: #232237;
    --text: #FFFFFE;
    --text-muted: #A7A7BE;
    --text-dark: #0F0E17;
    --border: #2E2D45;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
    --gradient-primary: linear-gradient(135deg, #7C3AED 0%, #EC4899 100%);
    --gradient-secondary: linear-gradient(135deg, #F59E0B 0%, #EF4444 100%);
    --gradient-success: linear-gradient(135deg, #10B981 0%, #3B82F6 100%);
    --header-height: 64px;
    --nav-height: 72px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    display: flex;
    flex-direction: column;
}

/* ========================================
   HEADER
   ======================================== */
#app-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-emoji {
    font-size: 28px;
    animation: bounce 2s infinite;
}

#app-header h1 {
    font-size: 22px;
    font-weight: 900;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* ========================================
   MAIN / SCREENS
   ======================================== */
#app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 16px;
}

.screen {
    display: none;
    padding: 16px;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

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

/* ========================================
   WELCOME CARD
   ======================================== */
.welcome-card {
    background: var(--gradient-primary);
    border-radius: var(--radius);
    padding: 28px 20px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.welcome-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
}

.welcome-emoji {
    font-size: 56px;
    display: block;
    margin-bottom: 8px;
    animation: bounce 2s infinite;
}

.welcome-card h2 {
    font-size: 24px;
    font-weight: 900;
    margin-bottom: 4px;
}

.welcome-card p {
    font-size: 15px;
    opacity: 0.9;
}

/* ========================================
   STATS GRID
   ======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:active {
    transform: scale(0.97);
}

.stat-icon {
    font-size: 28px;
}

.stat-value {
    font-size: 22px;
    font-weight: 900;
    color: var(--text);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========================================
   SECTION HEADER
   ======================================== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    font-size: 18px;
    font-weight: 800;
}

/* ========================================
   SCREEN TITLE
   ======================================== */
.screen-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.screen-title span {
    font-size: 32px;
}

.screen-title h2 {
    font-size: 22px;
    font-weight: 900;
}

/* ========================================
   PRODUCT GRID (HOME)
   ======================================== */
.product-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: transform 0.2s;
    position: relative;
}

.product-card:active {
    transform: scale(0.97);
}

.product-card-img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    background: var(--bg-input);
}

.product-card-placeholder {
    width: 100%;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: var(--bg-input);
}

.product-card-info {
    padding: 10px;
}

.product-card-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card-price {
    font-size: 16px;
    font-weight: 900;
    color: var(--success-light);
    margin-bottom: 4px;
}

.product-card-stock {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.product-card-stock.out-of-stock {
    color: var(--danger-light);
}

.product-card-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.product-card-delete:active {
    opacity: 1;
}

/* ========================================
   EMPTY STATE
   ======================================== */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px 16px;
}

.empty-emoji {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 600;
}

.empty-hint {
    font-size: 13px !important;
    margin-top: 4px;
    opacity: 0.7;
}

/* ========================================
   FORMS
   ======================================== */
.register-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
}

.form-input {
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 16px;
    color: var(--text);
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

.form-input:focus {
    border-color: var(--primary);
}

.form-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

/* ========================================
   PHOTO AREA
   ======================================== */
.photo-area {
    position: relative;
}

.photo-preview-container {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 8px;
}

.photo-preview {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.btn-remove-photo {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-container {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 8px;
}

.camera-container video {
    width: 100%;
    border-radius: var(--radius-sm);
}

/* ========================================
   BARCODE SCANNER
   ======================================== */
.barcode-input-group {
    display: flex;
    gap: 8px;
}

.barcode-input-group .form-input {
    flex: 1;
}

.scanner-box {
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-top: 8px;
    position: relative;
}

.scanner-box video {
    width: 100%;
    border-radius: var(--radius-sm);
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    color: var(--text);
}

.btn:active {
    transform: scale(0.96);
}

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

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
}

.btn-success {
    background: var(--gradient-success);
    color: white;
}

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

.btn-full {
    width: 100%;
    padding: 16px;
    font-size: 17px;
}

.btn-small {
    padding: 8px 14px;
    font-size: 13px;
}

.btn-scan {
    background: var(--gradient-secondary);
    color: var(--text-dark);
    font-weight: 800;
}

.btn-photo {
    background: var(--bg-input);
    border: 2px dashed var(--border);
    width: 100%;
    padding: 32px 16px;
    font-size: 16px;
    color: var(--text-muted);
}

.btn-camera-snap {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gradient-primary);
    z-index: 5;
}

.btn-checkout:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-reset {
    width: 100%;
    margin-top: 8px;
    background: transparent;
    border: 2px solid var(--danger);
    color: var(--danger-light);
}

/* ========================================
   CART
   ======================================== */
.sell-scanner-area {
    margin-bottom: 16px;
}

.cart-section {
    margin-bottom: 16px;
}

.cart-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cart-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cart-item-img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.cart-item-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

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

.cart-item-name {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-price {
    font-size: 13px;
    color: var(--text-muted);
}

.cart-item-qty {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.cart-item-qty button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item-qty button:active {
    background: var(--primary);
}

.cart-item-qty span {
    font-size: 16px;
    font-weight: 800;
    min-width: 24px;
    text-align: center;
}

.cart-item-subtotal {
    font-size: 14px;
    font-weight: 800;
    color: var(--success-light);
    flex-shrink: 0;
    min-width: 64px;
    text-align: right;
}

.cart-item-remove {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
}

/* ========================================
   TOTAL & PAYMENT
   ======================================== */
.cart-total-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.total-label {
    font-size: 18px;
    font-weight: 700;
}

.total-value {
    font-size: 28px;
    font-weight: 900;
    background: var(--gradient-success);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.payment-section {
    margin-bottom: 16px;
}

.payment-input {
    margin-top: 8px;
    margin-bottom: 8px;
}

.change-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
}

.change-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-muted);
}

.change-value {
    font-size: 22px;
    font-weight: 900;
    color: var(--secondary);
}

.change-value.negative {
    color: var(--danger-light);
}

/* ========================================
   MODAL
   ======================================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    max-width: 340px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.modal-emoji {
    font-size: 56px;
    display: block;
    margin-bottom: 12px;
}

.modal-content h3 {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 8px;
}

.modal-content p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
}

.sale-success-modal .sale-summary {
    margin: 16px 0;
    text-align: left;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.sale-summary p {
    margin-bottom: 8px !important;
    color: var(--text);
    font-size: 15px;
}

.change-highlight {
    color: var(--secondary) !important;
    font-size: 18px !important;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ========================================
   SUCCESS FEEDBACK
   ======================================== */
.success-feedback {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 14, 23, 0.95);
    animation: popIn 0.3s ease;
}

.success-feedback.hidden {
    display: none;
}

.success-emoji {
    font-size: 80px;
    display: block;
    margin-bottom: 12px;
    animation: bounce 0.6s;
}

.success-feedback p {
    font-size: 20px;
    font-weight: 800;
    color: var(--success-light);
}

/* ========================================
   BOTTOM NAV
   ======================================== */
#bottom-nav {
    height: var(--nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

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

.nav-btn:active {
    transform: scale(0.92);
}

.nav-icon {
    font-size: 24px;
}

.nav-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========================================
   TOAST
   ======================================== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideUp 0.3s ease;
    white-space: nowrap;
}

.toast.hidden {
    display: none;
}

@keyframes slideUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ========================================
   UTILITIES
   ======================================== */
.hidden {
    display: none !important;
}

/* Scrollbar */
#app-main::-webkit-scrollbar {
    width: 4px;
}

#app-main::-webkit-scrollbar-track {
    background: transparent;
}

#app-main::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (min-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 768px) {
    #app-main {
        max-width: 540px;
        margin: 0 auto;
    }
}
