
:root{
  --bg:#0a3e40;
  --bg-2:#0f4b4d;
  --green:#39c29a;
  --green-2:#2eab87;
  --red:#ff686a;
  --red-2:#e95256;
  --white:#f7fffd;
  --ink:#0a3032;
  --muted:#afd5cf;
  --panel:#f5fbf9;
  --shadow:0 14px 40px rgba(0,0,0,.16);
  --product-columns:2;
  --product-icon-scale:82%;
}

*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:#d7fbf2;font-family:Inter,ui-rounded,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:var(--white)}
body{display:flex;justify-content:center}
button,input,select{font:inherit}
button{cursor:pointer}

.app-shell{
  width:min(100%,680px);
  min-height:100dvh;
  background:
    radial-gradient(circle at 15% 5%, rgba(70,216,177,.20), transparent 28%),
    linear-gradient(180deg,var(--bg-2),var(--bg));
  padding:calc(18px + env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
  position:relative;
}

.topbar{display:flex;justify-content:space-between;gap:16px;align-items:flex-start;margin-bottom:18px}
.eyebrow{margin:0 0 3px;text-transform:uppercase;font-size:.72rem;letter-spacing:.16em;color:#7fe1c5;font-weight:800}
h1{margin:0;font-size:clamp(2rem,8vw,3.35rem);line-height:.98;letter-spacing:-.045em}
.subtitle{margin:10px 0 0;color:#c6e5df;font-size:.95rem}
.round-btn{
  width:46px;height:46px;border-radius:50%;border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.10);color:white;font-size:1.6rem
}

.screen{display:none}
.screen.active{display:block}
.screen[hidden]{display:none!important}

.section-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:10px 2px 14px}
.section-head h2{margin:0;font-size:1.12rem}
.section-subtitle{margin:4px 0 0;color:var(--muted);font-size:.86rem}
.counter{background:rgba(255,255,255,.12);padding:7px 10px;border-radius:999px;color:#d8f5ee;font-size:.8rem}

.product-grid{
  display:grid;
  grid-template-columns:repeat(var(--product-columns),minmax(0,1fr));
  gap:12px;
}

.product-card{
  min-width:0;
  border-radius:24px;
  background:linear-gradient(180deg,#43caa4,var(--green-2));
  box-shadow:var(--shadow);
  overflow:hidden;
  transition:transform .14s ease, background .2s ease;
  border:1px solid rgba(255,255,255,.10);
}
.product-card.selected{background:linear-gradient(180deg,#ff7679,var(--red-2))}
.product-card:active{transform:scale(.985)}

.product-main{
  width:100%;
  border:0;background:transparent;color:white;
  padding:16px 12px 10px;display:flex;flex-direction:column;align-items:center;
}
.product-icon{
  width:100%;
  aspect-ratio:1.25/1;
  display:grid;place-items:center;
}
.product-icon svg{width:var(--product-icon-scale);height:var(--product-icon-scale);stroke:currentColor;fill:none;stroke-width:2.7;stroke-linecap:round;stroke-linejoin:round}
.product-name{font-weight:850;font-size:1.05rem;margin-top:4px;text-align:center}

.qty-controls{
  display:none;
  margin:0 12px 12px;
  grid-template-columns:1fr 1fr 1fr;align-items:center;
  background:rgba(120,10,20,.17);border-radius:15px;overflow:hidden;
}
.product-card.selected .qty-controls{display:grid}
.qty-btn{border:0;background:transparent;color:white;font-size:1.55rem;line-height:42px}
.qty-value{text-align:center;font-weight:900;font-size:1.1rem}

.bottom-nav{
  position:fixed;z-index:20;left:50%;transform:translateX(-50%);bottom:0;
  width:min(100%,680px);padding:8px 12px calc(8px + env(safe-area-inset-bottom));
  display:grid;grid-template-columns:repeat(3,1fr);gap:6px;
  background:rgba(6,40,42,.96);backdrop-filter:blur(18px);
  border-top:1px solid rgba(255,255,255,.08)
}
.nav-btn{
  position:relative;border:0;background:transparent;color:#b4d4cf;border-radius:18px;
  min-height:58px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  font-size:.76rem
}
.nav-btn.active{background:#227e72;color:white}
.nav-icon{font-size:1.32rem;line-height:1}
.nav-badge{
  position:absolute;right:20%;top:5px;background:var(--red);color:white;
  min-width:20px;height:20px;border-radius:999px;display:grid;place-items:center;font-size:.68rem;font-weight:900
}

.empty-state{
  margin-top:36px;text-align:center;padding:32px 18px;border:1px dashed rgba(255,255,255,.22);
  border-radius:24px;color:#d8efea
}
.empty-icon{font-size:2.4rem}
.empty-state h3{margin:12px 0 6px}
.empty-state p{margin:0;color:var(--muted)}

.settings-card{
  background:var(--panel);color:var(--ink);border-radius:22px;padding:16px;margin-bottom:14px;box-shadow:var(--shadow)
}
.settings-card label{display:block;font-size:.82rem;font-weight:800;margin-bottom:12px}
.settings-card input,.settings-card select{
  width:100%;margin-top:6px;border:1px solid #c9dfda;border-radius:13px;padding:12px;background:white;color:#17393a;outline:none
}
.form-actions{display:flex;flex-wrap:wrap;gap:8px}
.primary-btn,.secondary-btn,.text-btn{
  border:0;border-radius:13px;padding:11px 14px;font-weight:800
}
.primary-btn{background:#14896f;color:white}
.secondary-btn{background:#e2efec;color:#22504b}
.text-btn{background:rgba(255,255,255,.10);color:white}
.text-btn.danger{color:#ffd8d8}

.settings-card h3{margin:0 0 10px}
.display-settings label:last-child{margin-bottom:0}
.display-settings output{float:right;color:#51746d;font-weight:700}
.display-settings input[type="range"]{padding:0;accent-color:#14896f}

:root[data-product-view="list"] .product-grid{grid-template-columns:1fr;gap:6px}
:root[data-product-view="list"] .product-card{border-radius:14px}
:root[data-product-view="list"] .product-main{padding:6px 10px;display:grid;grid-template-columns:38px minmax(0,1fr) auto;gap:8px;align-items:center;text-align:left}
:root[data-product-view="list"] .product-icon{width:38px;aspect-ratio:1}
:root[data-product-view="list"] .product-icon svg{width:88%;height:88%}
:root[data-product-view="list"] .product-name{margin:0;text-align:left;font-size:.92rem}
:root[data-product-view="list"] .product-price-line{margin:0;white-space:nowrap;font-size:.68rem}
:root[data-product-view="list"] .qty-controls{margin:0 8px 7px;border-radius:10px}
:root[data-product-view="list"] .qty-btn{font-size:1.25rem;line-height:32px}
:root[data-product-view="list"] .qty-value{font-size:.95rem}
:root[data-product-view="list"] .change-group-btn{margin:-2px 8px 6px auto;padding:2px 8px;font-size:.66rem}
:root[data-product-view="list"] .product-subtotal{margin:-2px 8px 7px;font-size:.68rem}
:root[data-product-view="list"] .bought-btn{width:calc(100% - 16px);margin:0 8px 8px;padding:7px;border-radius:10px;font-size:.8rem}
.settings-list{display:flex;flex-direction:column;gap:8px}
.settings-row{
  display:grid;grid-template-columns:44px 1fr auto auto;gap:8px;align-items:center;padding:8px;border-radius:14px;background:#eaf5f2
}
.settings-mini-icon{width:40px;height:40px;display:grid;place-items:center;color:#1e7768}
.settings-mini-icon svg{width:36px;height:36px;stroke:currentColor;fill:none;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
.settings-name{font-weight:800}
.icon-btn{border:0;background:white;border-radius:10px;padding:8px 9px}
.icon-btn.delete{color:#bd3239}

@media (max-width:380px){
  :root:not([data-product-view="list"]) .product-grid{gap:9px}
  :root:not([data-product-view="list"]) .product-card{border-radius:20px}
  :root:not([data-product-view="list"]) .product-main{padding:13px 9px 8px}
  :root:not([data-product-view="list"]) .product-name{font-size:.95rem}
}

/* busca e biblioteca visual de ícones */
.search-wrap{
  position:relative;display:flex;align-items:center;margin:0 0 14px;
  background:rgba(255,255,255,.11);border:1px solid rgba(255,255,255,.12);
  border-radius:16px;padding:0 10px
}
.search-wrap input{
  flex:1;min-width:0;border:0;outline:0;background:transparent;color:white;
  padding:12px 8px;font-size:.95rem
}
.search-wrap input::placeholder{color:#a9d0ca}
.search-icon{font-size:1.3rem;color:#91d8c7}
.search-clear{border:0;background:transparent;color:white;font-size:1.4rem;padding:5px 8px}
.empty-state.compact{margin-top:14px;padding:20px 14px}

.icon-fieldset{border:0;padding:0;margin:0 0 14px}
.icon-fieldset legend{font-size:.82rem;font-weight:800;margin-bottom:8px}
.icon-picker{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:8px}
.icon-choice{
  aspect-ratio:1;border:2px solid transparent;background:#eaf5f2;color:#257968;
  border-radius:14px;padding:7px;display:grid;place-items:center;position:relative
}
.icon-choice svg{width:88%;height:88%;stroke:currentColor;fill:none;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
.icon-choice.selected{border-color:#14896f;background:#d6eee8;box-shadow:0 0 0 2px rgba(20,137,111,.12)}
.icon-choice.selected::after{content:'✓';position:absolute;right:4px;top:2px;font-size:.72rem;font-weight:900;color:#14896f}
@media (max-width:380px){.icon-picker{grid-template-columns:repeat(4,minmax(0,1fr))}}


/* v3 - grupos e ordem de compra */
#productGrid,#selectedGrid{display:block}
.product-group{margin:0 0 24px}
.group-heading{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  margin:0 2px 10px;padding-top:2px
}
.group-heading h3{
  margin:0;color:#f4fffc;font-size:1.05rem;letter-spacing:.01em
}
.group-heading span{
  font-size:.72rem;color:#99ccc3;background:rgba(255,255,255,.08);
  padding:5px 8px;border-radius:999px
}
.settings-help{margin:4px 0 12px;color:#63817c;font-size:.78rem;line-height:1.35}
.settings-title-row{display:flex;justify-content:space-between;gap:10px}
.groups-list{display:flex;flex-direction:column;gap:7px;margin-bottom:12px}
.group-row{
  display:grid;grid-template-columns:28px 1fr 28px 38px 38px;gap:5px;align-items:center;
  background:#eaf5f2;padding:8px;border-radius:13px
}
.group-row.dragging{opacity:.45}
.drag-handle{font-size:1.15rem;color:#6c928b;text-align:center;cursor:grab}
.group-row-name{font-size:.9rem}
.group-count{
  min-width:24px;height:24px;border-radius:999px;background:#d5eae5;color:#2f675d;
  display:grid;place-items:center;font-size:.7rem;font-weight:900
}
.inline-form{display:grid;grid-template-columns:1fr auto;gap:8px;margin-top:8px}
.inline-form[hidden]{display:none}
.inline-form input{margin:0!important}
.settings-group-title{
  margin:13px 0 3px;padding:8px 4px 3px;color:#1b5e53;
  font-size:.78rem;font-weight:900;text-transform:uppercase;letter-spacing:.07em;
  border-bottom:1px solid #d8e9e5
}
.settings-group-title:first-child{margin-top:0}
.product-order-row{
  grid-template-columns:44px minmax(80px,1fr) auto auto auto;
}
.order-actions{display:flex;gap:3px}
.order-actions .icon-btn{padding:7px 8px}
@media (max-width:460px){
  .product-order-row{
    grid-template-columns:40px minmax(70px,1fr) auto;
    grid-template-areas:
      "icon name order"
      "icon edit delete";
  }
  .product-order-row .settings-mini-icon{grid-area:icon}
  .product-order-row .settings-name{grid-area:name}
  .product-order-row .order-actions{grid-area:order}
  .product-order-row .edit{grid-area:edit}
  .product-order-row .delete{grid-area:delete}
}


/* v4 - desenhos personalizados em SVG */
.settings-card textarea{
  width:100%;margin-top:6px;border:1px solid #c9dfda;border-radius:13px;
  padding:12px;background:white;color:#17393a;outline:none;resize:vertical;
  font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:.78rem
}
.custom-icon-preview{
  min-height:126px;border:1px dashed #a9cbc4;border-radius:16px;margin:4px 0 14px;
  display:grid;place-items:center;color:#75928d;background:#edf7f4
}
.custom-icon-preview svg{
  width:100px;height:100px;stroke:#1f7769;fill:none;stroke-width:2.7;
  stroke-linecap:round;stroke-linejoin:round
}
.custom-icon-preview.valid{border-style:solid;background:#e6f5f0}


/* v5 - importação de produto via JSON gerado pela IA */
.json-example{
  margin:10px 0 14px;padding:10px 12px;border-radius:13px;
  background:#eaf5f2;color:#315d57;font-size:.76rem;line-height:1.4
}
.json-example code{
  display:block;margin-top:6px;white-space:normal;word-break:break-word;
  font-family:ui-monospace,SFMono-Regular,Consolas,monospace
}
.ai-product-preview{
  min-height:92px;margin:4px 0 14px;padding:12px;border:1px dashed #a9cbc4;
  border-radius:16px;background:#edf7f4;display:flex;align-items:center;gap:14px;
  color:#75928d
}
.ai-product-preview.valid{border-style:solid;background:#e6f5f0;color:#244d47}
.ai-preview-icon{
  width:66px;height:66px;border-radius:14px;background:#dceee9;
  display:grid;place-items:center;color:#51867c;font-size:.72rem;font-weight:900
}
.ai-preview-icon svg{
  width:56px;height:56px;stroke:#1f7769;fill:none;stroke-width:2.7;
  stroke-linecap:round;stroke-linejoin:round
}
.ai-product-preview strong{display:block;font-size:1rem}
.ai-product-preview span{display:block;margin-top:3px;font-size:.8rem}


/* v6 - comprado, finalizar compra e backup */
.selected-actions{
  display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end
}
.primary-btn.compact{padding:9px 11px;font-size:.78rem}
.bought-btn{
  width:calc(100% - 24px);margin:0 12px 12px;border:0;border-radius:13px;
  padding:10px;background:rgba(255,255,255,.18);color:white;font-weight:900
}
.product-card.purchased{
  opacity:.58;filter:saturate(.55)
}
.product-card.purchased .product-name{
  text-decoration:line-through
}
.product-card.purchased .bought-btn{
  background:#e7f4ef;color:#1d6f60
}
.backup-actions{
  display:flex;gap:8px;flex-wrap:wrap
}
.file-label{
  display:inline-flex;align-items:center;justify-content:center;cursor:pointer
}
.backup-note{margin-top:10px}


/* v7 - importação de NFC-e */
.nfce-status{
  margin-top:12px;padding:10px 12px;border-radius:12px;font-size:.82rem;line-height:1.4
}
.nfce-status.info{background:#e8f2ff;color:#27577d}
.nfce-status.success{background:#e4f6ed;color:#1f6c55}
.nfce-status.error{background:#ffe9e9;color:#8e3035}
.nfce-preview{margin-top:14px}
.nfce-summary{
  display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:12px
}
.nfce-summary div{
  background:#eaf5f2;border-radius:12px;padding:9px 10px;min-width:0
}
.nfce-summary span{display:block;font-size:.68rem;color:#698780;text-transform:uppercase;font-weight:800}
.nfce-summary strong{display:block;margin-top:3px;font-size:.86rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.nfce-options{
  display:flex;flex-direction:column;gap:7px;margin:10px 0 12px;
  padding:10px;border:1px solid #d6e9e4;border-radius:13px
}
.nfce-options label{margin:0;font-size:.78rem;font-weight:700;display:flex;align-items:flex-start;gap:7px}
.nfce-options input{width:auto;margin:2px 0 0}
.nfce-items{
  max-height:420px;overflow:auto;border:1px solid #d5e6e2;border-radius:14px;margin-bottom:12px
}
.nfce-item-row{
  display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:8px;align-items:center;
  padding:10px;border-bottom:1px solid #e1ece9;background:white
}
.nfce-item-row:last-child{border-bottom:0}
.nfce-item-row.matched{background:#f0faf6}
.nfce-check{margin:0!important}
.nfce-check input{width:auto!important;margin:0!important}
.nfce-item-main{min-width:0}
.nfce-item-main strong{display:block;font-size:.82rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.nfce-item-main span{display:block;margin-top:3px;font-size:.69rem;color:#728a86}
.nfce-item-price{font-size:.76rem;font-weight:900;white-space:nowrap}
.full-btn{width:100%}
@media (max-width:420px){
  .nfce-item-row{grid-template-columns:24px minmax(0,1fr)}
  .nfce-item-price{grid-column:2;justify-self:start}
}


/* v12 - preço conhecido e estimativa da compra */
.product-price-line{
  margin-top:4px;font-size:.72rem;color:rgba(255,255,255,.9);font-weight:700
}
.product-subtotal{
  margin:-5px 12px 12px;text-align:center;font-size:.75rem;font-weight:900;
  color:white
}
.selected-estimate{
  margin:0 0 16px;padding:14px 16px;border-radius:18px;
  background:#f5fbf9;color:#17393a;box-shadow:var(--shadow)
}
.selected-estimate span{
  display:block;font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;
  color:#64827d;font-weight:800
}
.selected-estimate strong{
  display:block;margin-top:3px;font-size:1.6rem;color:#0f6b5e
}
.selected-estimate small{
  display:block;margin-top:3px;color:#728a86;font-size:.75rem
}


/* v13 - histórico de compras e aviso de atualização */
.purchase-history-list{display:flex;flex-direction:column;gap:8px;margin-bottom:6px}
.purchase-history-row{
  background:#eaf5f2;border-radius:14px;padding:10px 12px;
  display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px
}
.purchase-history-main{min-width:0}
.purchase-history-main strong{display:block;font-size:.88rem}
.purchase-history-main span{display:block;margin-top:2px;font-size:.72rem;color:#63817c}
.purchase-history-total{font-size:.86rem;font-weight:900;color:#0f6b5e}

.update-toast{
  position:fixed;left:50%;bottom:calc(78px + env(safe-area-inset-bottom));transform:translateX(-50%);
  z-index:30;max-width:min(92vw,420px);width:100%;
  background:#0f4b4d;color:white;border-radius:16px;padding:12px 14px;
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  box-shadow:var(--shadow);border:1px solid rgba(255,255,255,.14)
}
.update-toast span{font-size:.85rem;font-weight:700}
.update-toast button{
  border:0;border-radius:11px;padding:8px 12px;font-weight:800;
  background:#39c29a;color:#06322c
}

.login-gate{
  position:fixed;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;
  padding:16px;background:rgba(6,40,42,.96);backdrop-filter:blur(18px)
}
.login-gate[hidden]{display:none}
.login-card{
  width:min(100%,360px);background:var(--panel);color:var(--ink);border-radius:20px;
  padding:24px;box-shadow:var(--shadow);display:flex;flex-direction:column;gap:14px
}
.login-card h2{margin:0;font-size:1.4rem}
.login-card p{margin:0;color:#4c6b66;font-size:.9rem}
.login-card label{display:flex;flex-direction:column;gap:6px;font-size:.85rem;font-weight:700;color:#2f5a54}
.login-card input{
  border:1px solid #cfe9e2;border-radius:12px;padding:11px 12px;font-size:1rem;background:white;color:var(--ink)
}
.login-error{color:var(--red-2);font-size:.85rem;font-weight:700}

.sync-status{
  position:fixed;left:50%;top:calc(10px + env(safe-area-inset-top));transform:translateX(-50%);
  z-index:40;max-width:min(92vw,420px);text-align:center;
  background:#5a2b2b;color:white;border-radius:14px;padding:9px 14px;font-size:.82rem;font-weight:700;
  box-shadow:var(--shadow);border:1px solid rgba(255,255,255,.14)
}

/* Ação discreta para transferir um produto entre grupos. */
.change-group-btn{display:block;margin:0 auto 9px;padding:3px 10px;border:1px solid rgba(255,255,255,.45);border-radius:99px;background:rgba(0,0,0,.10);color:inherit;font:inherit;font-size:.72rem;cursor:pointer}
.change-group-btn:focus-visible{outline:2px solid currentColor;outline-offset:2px}
.change-group-dialog{width:min(92vw,400px);max-height:85vh;border:0;border-radius:18px;padding:22px;color:#20302c;background:#fff;box-shadow:0 14px 60px #0005}
.change-group-dialog::backdrop{background:rgba(0,0,0,.55)}
.change-group-dialog form{display:grid;gap:14px}
.change-group-dialog h3,.change-group-dialog p{margin:0}
.change-group-dialog label{display:grid;gap:6px;font-weight:600}
.change-group-dialog select{width:100%;padding:12px;font:inherit;border:1px solid #879b92;border-radius:10px;background:white;color:#20302c}
.change-group-actions{display:flex;justify-content:flex-end;gap:10px}
.change-group-actions button{padding:10px 16px;border-radius:10px;border:1px solid #879b92;background:#fff;font:inherit;cursor:pointer}
.change-group-actions .change-group-save{background:#167b60;color:#fff;border-color:#167b60}
