/* ================= B92 — Espresso Ledger ================= */
:root {
  --paper: #f3ecdf;
  --paper-2: #ece2d0;
  --card: #fbf7ee;
  --ink: #2b1a12;
  --ink-soft: #6f5a4c;
  --line: #ddcfba;
  --caramel: #b05e21;
  --caramel-dark: #8f4a17;
  --cream: #f9f3e6;
  --green: #4a6b4f;
  --red: #a13d2d;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(43, 26, 18, .08);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Schibsted Grotesk', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, #fff6e3 0%, transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  color: var(--ink);
  min-height: 100%;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============ LOGIN ============ */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 40px 28px 32px;
  box-shadow: 0 12px 40px rgba(43,26,18,.12);
  text-align: center;
  animation: rise .5s cubic-bezier(.2,.9,.3,1.2) both;
}
.login-logo {
  font-family: var(--font-display);
  font-weight: 900; font-size: 64px; line-height: 1;
  letter-spacing: -.03em;
}
.login-logo span { color: var(--caramel); font-style: italic; }
.login-sub { color: var(--ink-soft); font-size: 14px; margin: 8px 0 28px; }
.login-card input {
  width: 100%; padding: 15px 16px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: #fff; font: inherit; font-size: 17px;
  text-align: center; letter-spacing: .1em;
  margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--caramel); }
.login-error { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 10px; font-weight: 600; }
.login-foot { color: var(--ink-soft); font-size: 12px; opacity: .6; }

@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } }

/* ============ BUTTONS ============ */
.btn {
  font: inherit; font-weight: 700; border: none; cursor: pointer;
  border-radius: 14px; padding: 13px 18px; font-size: 16px;
  transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--ink); color: var(--cream); }
.btn-primary:active { filter: brightness(1.25); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }
.btn-block { display: block; width: 100%; }
.btn-big { padding: 17px; font-size: 17px; border-radius: 16px; }
.btn-add { margin-bottom: 14px; }

/* ============ LAYOUT ============ */
.view {
  padding: 16px 16px 170px;
  max-width: 560px; margin: 0 auto;
  animation: fade .25s ease both;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 18px;
}
.brand {
  font-family: var(--font-display); font-weight: 900;
  font-size: 34px; letter-spacing: -.03em; line-height: 1;
}
.brand span { color: var(--caramel); font-style: italic; }
.page-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: 28px; letter-spacing: -.02em;
}

.topbar-stats { display: flex; gap: 8px; }
.stat-chip {
  background: var(--ink); color: var(--cream);
  border-radius: 14px; padding: 8px 14px;
  display: flex; flex-direction: column; align-items: flex-end;
}
.stat-chip-alt { background: var(--caramel); }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; opacity: .7; font-weight: 700; }
.stat-value { font-family: var(--font-display); font-weight: 700; font-size: 17px; }

/* ============ CATEGORIES ============ */
.cats {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 14px;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: 0 0 auto; padding: 9px 18px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--card);
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; transition: all .15s;
}
.cat.active { background: var(--ink); border-color: var(--ink); color: var(--cream); }

/* ============ PRODUCT GRID ============ */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 420px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.pcard {
  position: relative;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 16px 14px 14px;
  cursor: pointer; text-align: left;
  font: inherit; color: inherit;
  box-shadow: var(--shadow);
  transition: transform .1s, border-color .15s;
  min-height: 108px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
}
.pcard:active { transform: scale(.95); border-color: var(--caramel); }
.pcard.bump { animation: bump .3s cubic-bezier(.2,1.5,.4,1); }
@keyframes bump { 30% { transform: scale(.93); } 70% { transform: scale(1.03); } }
.pcard-emoji { font-size: 26px; line-height: 1; }
.pcard-name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.pcard-price {
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  color: var(--caramel-dark);
}
.pcard-badge {
  position: absolute; top: -7px; right: -7px;
  background: var(--caramel); color: #fff;
  min-width: 26px; height: 26px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
  box-shadow: 0 2px 6px rgba(176,94,33,.4);
  animation: pop .25s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(0); } }

.empty {
  text-align: center; color: var(--ink-soft); padding: 60px 20px;
  font-size: 15px; line-height: 1.7;
}

/* ============ ORDER BAR ============ */
.orderbar {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--caramel); color: #fff;
  border-radius: 18px; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 8px 24px rgba(176,94,33,.45);
  cursor: pointer; z-index: 40;
  max-width: 536px; margin: 0 auto;
  animation: rise .3s cubic-bezier(.2,.9,.3,1.3) both;
}
.orderbar-info { display: flex; align-items: baseline; gap: 12px; }
#orderbar-count { font-size: 13px; font-weight: 600; opacity: .85; }
.orderbar-total { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.orderbar-cta { font-size: 14px; font-weight: 700; }

/* ============ TAB BAR ============ */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex;
  background: rgba(251,247,238,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  font: inherit; font-size: 11.5px; font-weight: 700;
  color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0; border-radius: 12px;
  transition: color .15s;
}
.tab svg { width: 23px; height: 23px; fill: currentColor; }
.tab.active { color: var(--caramel-dark); }

/* ============ DATE NAV / HISTORY ============ */
.datenav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.datenav-btn {
  width: 46px; height: 46px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card);
  font-size: 24px; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.datenav-btn:disabled { opacity: .3; }
.datenav-label {
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  flex: 1; text-align: center;
}

.hist-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.hist-sum-item {
  background: var(--ink); color: var(--cream);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.hist-sum-item:last-child { background: var(--caramel); }
.hist-sum-num { font-family: var(--font-display); font-weight: 700; font-size: 24px; }
.hist-sum-cap { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; opacity: .7; margin-top: 3px; font-weight: 700; }

.hist-top {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
}
.hist-top-chip {
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft);
}
.hist-top-chip b { color: var(--ink); }

.hist-list { display: flex; flex-direction: column; gap: 10px; }
.sale-card {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
}
.sale-head {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
}
.sale-time { font-weight: 700; font-size: 15px; }
.sale-cust { color: var(--caramel-dark); font-size: 13px; font-weight: 600; }
.sale-total { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.sale-items { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.sale-item {
  display: flex; justify-content: space-between; font-size: 14px;
  color: var(--ink-soft); padding: 3px 0;
}
.sale-item b { color: var(--ink); font-weight: 600; }
.sale-del {
  margin-top: 10px; width: 100%;
  background: none; border: 1.5px solid #e5c4bb; color: var(--red);
  border-radius: 12px; padding: 10px; font: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
}

/* ============ SETTINGS ============ */
.seg {
  display: flex; background: var(--paper-2); border-radius: 14px;
  padding: 4px; margin-bottom: 16px; border: 1px solid var(--line);
}
.seg-btn {
  flex: 1; border: none; background: none; font: inherit;
  font-weight: 700; font-size: 15px; color: var(--ink-soft);
  padding: 11px; border-radius: 11px; cursor: pointer;
  transition: all .15s;
}
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.set-list { display: flex; flex-direction: column; gap: 8px; }
.set-row {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 16px; padding: 13px 14px;
  display: flex; align-items: center; gap: 12px;
}
.set-row-emoji { font-size: 22px; width: 30px; text-align: center; }
.set-row-main { flex: 1; min-width: 0; }
.set-row-name { font-weight: 700; font-size: 15px; }
.set-row-sub { color: var(--ink-soft); font-size: 12.5px; margin-top: 1px; }
.set-row-price { font-family: var(--font-display); font-weight: 700; font-size: 16px; color: var(--caramel-dark); white-space: nowrap; }
.set-row-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1.5px solid var(--line);
  background: none; cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn.danger { border-color: #e5c4bb; }

/* ============ SHEETS ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(43,26,18,.45);
  z-index: 90; animation: fadein .2s ease both;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
@keyframes fadein { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  background: var(--card);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  max-height: 86vh; max-height: 86dvh; overflow-y: auto;
  box-shadow: 0 -12px 40px rgba(43,26,18,.25);
  animation: slideup .3s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-handle {
  width: 42px; height: 5px; border-radius: 99px;
  background: var(--line); margin: 6px auto 14px;
}
.sheet-title {
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  margin-bottom: 16px;
}

/* order sheet */
.order-items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.order-item { display: flex; align-items: center; gap: 10px; }
.order-item-name { flex: 1; font-weight: 600; font-size: 15px; min-width: 0; }
.order-item-name small { display: block; color: var(--ink-soft); font-weight: 500; }
.qty { display: flex; align-items: center; gap: 2px; background: var(--paper-2); border-radius: 12px; padding: 3px; }
.qty button {
  width: 34px; height: 34px; border: none; background: none;
  font-size: 20px; font-weight: 700; color: var(--caramel-dark); cursor: pointer;
  border-radius: 9px;
}
.qty button:active { background: var(--line); }
.qty span { min-width: 26px; text-align: center; font-weight: 800; font-size: 16px; }
.order-item-sum { font-family: var(--font-display); font-weight: 700; min-width: 66px; text-align: right; font-size: 15px; }

.order-total-row {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 2px solid var(--ink); margin: 16px 0; padding-top: 14px;
  font-weight: 700; font-size: 17px;
}
#order-total { font-family: var(--font-display); font-weight: 900; font-size: 26px; }
#btn-register-sale { margin-bottom: 8px; background: var(--green); }

/* forms */
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-soft); margin-bottom: 6px;
}
.field label small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.field input, .field select {
  width: 100%; padding: 13px 14px; font: inherit; font-size: 16px;
  border: 1.5px solid var(--line); border-radius: 13px; background: #fff;
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--caramel); }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(150px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--cream);
  padding: 13px 22px; border-radius: 999px;
  font-weight: 700; font-size: 15px; z-index: 200;
  box-shadow: 0 8px 24px rgba(43,26,18,.35);
  animation: toastin .3s cubic-bezier(.2,1.4,.4,1) both;
  white-space: nowrap;
}
.toast.success { background: var(--green); color: #fff; }
.toast.error { background: var(--red); color: #fff; }
@keyframes toastin { from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(.9); } }

/* ============ PAID / UNPAID ============ */
.paytoggle { display: flex; gap: 8px; }
.pay-btn {
  flex: 1; padding: 13px; border-radius: 13px;
  border: 1.5px solid var(--line); background: #fff;
  font: inherit; font-weight: 700; font-size: 15px; color: var(--ink-soft);
  cursor: pointer; transition: all .15s;
}
.pay-btn.active[data-paid="1"] { background: var(--green); border-color: var(--green); color: #fff; }
.pay-btn.active[data-paid="0"] { background: var(--red); border-color: var(--red); color: #fff; }
.field-required select { border-color: var(--red); }

.unpaid-chip {
  display: inline-block; background: var(--red); color: #fff;
  border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 800;
  margin-left: 7px; vertical-align: 2px; letter-spacing: .02em;
}
.sale-card.unpaid { border-color: #e5c4bb; background: #fdf6f2; }
.sale-card.unpaid .sale-total { color: var(--red); }

.tab { position: relative; }
.tab-dot {
  position: absolute; top: 4px; right: calc(50% - 18px);
  width: 9px; height: 9px; border-radius: 99px;
  background: var(--red); border: 2px solid var(--card);
}

/* ============ BORXH PAGE ============ */
.debt-banner {
  background: var(--red); color: #fff;
  border-radius: var(--radius); padding: 16px; text-align: center;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(161,61,45,.3);
}
.debt-banner-num { font-family: var(--font-display); font-weight: 900; font-size: 27px; }
.debt-banner-cap { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; opacity: .8; font-weight: 700; margin-top: 3px; }

.badge-debt {
  background: var(--red); color: #fff;
  border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 800; white-space: nowrap;
  font-family: var(--font-display);
}

.debt-card {
  background: var(--card); border: 1.5px solid #e5c4bb;
  border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow);
}
.debt-card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; cursor: pointer;
  transition: background .15s;
}
.debt-card-head:active { background: #fdf6f2; }
.debt-card.open .debt-card-head { background: #fdf6f2; border-bottom: 1px dashed #e5c4bb; }
.debt-chevron { color: var(--ink-soft); font-size: 13px; width: 14px; }

.debt-card-body { padding: 6px 14px 14px; }
.debt-sale {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.debt-sale:last-of-type { border-bottom: none; }
.debt-sale-info { flex: 1; min-width: 0; }
.debt-sale-date { font-weight: 700; font-size: 13.5px; }
.debt-sale-items { color: var(--ink-soft); font-size: 12.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debt-sale-total { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: var(--red); white-space: nowrap; }
.debt-sale-pay {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 12px; border: none;
  background: var(--green); color: #fff;
  font-size: 17px; font-weight: 800; cursor: pointer;
  transition: transform .1s;
}
.debt-sale-pay:active { transform: scale(.9); }
.btn-pay-all { background: var(--green); color: #fff; margin-top: 12px; }

/* ============ ADDON PROMPT ============ */
#sheet-addon .sheet-title { text-align: center; margin-bottom: 20px; }
#addon-yes { background: var(--caramel); color: #fff; margin-bottom: 10px; }
#addon-no { margin-bottom: 4px; }
