/* === THEME === */
:root {
    /* Shop theme */
    --primary: #1D4461;
    --home-buttons: #1D4461;
    --over-primary: #FFF;
    --success: #008F39;
    --info: #2797F9;
    --warning: #FFEC44;
    --danger: #EB3107;
    --text: #333;
    --disabled: #888;
    --white: #FFF;
    --black: #000;
    --light-gray: #DDD;
    --gray: #AAA;
    --bg: #f8ece3;
    --font-tiny: 12px;
    --font-small: 15px;
    --font-medium: 20px;
    --font-large: 24px;
    --font-xl: 34px;
}
body.theme-basic {
    --primary: #D8AC48;
    --home-buttons: #161616;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    width: 100%; min-height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%;
    overflow: hidden;
}
body { display: flex; flex-direction: column; height: 100vh; }
input, select, button { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { text-decoration: none; color: inherit; }

/* === SCREENS === */
.screen { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; flex-direction: column; background: var(--bg); }
.screen.active { display: flex; }

/* === TOPBAR (Home) === */
.topbar {
    width: 100%; position: absolute; top: 0; left: 0; z-index: 10;
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 10px; background: var(--primary); color: var(--white);
    height: 42px;
}
.topbar-title { font-size: var(--font-small); font-weight: bold; }
.topbar-user { font-size: var(--font-large); cursor: pointer; }
.user-menu {
    display: none; position: absolute; right: 0; top: 57px; min-width: 200px;
    background: var(--primary); border-radius: 0; z-index: 20;
    box-shadow: 1px 1px 10px rgba(0,0,0,0.2);
}
.user-menu.show { display: block; }
.user-menu-item {
    display: flex; align-items: center; padding: 8px 12px; gap: 10px;
    border-top: 1px solid rgba(255,255,255,0.3); color: var(--white); cursor: pointer;
}
.user-menu-item:first-child { border-top: none; }
.user-menu-item:hover { opacity: 0.8; }
.user-menu-item .icon { font-size: var(--font-xl); }
.user-menu-item span { font-size: var(--font-small); font-weight: bold; }

/* === LOGIN === */
.login-bg {
    flex: 1; display: flex; justify-content: center; align-items: center;
    background-size: cover; background-position: center; background-repeat: no-repeat;
    background-color: var(--bg);
}
.login-box {
    width: 450px; max-width: 80%; padding: 30px 20px 50px;
    border-radius: 20px; display: flex; flex-direction: column; align-items: center;
    background: var(--white); box-shadow: 1px 1px 10px rgba(0,0,0,0.2);
}
.login-icon { font-size: var(--font-xl); color: var(--primary); }
.login-title { font-size: var(--font-large); font-weight: 100; text-align: center; margin-bottom: 20px; color: var(--primary); }
.login-input {
    padding: 5px 0; margin: 10px 0; font-size: var(--font-medium);
    border: none; border-bottom: 1px solid var(--gray); outline: none; width: 100%; max-width: 100%;
}
.login-error { color: var(--danger); display: none; margin-top: 5px; }

/* === HOME === */
.home-bg {
    flex: 1; position: relative;
    display: flex; flex-direction: column; align-items: flex-end;
    background-size: cover; background-position: center; background-repeat: no-repeat;
    background-color: var(--bg);
}
.menu-view {
    width: 160px; margin-right: 10px; padding: 50px 0 20px;
    height: 100%;
    display: flex; flex-direction: column; gap: 4px;
    overflow-y: auto; z-index: 5;
    -webkit-overflow-scrolling: touch;
}
/* Push items to vertical center when there's room, but allow scroll when not */
.menu-view::before {
    content: ''; margin-top: auto;
}
.menu-view::after {
    content: ''; margin-bottom: auto;
}
.menu-btn {
    position: relative; padding: 15px; margin: 2px; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    background: var(--home-buttons); box-shadow: 1px 1px 10px rgba(0,0,0,0.2);
    cursor: pointer; color: var(--white); text-align: center; font-size: var(--font-medium);
    flex-shrink: 0;
}
.menu-btn img { width: 40px; height: 40px; }
.menu-btn-text { font-size: var(--font-medium); }
.menu-counter {
    position: absolute; top: 2px; right: 3px; width: 30px; height: 30px;
    border-radius: 3px; border-top-right-radius: 10px;
    display: none; align-items: center; justify-content: center;
    background: var(--black); color: var(--white); font-weight: bold; font-size: var(--font-small);
}
.menu-counter.show { display: flex; }

/* === PAGE HEADER === */
.page-header {
    display: flex; align-items: center; padding: 30px 30px 15px;
    background: var(--primary); border-bottom-left-radius: 30px; border-bottom-right-radius: 30px;
    box-shadow: 1px 1px 10px rgba(0,0,0,0.2); flex-shrink: 0;
}
.page-header .back-btn { color: var(--over-primary); font-size: var(--font-xl); cursor: pointer; background: none; border: none; }
.page-header .title { flex-grow: 1; text-align: center; font-size: var(--font-large); color: var(--over-primary); }
.page-header .spacer { width: 34px; }

/* === SEARCH BAR === */
.search-bar {
    display: flex; align-items: center; background: var(--white);
    padding: 10px 15px; margin: 10px; border-radius: 10px; gap: 10px;
}
.search-bar .icon { color: var(--gray); font-size: var(--font-medium); }
.search-bar input { flex-grow: 1; border: none; outline: none; font-size: var(--font-small); min-width: 0; }
.search-bar .search-btn { background: none; border: none; cursor: pointer; }

/* === PAGE INFO / PAGINATION === */
.page-info {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 20px 10px; flex-shrink: 0;
}
.page-info-text {
    padding: 6px 12px; font-size: var(--font-small); font-weight: bold;
    border-radius: 5px; color: var(--white); background: var(--black);
}
.pagination { display: flex; align-items: center; gap: 3px; }
.pagination .page-label { margin-right: 10px; font-size: var(--font-small); }
.pagination .page-btn {
    border-radius: 5px; padding: 5px; min-width: 30px; min-height: 30px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary); color: var(--white); font-weight: bold;
    cursor: pointer; border: none;
}
.pagination .page-btn:disabled { opacity: 0.6; cursor: default; }

/* === LIST === */
.list-container { flex: 1; overflow-y: auto; }
.list-item {
    padding: 20px; border-bottom: 1px solid var(--light-gray); cursor: pointer;
}
.list-item:hover { background: rgba(0,0,0,0.02); }
.list-row { display: flex; width: 100%; gap: 5px; }
.list-text { font-size: var(--font-small); padding: 2px 0; }
.fill-right { flex-grow: 1; font-weight: bold; text-transform: uppercase; }
.empty-item { padding: 20px; color: var(--disabled); }

/* === PRODOTTO LIST ITEM === */
.prodotto-item { display: flex; gap: 10px; }
.prodotto-img-container {
    width: 120px; height: 120px; border-radius: 10px; overflow: hidden;
    border: 1px solid var(--light-gray); padding: 10px; flex-shrink: 0;
}
.prodotto-img-container img { width: 100%; height: 100%; object-fit: contain; border-radius: 10px; }
.prodotto-info { flex: 1; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.prodotto-price-block { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-top: 5px; }
.prodotto-price { font-weight: bold; font-size: var(--font-medium); color: var(--info); }
.prodotto-old-price { font-size: var(--font-small); color: var(--disabled); text-decoration: line-through; }

/* === RIPARAZIONE LIST ITEM === */
.rip-cod { font-weight: bold; width: 33%; }
.rip-date { text-align: center; width: 33%; }
.rip-ready { text-align: right; font-weight: bold; width: 33%; }
.rip-price { text-align: right; font-weight: bold; color: var(--info); font-size: var(--font-medium); }

/* === DETAIL SCREENS === */
.detail-scroll { flex: 1; overflow-y: auto; }
.block-title { padding: 20px; background: var(--light-gray); border-bottom: 1px solid var(--gray); }
.block-title-text { font-size: var(--font-small); text-transform: uppercase; }
.single-block { padding: 10px; border-bottom: 1px solid var(--gray); }
.single-block-title { font-size: var(--font-small); }
.single-block-text { font-size: var(--font-small); font-weight: bold; }

/* === GALLERY === */
.gallery-container { width: 100%; padding: 10px 20px; }
.gallery-main { width: 100%; height: 320px; padding: 10px; display: flex; align-items: center; justify-content: center; }
.gallery-main img { border-radius: 15px; max-width: 100%; width: 300px; height: 300px; object-fit: contain; }
.gallery-previews { display: flex; gap: 5px; flex-wrap: wrap; }
.gallery-preview {
    width: 70px; height: 70px; padding: 5px; cursor: pointer;
}
.gallery-preview img {
    width: 100%; height: 100%; border: 2px solid var(--light-gray); border-radius: 5px; object-fit: contain;
}
.gallery-preview.active img { border-color: var(--primary); }

/* === GENERIC BUTTON === */
.btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 10px 15px; border-radius: 10px; font-weight: bold;
    color: var(--white); cursor: pointer; border: none;
}
.btn-primary { background: var(--primary); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-info { background: var(--info); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* === MODAL === */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 100; justify-content: center; align-items: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--white); padding: 10px; max-width: 100%; max-height: 80%;
    width: 500px; border-radius: 20px; display: flex; flex-direction: column;
}
.modal-box.wide { width: 95%; max-height: 100%; }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    min-height: 35px; padding: 5px;
}
.modal-header .modal-title { font-size: var(--font-medium); font-weight: bold; }
.modal-header .close-btn { font-size: var(--font-large); cursor: pointer; background: none; border: none; }
.modal-content { overflow-y: auto; flex: 1; }

/* === ALERT === */
.alert-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 200; justify-content: center; align-items: center; cursor: pointer;
}
.alert-overlay.show { display: flex; }
.alert-content { max-width: 80%; text-align: center; }
.alert-content .icon { font-size: var(--font-xl); }

/* === VENDITA / CART === */
.cart-summary {
    display: flex; align-items: center; border-bottom: 1px solid var(--gray);
    padding: 10px 15px; flex-shrink: 0;
}
.cart-summary-col {
    display: flex; flex-direction: column; padding: 10px 20px 10px 0;
}
.cart-summary-col:not(:last-child) { border-right: 1px solid var(--gray); margin-right: 20px; }
.cart-summary-col .label { text-transform: uppercase; font-size: var(--font-small); }
.cart-summary-col.total .label { font-weight: bold; }
.cart-summary-col .value { font-size: var(--font-small); }
.cart-footer {
    display: flex; justify-content: space-between; padding: 10px 15px;
    border-top: 1px solid var(--gray); flex-shrink: 0;
}

/* === CART ITEM === */
.cart-item {
    padding: 10px; border-bottom: 1px solid var(--gray);
}
.cart-item-row { display: flex; padding: 5px 0; align-items: center; }
.cart-item-row .col { flex: 1; }
.cart-item-row .col-2 { flex: 2; }
.cart-item-row .col-3 { flex: 3; }
.cart-item-row .col-4 { flex: 4; }
.cart-item-header { font-size: var(--font-tiny); font-weight: bold; }
.cart-item-actions { display: flex; justify-content: flex-end; gap: 10px; }
.cart-item-actions button { padding: 5px 10px; cursor: pointer; background: none; border: none; font-size: var(--font-medium); }

/* === STATISTICHE === */
.stat-filters { padding: 10px 15px; }
.stat-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.stat-row label { white-space: nowrap; }
.stat-row input, .stat-row select {
    flex: 1; padding: 5px; border-radius: 5px; border: 1px solid var(--light-gray);
    background: var(--white);
}
.stat-section-title {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--gray); padding: 10px; font-weight: bold;
    font-size: var(--font-medium);
}
.stat-table { width: 100%; background: var(--white); }
.stat-table-row { display: flex; padding: 10px; border-bottom: 1px solid var(--gray); align-items: center; }
.stat-table-row .col-1 { flex: 1; }
.stat-table-row .col-2 { flex: 2; text-align: right; }
.stat-table-row .col-3 { flex: 3; }
.stat-table-header { font-size: var(--font-tiny); font-weight: bold; }

/* === INVENTARIO === */
.inv-mag-info {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 25px; flex-shrink: 0;
}
.inv-qta-row {
    display: flex; justify-content: center; align-items: center; gap: 10px;
    padding: 10px; flex-shrink: 0;
}
.inv-qta-row label { font-size: var(--font-large); }
.inv-qta-input {
    padding: 8px; width: 100px; border-radius: 5px; font-size: var(--font-large);
    border: 1px solid var(--light-gray); text-align: center;
}
.inv-scan-row {
    display: flex; justify-content: center; padding: 5px 10px 10px; flex-shrink: 0;
}
.inv-scan-row .btn { width: 100%; justify-content: center; }
.inv-manual-row {
    display: flex; justify-content: center; align-items: center; gap: 5px;
    padding: 5px 10px 10px; border-bottom: 1px solid var(--gray); flex-shrink: 0;
}
.inv-manual-row input {
    flex-grow: 1; padding: 8px; border-radius: 5px; font-size: var(--font-large);
    border: 1px solid var(--light-gray); text-align: center;
}
.inv-manual-label { font-size: var(--font-tiny); text-align: center; padding: 5px; flex-shrink: 0; }

/* === MOVIMENTO ITEM === */
.mov-item { padding: 10px; border-bottom: 1px solid var(--gray); }
.mov-row { display: flex; padding: 5px 0; align-items: center; }
.mov-row .col { flex: 1; }
.mov-header { font-size: var(--font-tiny); font-weight: bold; }
.mov-input {
    padding: 8px; width: 80px; border-radius: 5px; border: 1px solid var(--light-gray);
    text-align: center; font-size: var(--font-medium);
}
.mov-input-wide { width: 100%; max-width: 150px; }

/* === PICKING ITEM === */
.pick-item { padding: 10px; border-bottom: 1px solid var(--gray); }
.pick-row { display: flex; padding: 2px 0; align-items: center; }
.pick-row .col { flex: 1; }
.pick-row .col-2 { flex: 2; }
.pick-row .col-3 { flex: 3; }
.pick-header { font-size: var(--font-tiny); font-weight: bold; }

/* === GIACENZA ITEM === */
.giac-item { padding: 10px; border-bottom: 1px solid var(--gray); }
.giac-row { display: flex; padding: 2px 0; align-items: center; }
.giac-row .col { flex: 1; text-align: center; }
.giac-header { font-size: var(--font-tiny); font-weight: bold; }
.giac-input {
    padding: 8px; width: 60px; border-radius: 5px; border: 1px solid var(--light-gray); text-align: center;
}
.giac-input.error { border-color: var(--danger); }

/* === RIPARAZIONE DETAIL === */
.rip-detail-sms {
    display: flex; align-items: center; justify-content: space-between; padding: 10px;
    border-bottom: 1px solid var(--gray);
}
.rip-detail-sms .sms-check { display: flex; align-items: center; gap: 10px; }
.rip-detail-sms input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.rip-price-edit {
    display: flex; align-items: center; gap: 5px;
}
.rip-price-edit input {
    font-size: var(--font-small); font-weight: bold; padding: 3px 5px;
    border: 1px solid var(--light-gray); border-radius: 3px; background: var(--white);
}

/* === CLIENT SELECTOR ROW === */
.client-row {
    display: flex; align-items: center; padding: 5px 15px 20px; gap: 20px;
    border-bottom: 1px solid var(--gray); flex-shrink: 0;
}

/* === PICKING CLIENT/MAG INFO === */
.pick-info-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 25px; flex-shrink: 0;
}

/* === BARCODE SCANNER === */
#barcode-reader { width: 100%; min-height: 300px; }
#barcode-reader video { border-radius: 10px; }
#barcode-reader__scan_region { border-radius: 10px; overflow: hidden; }
#barcode-reader__dashboard { padding: 10px 0 0; }
#barcode-reader__dashboard button {
    background: var(--primary); color: var(--white); border: none;
    padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: var(--font-small);
}
#barcode-reader__dashboard select {
    padding: 6px 10px; border-radius: 8px; border: 1px solid var(--light-gray); font-size: var(--font-small);
}
/* Hide built-in file scan area */
#barcode-reader__filescan_input { display: none; }

/* === RESPONSIVE === */
@media (max-width: 600px) {
    .login-box { max-width: 90%; }
    .menu-view { width: 140px; }
    .modal-box { width: 95%; margin: 10px; }
    .prodotto-img-container { width: 80px; height: 80px; }
}
