/* v1.1.0 — device-aware layer. device.js tags <html> with data-device="phone|tablet|desktop",
   data-os, data-orient; these rules refine the responsive base for real phones and tablets
   (bigger tap targets, safe-area padding, fewer columns, no hover-only affordances). */

/* ---------- shared (any touch device) ---------- */
html[data-touch="1"] .btn:hover, html[data-touch="1"] .icon-btn:hover, html[data-touch="1"] .card .add-btn:hover { transform: none; }
html[data-touch="1"] input, html[data-touch="1"] select, html[data-touch="1"] textarea { font-size: 16px; } /* iOS zooms on focus below 16px */
html[data-os="ios"] body, html[data-os="ipados"] body { -webkit-tap-highlight-color: transparent; }

/* ---------- PHONE (iPhone / Android phone) ---------- */
html[data-device="phone"] { --gutter: 16px; --section-gap: 44px; }
html[data-device="phone"] body { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* header: compact, big targets */
html[data-device="phone"] .header-row { min-height: 60px; gap: 6px; }
html[data-device="phone"] .icon-btn, html[data-device="phone"] .menu-btn { width: 44px; height: 44px; }
html[data-device="phone"] .brand-mark { width: 34px; height: 34px; font-size: 1.05rem; }
html[data-device="phone"] .brand-name { font-size: 1.05rem; }
html[data-device="phone"] .pref-group button { min-height: 44px; padding: 0 14px; font-size: .84rem; }
html[data-device="phone"] .preview-bar { padding: 8px 12px; font-size: .78rem; line-height: 1.35; }

/* buttons: taller, full width where they stack */
html[data-device="phone"] .btn { min-height: 52px; padding: 0 22px; font-size: 1rem; border-radius: 16px; }
html[data-device="phone"] .btn.sm { min-height: 44px; padding: 0 16px; font-size: .92rem; }
html[data-device="phone"] .hero-cta { flex-direction: column; gap: 10px; }
html[data-device="phone"] .hero-cta .btn { width: 100%; }
html[data-device="phone"] .hero-content { padding-block: 44px 34px; }
html[data-device="phone"] .hero h1 { font-size: clamp(1.9rem, 8.5vw, 2.5rem); }
html[data-device="phone"] .hero .lead { font-size: 1rem; }
html[data-device="phone"] .chip { min-height: 40px; padding: 0 14px; font-size: .92rem; display: inline-flex; align-items: center; }
html[data-device="phone"] .section-head { flex-direction: column; align-items: stretch; gap: 12px; }
html[data-device="phone"] .section-head .btn { align-self: flex-start; }

/* product cards: two columns, generous add button */
html[data-device="phone"] .product-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
html[data-device="phone"][data-orient="landscape"] .product-grid { grid-template-columns: repeat(3, 1fr); }
html[data-device="phone"] .card .add-btn { width: 46px; height: 46px; }
html[data-device="phone"] .card-name { font-size: .98rem; }
html[data-device="phone"] .usp { grid-template-columns: 1fr; gap: 10px; }
html[data-device="phone"] .usp-item { padding: 14px 16px; }

/* product page: variants and buy row easy to hit; buy row sticks to the bottom */
html[data-device="phone"] .variant { min-height: 48px; }
html[data-device="phone"] .buy-row { position: sticky; bottom: env(safe-area-inset-bottom, 0px); z-index: 20; background: var(--bg); padding: 12px 0; margin: 0 calc(var(--gutter) * -1); padding-inline: var(--gutter); box-shadow: 0 -10px 24px -18px rgba(0,0,0,.35); }
html[data-device="phone"] .buy-row .btn { min-width: 0; }
html[data-device="phone"] .qty button { width: 48px; height: 52px; }
html[data-device="phone"] .accordion summary { padding: 16px 0; min-height: 52px; }

/* cart drawer fills the screen; controls bigger */
html[data-device="phone"] .cart-drawer { width: 100vw; max-width: 100vw; padding-bottom: env(safe-area-inset-bottom, 0px); }
html[data-device="phone"] .cart-line .qty button { width: 44px; height: 44px; }
html[data-device="phone"] .cart-foot .btn { min-height: 54px; }

/* catalog filters panel full width */
html[data-device="phone"] .filters { width: 100vw; }
html[data-device="phone"] .check { min-height: 42px; }

/* checkout / account forms */
html[data-device="phone"] .form .two, html[data-device="phone"] .form .three { grid-template-columns: 1fr; }
html[data-device="phone"] .form input, html[data-device="phone"] .form select, html[data-device="phone"] .form textarea { min-height: 48px; }

/* floating controls stay above the home indicator */
html[data-device="phone"] .settings-fab { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); inset-inline-end: 16px; width: 48px; height: 48px; }
html[data-device="phone"] .settings-panel { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); inset-inline-end: 12px; width: calc(100vw - 24px); }
html[data-device="phone"] .toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 32px); text-align: center; }

/* footer: single column, comfortable links */
html[data-device="phone"] .footer-grid { grid-template-columns: 1fr; gap: 24px; }
html[data-device="phone"] .footer-grid a { display: inline-block; padding: 6px 0; }

/* ---------- TABLET (iPad / Android tablet) ---------- */
html[data-device="tablet"] .btn { min-height: 48px; }
html[data-device="tablet"] .icon-btn { width: 44px; height: 44px; }
html[data-device="tablet"] .product-grid { grid-template-columns: repeat(3, 1fr); }
html[data-device="tablet"][data-orient="landscape"] .product-grid { grid-template-columns: repeat(4, 1fr); }
html[data-device="tablet"] .chip { min-height: 40px; display: inline-flex; align-items: center; }
html[data-device="tablet"] .settings-fab { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }

/* =====================================================================
   ADMIN (body.admin) — phone and tablet
   ===================================================================== */
body.admin .bottom-nav { display: none; }

html[data-device="phone"] body.admin .main { padding: 12px 14px calc(84px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"] body.admin .topbar { margin-bottom: 14px; }
html[data-device="phone"] body.admin .topbar h1 { font-size: 1.3rem; }
html[data-device="phone"] body.admin .topbar .tools { width: 100%; }
html[data-device="phone"] body.admin .topbar .tools .btn, html[data-device="phone"] body.admin .search-row .btn { min-height: 44px; }
html[data-device="phone"] body.admin .search-row { gap: 8px; }
html[data-device="phone"] body.admin .search-row input, html[data-device="phone"] body.admin .search-row select { flex: 1 1 45%; min-height: 44px; min-width: 0; }
html[data-device="phone"] body.admin .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
html[data-device="phone"] body.admin .stat { padding: 12px 14px; }
html[data-device="phone"] body.admin .stat b { font-size: 1.25rem; }
html[data-device="phone"] body.admin .panel { padding: 14px; border-radius: 16px; }
html[data-device="phone"] body.admin .tbl { font-size: .84rem; min-width: 560px; }
html[data-device="phone"] body.admin .tbl th, html[data-device="phone"] body.admin .tbl td { padding: 10px 6px; }
html[data-device="phone"] body.admin .tbl td:first-child { white-space: nowrap; }
html[data-device="phone"] body.admin .tbl-wrap { margin: 0 -14px; padding: 0 14px; -webkit-overflow-scrolling: touch; }
html[data-device="phone"] body.admin .btn { min-height: 46px; }
html[data-device="phone"] body.admin .btn.tiny { min-height: 38px; }
html[data-device="phone"] body.admin .actions { gap: 10px; }
html[data-device="phone"] body.admin .f input, html[data-device="phone"] body.admin .f select, html[data-device="phone"] body.admin .f textarea { min-height: 46px; }
html[data-device="phone"] body.admin .modal { padding: 16px; padding-inline-end: 54px; max-height: calc(var(--vh, 100vh) - 24px); border-radius: 16px; }   /* v1.9.1: real viewport height; taller dialogs scroll inside the backdrop */
html[data-device="phone"] body.admin .tabs button { min-height: 44px; padding: 0 12px; }
html[data-device="phone"] body.admin .side { width: min(86vw, 320px); padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"] body.admin .side a { min-height: 46px; }

/* bottom tab bar (rendered by admin.js; visible on phones only) */
html[data-device="phone"] body.admin .bottom-nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 75; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -8px 24px -16px rgba(0,0,0,.3); }
body.admin .bottom-nav a, body.admin .bottom-nav button { display: grid; justify-items: center; gap: 3px; padding: 6px 2px; border-radius: 12px; font-size: .68rem; font-weight: 600; color: var(--text-2); line-height: 1.1; text-align: center; }
body.admin .bottom-nav a.active { color: var(--accent); background: var(--accent-soft); }
body.admin .bottom-nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
body.admin .bottom-nav .badge { position: absolute; }
body.admin .bottom-nav a { position: relative; }
body.admin .bottom-nav .badge { top: 2px; inset-inline-end: 12%; background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .62rem; padding: 1px 6px; font-weight: 700; }

/* tablet admin: sidebar stays, but touch sizing */
html[data-device="tablet"] body.admin .btn { min-height: 44px; }
html[data-device="tablet"] body.admin .side a { min-height: 44px; }
html[data-device="tablet"] body.admin .f input, html[data-device="tablet"] body.admin .f select { min-height: 44px; }
html[data-device="tablet"] body.admin .cards { grid-template-columns: repeat(3, 1fr); }

/* ---------- profit report (admin) ---------- */
.report-tbl td, .report-tbl th { white-space: nowrap; }

.profit-chart { width: 100%; height: auto; display: block; font-family: var(--font-body); }
.profit-chart .grid line { stroke: var(--line); }
.profit-chart .lbl { fill: var(--muted); font-size: 11px; }
.profit-chart .val { fill: var(--text-2); font-size: 10px; }
.profit-chart .bar-sales { fill: var(--accent); opacity: .55; }
.profit-chart .bar-cost { fill: var(--muted); opacity: .45; }
.profit-chart .bar-profit { fill: var(--success); }
.profit-chart .bar-profit.neg { fill: var(--danger); }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--text-2); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-inline-end: 6px; }
.stat.profit b { color: var(--success); } .stat.profit.neg b { color: var(--danger); }
.quick-ranges { display: flex; gap: 6px; flex-wrap: wrap; }
.quick-ranges button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: .82rem; font-weight: 600; color: var(--text-2); }
.quick-ranges button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
html[data-device="phone"] .quick-ranges button { min-height: 40px; }

/* ---------- v1.2.0 — admin product editor on phones ---------- */
html[data-device="phone"] body.admin .f input, html[data-device="phone"] body.admin .f select, html[data-device="phone"] body.admin .f textarea { box-sizing: border-box; max-width: 100%; }
html[data-device="phone"] body.admin .imgs { grid-template-columns: 1fr 1fr; }
html[data-device="phone"] body.admin .imgs .img input { min-height: 40px; font-size: 16px; }
html[data-device="phone"] body.admin .vrow { padding: 12px; }
html[data-device="phone"] body.admin .vact .btn.tiny { min-height: 42px; }
/* the product Save bar stays reachable above the bottom tab bar */
html[data-device="phone"] body.admin #pf .save-bar { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); background: var(--surface); padding: 10px 0; z-index: 30; border-top: 1px solid var(--line); margin-top: 4px; }
html[data-device="phone"] body.admin #pf .save-bar .btn { min-height: 48px; padding-inline: 26px; }
html[data-device="phone"] body.admin .modal .actions .btn { min-height: 46px; }

/* v1.3.0 — product editor on phones */
html[data-device="phone"] body.admin .sel-add { flex-wrap: wrap; }
html[data-device="phone"] body.admin .sel-add select { flex: 1 1 100%; }
html[data-device="phone"] body.admin .xbox input { width: 24px; height: 24px; }
html[data-device="phone"] body.admin .en-row input, html[data-device="phone"] body.admin .en-row textarea { min-height: 42px; }

/* ---------- v1.8.0 — phone held sideways (iPhone 15 landscape, 852×393) ---------- */
/* product page: photo beside the details instead of one 1000px-tall photo; the photo box never exceeds the screen */
html[data-device="phone"][data-orient="landscape"] .pdp { grid-template-columns: 1fr 1fr; gap: 20px; padding-top: 14px; }
html[data-device="phone"][data-orient="landscape"] .gallery { position: static; }
html[data-device="phone"][data-orient="landscape"] .gallery-main { max-height: 78vh; }
html[data-device="phone"][data-orient="landscape"] .gallery-main img { width: 100%; height: 100%; }
/* overlays keep their close button on screen and scroll inside when taller than the (short) screen */
html[data-device="phone"][data-orient="landscape"] .cart-drawer { width: min(100vw, 480px); }
html[data-device="phone"][data-orient="landscape"] .settings-panel { max-height: calc(var(--vh, 100vh) - 100px); overflow: auto; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"][data-orient="landscape"] .mobile-nav .panel { padding: 14px 18px; }
html[data-device="phone"][data-orient="landscape"] .mobile-nav a { padding: 9px 6px; font-size: 1rem; }
html[data-device="phone"][data-orient="landscape"] .hero-content { padding-block: 24px 20px; }
html[data-device="phone"][data-orient="landscape"] .hero h1 { font-size: 1.8rem; }
html[data-device="phone"][data-orient="landscape"] .product-grid { grid-template-columns: repeat(3, 1fr); }
/* admin dialogs on a sideways phone: never taller than the screen, scroll inside, buttons reachable */
html[data-device="phone"][data-orient="landscape"] body.admin .modal { max-height: calc(var(--vh, 100vh) - 16px); padding: 12px 54px 12px 14px; }
html[data-device="phone"][data-orient="landscape"] body.admin .main { padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }


/* ---------- v1.8.0 — phone: cards, showcase, quick filters, edit mode ---------- */
html[data-device="phone"] .card > .card-name { font-size: 1.05rem; padding: 12px 12px 8px; }
html[data-device="phone"] .card-short { font-size: .9rem; }
html[data-device="phone"] .card-desc { font-size: .8rem; }
html[data-device="phone"] .show-slide { flex-basis: 100%; }
html[data-device="phone"] .show-foot .btn.sm { min-height: 46px; flex: 1 1 auto; }
html[data-device="phone"] .fchip { min-height: 44px; }
html[data-device="phone"] .qf-cats .fchip { min-height: 48px; flex: 1 1 auto; justify-content: center; }
html[data-device="phone"] .em-bar { inset-inline-start: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"] .em-tools { max-width: calc(100vw - 20px); }

/* v1.8.0 — phone hero: the photo's face stays visible at the top, the headline sits in the lower part over the wash */
html[data-device="phone"] .hero-content { padding-block: min(50vh, 430px) 26px; }
html[data-device="phone"] .hero .layer-photo img { object-position: var(--focal-mobile, 38% 18%); }
html[data-device="phone"] .hero .layer-wash { background: linear-gradient(180deg, transparent 0%, transparent 30%, var(--hero-wash-2) 58%); }
html[data-device="phone"][data-orient="landscape"] .hero-content { padding-block: 24px 20px; }


/* ---------- v1.8.0 — audit fixes (phone) ---------- */
html[data-device="phone"] .search-form .search-btn { width: 44px; height: 44px; }
html[data-device="phone"] .chip, html[data-device="phone"] .check { min-height: 44px; }
html[data-device="phone"] .cart-line .rm { min-height: 44px; display: inline-flex; align-items: center; padding: 0 6px; margin-top: 0; }
html[data-device="phone"] .star-input label { min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; }
html[data-device="phone"] .switch { width: 56px; height: 32px; } html[data-device="phone"] .switch::after { width: 26px; height: 26px; }
html[data-device="phone"] .toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"] .footer-grid a:not(.wa-btn):not(.brand) { display: inline-block; padding: 6px 0; }
html[data-device="phone"] .footer-grid .wa-btn { display: inline-flex; padding: 6px 12px; }
html[data-device="phone"] .form input:is([type="radio"], [type="checkbox"], [type="file"]) { min-height: 0; }
html[data-device="phone"] body[data-page="product"] .as-fab { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
html[data-device="phone"] .as-fab { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
html[data-touch="1"] .card:hover { transform: none; box-shadow: var(--shadow-s); }
html[data-touch="1"] .card:hover .card-media img { transform: none; }
html[data-device="phone"][data-orient="landscape"] .cart-head { padding: 10px 16px; }
html[data-device="phone"][data-orient="landscape"] .cart-foot { padding: 10px 16px; }
html[data-device="phone"][data-orient="landscape"] .cart-foot .btn { min-height: 46px; }
