:root {
  --porcelain: #EEF1F2;
  --steam: #FFFFFF;
  --espresso: #2B1B14;
  --roast: #5A4034;
  --bean: #8C7468;
  --crema: #C98A3D;
  --crema-soft: #F3E3CC;
  --sage: #3E7D6B;
  --sage-soft: #DCEBE5;
  --cherry: #B23A3A;
  --line: #DCE1E3;
  --m-bg: #24150F; --m-ink: #F6EDE3; --m-dim: #B79E8C;

  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;

  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--porcelain);
  color: var(--espresso);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--crema); outline-offset: 2px; }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; font-weight: 700; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 0; border-radius: 999px; padding: .8em 1.4em; font-weight: 600;
  background: var(--espresso); color: var(--steam);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  transition: transform .12s ease, background .2s;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.crema { background: var(--crema); color: var(--espresso); }
.btn.ghost { background: transparent; color: var(--espresso); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { background: transparent; color: var(--cherry); box-shadow: inset 0 0 0 1.5px #E8C9C9; }
.btn.small { padding: .45em .95em; font-size: .9rem; }
.btn.block { width: 100%; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-size: .88rem; font-weight: 600; color: var(--roast); }
.input {
  width: 100%; padding: .85em 1em; border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--steam);
}
.input:focus { border-color: var(--crema); outline: none; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 40px); opacity: 0; pointer-events: none;
  background: var(--espresso); color: var(--steam); padding: .75em 1.2em; border-radius: 999px;
  font-weight: 500; max-width: calc(100% - 32px); text-align: center; z-index: 100;
  transition: all .25s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--cherry); }

/* ---------- login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 110% -10%, var(--crema-soft), transparent 60%),
    var(--porcelain);
}
.login-card { width: 100%; max-width: 380px; }
.brand { font-family: var(--display); font-weight: 800; font-stretch: 80%; font-size: 3.2rem; letter-spacing: -.02em; line-height: .95; }
.brand small { display: block; font: 500 1rem/1.4 var(--body); letter-spacing: 0; color: var(--bean); margin-top: 10px; }
.login form { margin-top: 32px; background: var(--steam); padding: 24px; border-radius: var(--r-lg); border: 1px solid var(--line); }
.login .hint { margin-top: 14px; font-size: .9rem; color: var(--bean); }
.login .err { color: var(--cherry); font-size: .92rem; min-height: 1.4em; margin: 0 0 8px; }

/* ---------- app shell (user + admin) ---------- */
.shell { max-width: 1080px; margin: 0 auto; padding: 18px 18px 140px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar .logo { font-family: var(--display); font-weight: 800; font-stretch: 80%; font-size: 1.5rem; }
.topbar .who { font-size: .92rem; color: var(--bean); }

.wallet {
  background: var(--espresso); color: var(--steam); border-radius: var(--r-lg);
  padding: 22px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  position: relative; overflow: hidden;
}
.wallet::after {
  content: ''; position: absolute; right: -60px; top: -80px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201,138,61,.55), transparent 70%);
}
.wallet .greet { font-family: var(--display); font-size: 1.7rem; font-weight: 700; font-stretch: 85%; }
.wallet .bal { text-align: right; position: relative; z-index: 1; }
.wallet .bal b { display: block; font-family: var(--display); font-size: 2rem; font-weight: 700; }
.wallet .bal span { font-size: .85rem; opacity: .7; }

.status {
  margin-top: 14px; border-radius: var(--r-lg); padding: 16px 18px; display: flex; gap: 14px; align-items: center;
  background: var(--crema-soft); border: 1px solid #E9CFA9;
}
.status.live { background: var(--sage-soft); border-color: #BCD8CD; }
.status .pulse { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--steam); position: relative; font-size: 1.3rem; }
.status .pulse::before {
  content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--crema);
  animation: ring 1.8s ease-out infinite;
}
.status.live .pulse::before { border-color: var(--sage); }
.status p { margin: 2px 0 0; font-size: .93rem; color: var(--roast); }
.status strong { font-weight: 700; }

.cats { display: flex; gap: 8px; margin: 26px 0 14px; overflow-x: auto; padding-bottom: 4px; }
.chip { border: 0; padding: .55em 1.1em; border-radius: 999px; background: var(--steam); box-shadow: inset 0 0 0 1.5px var(--line); font-weight: 600; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--espresso); color: var(--steam); box-shadow: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
.prod {
  background: var(--steam); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 10px;
  border: 1.5px solid transparent; transition: border-color .2s;
}
.prod.in { border-color: var(--crema); }
.prod .emo { font-size: 2.1rem; width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; background: var(--porcelain); }
.prod .nm { font-weight: 600; line-height: 1.25; }
.prod .pr { color: var(--bean); font-size: .92rem; }
.stepper { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--porcelain); font-size: 1.2rem; font-weight: 600; line-height: 1; }
.stepper button.add { background: var(--espresso); color: var(--steam); }
.stepper b { font-family: var(--display); font-size: 1.15rem; min-width: 1.5em; text-align: center; }

.section-title { font-size: 1.25rem; margin: 34px 0 12px; }
.history { display: grid; gap: 8px; }
.hrow { background: var(--steam); border-radius: var(--r-md); padding: 12px 16px; display: flex; justify-content: space-between; gap: 12px; font-size: .93rem; }
.hrow .meta { color: var(--bean); font-size: .85rem; }
.hrow .amt { font-weight: 700; white-space: nowrap; }
.empty { color: var(--bean); padding: 18px; text-align: center; background: var(--steam); border-radius: var(--r-md); }

.paybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255,255,255,.9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  transform: translateY(110%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.paybar.show { transform: none; }
.paybar .in { max-width: 1080px; margin: 0 auto; display: flex; gap: 14px; align-items: center; justify-content: space-between; }
.paybar .sum { font-size: .9rem; color: var(--bean); }
.paybar .sum b { display: block; color: var(--espresso); font-family: var(--display); font-size: 1.35rem; }

/* ---------- payment sheet ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(43,27,20,.45); display: grid; align-items: end; justify-items: center; z-index: 50; animation: fade .2s; }
.sheet {
  width: 100%; max-width: 460px; background: var(--steam); border-radius: 26px 26px 0 0;
  padding: 26px 22px calc(26px + env(safe-area-inset-bottom, 0px)); animation: up .3s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 640px) { .sheet-back { align-items: center; } .sheet { border-radius: 26px; } }
.sheet h2 { font-size: 1.5rem; margin-bottom: 4px; }
.sheet .lines { margin: 18px 0; border-top: 1px dashed var(--line); }
.sheet .line { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.sheet .tot { display: flex; justify-content: space-between; font-family: var(--display); font-weight: 700; font-size: 1.3rem; margin-bottom: 20px; }
.paystate { text-align: center; padding: 18px 0 6px; }
.paystate .ico { width: 84px; height: 84px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; font-size: 2.2rem; }
.paystate .spin { border: 4px solid var(--porcelain); border-top-color: var(--crema); animation: spin .8s linear infinite; }
.paystate .ok { background: var(--sage); color: var(--steam); animation: pop .4s cubic-bezier(.2,1.6,.4,1); }
.paystate p { color: var(--roast); margin: 8px 0 20px; }
.nfc-hint { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--porcelain); border-radius: var(--r-md); padding: 14px; margin-bottom: 18px; font-size: .93rem; }
.nfc-hint .phone { font-size: 1.8rem; animation: tap 1.6s ease-in-out infinite; }

/* ---------- tap page ---------- */
.tap-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.tap-card { width: 100%; max-width: 420px; text-align: center; }
.tap-card .big { width: 110px; height: 110px; border-radius: 50%; margin: 0 auto 22px; display: grid; place-items: center; font-size: 2.8rem; background: var(--sage); color: var(--steam); }
.tap-card .big.wait { background: var(--crema-soft); }
.tap-card .big.bad { background: #F2DADA; }
.tap-card h1 { font-size: 2rem; font-stretch: 85%; }
.tap-card p { color: var(--roast); }
.tap-card .lines { text-align: left; background: var(--steam); border-radius: var(--r-md); padding: 6px 16px; margin: 18px 0; }
.tap-card .line { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--porcelain); }
.tap-card .line:last-child { border-bottom: 0; }

/* ---------- machine screen ---------- */
.machine {
  min-height: 100vh; min-height: 100dvh; height: 100%;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(201,138,61,.28), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(62,125,107,.18), transparent 60%),
    var(--m-bg);
  color: var(--m-ink); display: flex; flex-direction: column; padding: 22px clamp(18px, 4vw, 48px);
  overflow: hidden;
}
.mhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--m-dim); font-size: .95rem; }
.mhead b { color: var(--m-ink); font-family: var(--display); font-size: 1.15rem; font-weight: 700; }
.mhead .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #6FCF97; margin-right: 8px; box-shadow: 0 0 10px #6FCF97; }
.mhead .clock { font-variant-numeric: tabular-nums; }

.idle { flex: 1; display: grid; place-items: center; text-align: center; }
.rings { position: relative; width: 210px; height: 210px; margin: 0 auto 34px; display: grid; place-items: center; }
.rings span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(201,138,61,.7); animation: ring 2.6s ease-out infinite; }
.rings span:nth-child(2) { animation-delay: .85s; }
.rings span:nth-child(3) { animation-delay: 1.7s; }
.rings .core { width: 110px; height: 110px; border-radius: 50%; background: var(--crema); color: var(--espresso); display: grid; place-items: center; position: relative; z-index: 1; }
.rings .core svg { width: 52px; height: 52px; }
.idle h1 { font-size: clamp(2.2rem, 6vw, 4.2rem); font-stretch: 78%; font-weight: 800; letter-spacing: -.02em; }
.idle p { color: var(--m-dim); font-size: 1.1rem; margin: 10px 0 0; }

.session { flex: 1; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: clamp(20px, 4vw, 56px); align-items: start; padding-top: clamp(12px, 3vh, 36px); min-height: 0; }
@media (max-width: 820px) { .session { grid-template-columns: 1fr; } }
.hello { font-family: var(--display); font-weight: 800; font-stretch: 75%; letter-spacing: -.03em; line-height: .9; font-size: clamp(3.2rem, 9vw, 7.5rem); }
.hello .nm { display: block; color: var(--crema); }
.hello.reveal { animation: rise .7s cubic-bezier(.2,.8,.2,1) both; }
.lead { color: var(--m-dim); font-size: clamp(1.05rem, 1.8vw, 1.35rem); margin: 18px 0 0; max-width: 28ch; }
.mbal { margin-top: 26px; display: inline-flex; gap: 10px; align-items: baseline; padding: 10px 16px; border-radius: 999px; background: rgba(255,255,255,.06); color: var(--m-dim); }
.mbal b { color: var(--m-ink); font-family: var(--display); font-size: 1.2rem; }

/* the paper ticket: the one memorable element */
.ticket {
  background: #FBF7F1; color: var(--espresso); border-radius: 18px 18px 0 0; padding: 22px 22px 12px;
  position: relative; box-shadow: 0 30px 60px -25px rgba(0,0,0,.6);
  -webkit-mask: radial-gradient(10px at 50% 100%, #0000 98%, #000) 0 0 / 22px 100% repeat-x;
          mask: radial-gradient(10px at 50% 100%, #0000 98%, #000) 0 0 / 22px 100% repeat-x;
  padding-bottom: 30px;
}
.ticket.reveal { animation: print .9s cubic-bezier(.2,.8,.2,1) .15s both; transform-origin: top; }
.ticket h3 { font-size: 1.05rem; display: flex; justify-content: space-between; color: var(--roast); font-weight: 600; padding-bottom: 12px; border-bottom: 1.5px dashed #E2D6C8; }
.titem { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1.5px dashed #E9DFD3; }
.titem .e { font-size: 1.6rem; }
.titem .n { font-weight: 600; line-height: 1.2; }
.titem .n small { display: block; color: var(--bean); font-weight: 500; }
.titem .p { font-family: var(--display); font-weight: 700; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #EFE6DA; font-weight: 700; font-size: 1.1rem; line-height: 1; }
.qty b { min-width: 1.4em; text-align: center; font-family: var(--display); }
.ttotal { display: flex; justify-content: space-between; font-family: var(--display); font-size: 1.5rem; font-weight: 800; padding-top: 14px; }
.tempty { color: var(--bean); padding: 20px 0; text-align: center; }

.mactions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.mactions .btn { padding: 1em 1.5em; }
.mactions .grow { flex: 1; }
.machine .btn.ghost { color: var(--m-ink); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.2); }

.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; animation: fade .2s; display: flex; justify-content: flex-end; }
.drawer { width: min(520px, 100%); height: 100%; background: #FBF7F1; color: var(--espresso); padding: 24px; overflow-y: auto; animation: slide .3s cubic-bezier(.2,.8,.2,1); padding-top: calc(24px + env(safe-area-inset-top, 0px)); }
.drawer .dh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.drawer .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.drawer .prod { background: var(--steam); }

.dispense { position: fixed; inset: 0; z-index: 60; background: rgba(36,21,15,.94); display: grid; place-items: center; text-align: center; color: var(--m-ink); animation: fade .25s; }
.cup { width: 120px; height: 140px; margin: 0 auto 28px; position: relative; border: 5px solid var(--m-ink); border-top: 0; border-radius: 0 0 36px 36px; }
.cup::after { content: ''; position: absolute; right: -34px; top: 26px; width: 30px; height: 50px; border: 5px solid var(--m-ink); border-left: 0; border-radius: 0 22px 22px 0; }
.cup i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 0 0 31px 31px; background: linear-gradient(var(--crema) 0 14%, #6B4226 14%); animation: fill 2.6s ease-in-out forwards; }
.dispense h2 { font-size: clamp(2rem, 5vw, 3.4rem); font-stretch: 80%; }
.dispense p { color: var(--m-dim); font-size: 1.15rem; }

/* ---------- machine index ---------- */
.mlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.mcard { background: var(--steam); border-radius: var(--r-lg); padding: 18px; display: grid; gap: 10px; border: 1px solid var(--line); }
.mcard h3 { font-size: 1.2rem; }
.mcard .loc { color: var(--bean); font-size: .9rem; margin-top: -6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600; padding: .25em .75em; border-radius: 999px; background: var(--porcelain); width: fit-content; }
.badge.on { background: var(--sage-soft); color: var(--sage); }
.badge.on::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--sage); }
.link { font-size: .82rem; word-break: break-all; background: var(--porcelain); border-radius: var(--r-sm); padding: 8px 10px; color: var(--roast); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 6px; margin: 4px 0 20px; overflow-x: auto; padding-bottom: 2px; }
.panel { background: var(--steam); border-radius: var(--r-lg); padding: 18px; border: 1px solid var(--line); }
.panel + .panel { margin-top: 14px; }
.panel h2 { font-size: 1.2rem; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; font-weight: 600; color: var(--bean); font-size: .85rem; padding: 8px 10px; border-bottom: 1.5px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--porcelain); vertical-align: middle; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td .input { padding: .5em .7em; min-width: 80px; }
.plus { color: var(--sage); font-weight: 700; }
.minus { color: var(--cherry); font-weight: 700; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.form-row .field { margin: 0; }
.muted { color: var(--bean); font-size: .9rem; }
.off td { opacity: .45; }

/* ---------- motion ---------- */
@keyframes ring { from { transform: scale(.85); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(.4); } to { transform: scale(1); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes slide { from { transform: translateX(60px); opacity: 0; } }
@keyframes tap { 0%, 100% { transform: translateX(0) rotate(-8deg); } 50% { transform: translateX(10px) rotate(0); } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
@keyframes print { from { clip-path: inset(0 0 100% 0); transform: translateY(-14px); } to { clip-path: inset(0 0 0 0); transform: none; } }
@keyframes fill { to { height: 92%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
