:root {
  --bg-white: #ffffff;
  --bg-subtle: #f4f6fa;
  --btn-grey: #f1f3f7;
  --btn-grey-press: #e2e6ee;
  --btn-pink: #fdecec;
  --btn-pink-press: #f9d2d2;
  --red-main: #f02828;
  --red-dark: #c81919;
  --blue-main: #2563eb;
  --green-main: #059669;
  --amber-cod: #d97706;
  --text-dark: #141821;
  --text-muted: #5e6a7d;
  --border-color: #e4e8f0;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Bengali', sans-serif;
  font-variant-numeric: tabular-nums;
}

body {
  background-color: #e8ecf2;
  color: var(--text-dark);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

/* Splash Screen */
.splash-screen {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.splash-screen.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-logo-box {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  background: #fff5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.splash-title {
  font-size: 1.3rem;
  font-weight: 800;
}

.splash-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 600;
}

/* App Shell - Evenly Distributed, Zero Wasted Blank Gaps */
.app-shell {
  background: var(--bg-white);
  width: 100%;
  max-width: 425px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 12px 10px;
  overflow: hidden;
}

/* Top Bar */
.top-bar {
  height: 36px;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--btn-pink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.brand-title {
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--text-dark);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.lang-switch-btn {
  background: var(--bg-subtle);
  border: 1.5px solid #d5dbe6;
  color: var(--text-dark);
  font-size: 0.73rem;
  font-weight: 800;
  height: 28px;
  padding: 0 9px;
  border-radius: 14px;
  cursor: pointer;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dark);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--btn-grey);
}

/* Top Daily Summary Strip (Fills top space usefully) */
.top-stats-strip {
  height: 44px;
  flex-shrink: 0;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 6px;
  cursor: pointer;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.sp-label {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--text-muted);
}

.sp-val {
  font-size: 0.84rem;
  font-weight: 900;
  color: var(--text-dark);
  margin-top: 1px;
}

.sp-cod {
  color: var(--amber-cod);
}

.sp-online {
  color: var(--blue-main);
}

.stat-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
}

/* Unit Rate Quick Reference Grid (1g, 10g, 50g, 100g, 750g) */
.unit-ref-grid {
  height: 36px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.uref-box {
  background: #fafafa;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.uref-w {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
}

.uref-p {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-dark);
}

/* Display Card (Compact, Clean, Zero Overflow) */
.display-card {
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.bill-bar-row {
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  overflow: hidden;
}

.active-grade-chip {
  background: var(--btn-pink);
  color: var(--red-main);
  font-size: 0.73rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.bill-chips-scroll {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.bill-chips-scroll::-webkit-scrollbar {
  display: none;
}

.bill-chip {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 0.7rem;
  font-weight: 800;
  height: 23px;
  padding: 0 7px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.bill-chip button {
  background: var(--blue-main);
  color: #fff;
  border: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 0.58rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Unified Input Box */
.unified-input-box {
  height: 50px;
  background: var(--bg-subtle);
  border: 1.8px solid var(--border-color);
  border-radius: 11px;
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
}

.unified-input-box.active-weight {
  background: #ffffff;
  border-color: var(--red-main);
}

.unified-input-box.active-amount {
  background: #f8faff;
  border-color: var(--blue-main);
}

.input-left-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

.meta-caption {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.meta-converted {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--red-main);
  white-space: nowrap;
}

.unified-input-box.active-amount .meta-converted {
  color: var(--blue-main);
}

.input-right-value {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.typed-number {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1;
}

.mode-badge {
  font-size: 0.68rem;
  font-weight: 800;
  color: #ffffff;
  background: var(--text-dark);
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.mode-badge.badge-gm {
  background: var(--green-main);
}

.mode-badge.badge-amt {
  background: var(--blue-main);
}

/* Final Output Summary Box */
.output-summary-box {
  height: 54px;
  border-top: 1px solid var(--border-color);
  padding-top: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.breakdown-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.breakdown-line-1 {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breakdown-line-2 {
  font-size: 0.71rem;
  font-weight: 800;
  color: var(--green-main);
  white-space: nowrap;
}

.primary-result-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
}

.primary-result-label {
  font-size: 0.64rem;
  font-weight: 800;
  color: var(--text-muted);
}

.primary-result-number {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1.05;
  white-space: nowrap;
}

.primary-result-number.amount-mode-output {
  font-size: 1.55rem;
  color: var(--blue-main);
}

/* Mode Switcher & History Toolbar */
.mode-toolbar {
  height: 34px;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.history-btn {
  height: 32px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-dark);
  padding: 0 9px;
  border-radius: 16px;
  font-size: 0.73rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.history-count {
  background: var(--btn-pink);
  color: var(--red-main);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.67rem;
  font-weight: 800;
}

.segmented-modes {
  display: flex;
  background: var(--bg-subtle);
  padding: 2px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.71rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--text-dark);
  color: #ffffff;
}

.seg-btn.seg-amount.active {
  background: var(--blue-main);
  color: #ffffff;
}

/* Grade Bar */
.grade-bar {
  height: 42px;
  flex-shrink: 0;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}

.grade-bar::-webkit-scrollbar {
  display: none;
}

.grade-chip {
  flex: 1;
  min-width: 58px;
  height: 40px;
  background: var(--btn-grey);
  border: 1.5px solid transparent;
  color: var(--text-dark);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.grade-chip .g-main {
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.1;
}

.grade-chip .g-sub {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.1;
  margin-top: 1px;
}

.grade-chip.active {
  background: var(--btn-pink);
  border-color: var(--red-main);
  color: var(--red-main);
}

.grade-chip.active .g-sub {
  color: var(--red-dark);
}

/* Quick Presets Row */
.preset-bar {
  height: 30px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.45fr;
  gap: 5px;
}

.preset-chip {
  background: #fafafa;
  border: 1px solid #dcdfe6;
  color: var(--text-dark);
  font-size: 0.72rem;
  font-weight: 800;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.preset-chip.preset-highlight {
  background: #fff5f5;
  border-color: #fecaca;
  color: var(--red-main);
}

.preset-chip:active {
  background: var(--btn-grey-press);
}

/* 4x5 Calculator Keypad Grid */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex-shrink: 0;
}

.key-btn {
  height: 49px;
  border-radius: 25px;
  border: none;
  background: var(--btn-grey);
  color: var(--text-dark);
  font-size: 1.32rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.key-btn:active {
  background: var(--btn-grey-press);
}

.key-ac {
  color: var(--red-main);
  font-size: 1.08rem;
  font-weight: 900;
}

.key-backspace {
  color: var(--red-main);
}

.key-bill {
  background: #eef2ff;
  color: var(--blue-main);
  font-size: 0.8rem;
  font-weight: 800;
}

.key-preset-side {
  background: var(--btn-pink);
  color: var(--red-main);
  font-size: 0.78rem;
  font-weight: 800;
  gap: 2px;
}

.key-preset-side small {
  font-size: 0.6rem;
  font-weight: 700;
  opacity: 0.88;
}

.key-preset-side:active {
  background: var(--btn-pink-press);
}

.key-dot {
  font-size: 1.5rem;
  font-weight: 900;
}

.key-save {
  background: var(--red-main);
  color: #ffffff;
  font-size: 1.4rem;
  font-weight: 900;
}

.key-save:active {
  background: var(--red-dark);
}

/* COD vs ONLINE Payment Sheet */
.payment-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 350px;
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

.pay-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.pay-sheet-header h4 {
  font-size: 0.9rem;
  font-weight: 800;
}

.pay-preview-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pay-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pay-choice-btn {
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.pay-choice-btn .pay-icon {
  font-size: 1.45rem;
}

.pay-choice-btn strong {
  font-size: 0.88rem;
  font-weight: 900;
}

.pay-choice-btn small {
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.85;
}

.pay-cod {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #b45309;
}

.pay-online {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
}

/* Modals */
.modal-overlay,
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-overlay {
  align-items: flex-end;
  padding: 0;
}

.modal-overlay.open,
.confirm-overlay.open {
  display: flex;
}

.modal-sheet {
  background: var(--bg-white);
  width: 100%;
  max-width: 425px;
  max-height: 86dvh;
  border-radius: 22px 22px 0 0;
  padding: 15px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 9px;
}

.modal-header h3 {
  font-size: 0.95rem;
  font-weight: 800;
}

.close-modal-btn {
  background: var(--btn-grey);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 800;
  cursor: pointer;
}

.summary-cards-4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.sum-card {
  background: var(--bg-subtle);
  padding: 8px 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sum-card span {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
}

.sum-card strong {
  font-size: 1.05rem;
  color: var(--text-dark);
}

.modal-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.73rem;
  font-weight: 800;
  color: var(--text-muted);
  margin-top: 2px;
}

.text-danger-btn {
  background: none;
  border: none;
  color: var(--red-main);
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
}

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-row-card {
  background: var(--bg-subtle);
  padding: 9px 11px;
  border-radius: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  gap: 8px;
}

.sale-id-badge {
  display: inline-block;
  background: #e2e8f0;
  color: #1e293b;
  font-size: 0.64rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
}

.pay-tag-cod {
  display: inline-block;
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fcd34d;
  font-size: 0.63rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

.pay-tag-online {
  display: inline-block;
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
  font-size: 0.63rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

.load-more-btn {
  background: var(--btn-grey);
  border: 1px solid var(--border-color);
  color: var(--text-dark);
  padding: 9px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.del-item-btn {
  background: var(--btn-pink);
  color: var(--red-main);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

/* Settings Controls */
.add-grade-box,
.settings-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr auto;
  gap: 6px;
  align-items: center;
}

.add-grade-box input,
.settings-row input {
  background: var(--bg-subtle);
  border: 1px solid #cfd6e0;
  padding: 8px 9px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 700;
  width: 100%;
  outline: none;
}

.primary-pill-btn {
  background: var(--text-dark);
  color: #fff;
  border: none;
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  font-weight: 700;
  cursor: pointer;
}

.save-settings-btn {
  background: var(--red-main);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 11px;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

/* Guide Content */
.guide-content {
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 0.8rem;
  line-height: 1.45;
}

.guide-item {
  background: var(--bg-subtle);
  padding: 10px 12px;
  border-radius: 10px;
}

.guide-item ul {
  padding-left: 16px;
  margin-top: 4px;
}

.guide-item code {
  background: var(--btn-pink);
  color: var(--red-main);
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 800;
}

/* Confirm Box */
.confirm-box {
  background: #fff;
  width: 100%;
  max-width: 305px;
  border-radius: 18px;
  padding: 18px 16px 14px;
  text-align: center;
}

.confirm-icon {
  font-size: 1.6rem;
  margin-bottom: 4px;
}

.confirm-box h4 {
  font-size: 0.96rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.confirm-box p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.conf-btn {
  border: none;
  padding: 9px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.conf-cancel {
  background: var(--btn-grey);
  color: var(--text-dark);
}

.conf-ok {
  background: var(--red-main);
  color: #fff;
}

/* 4-Second Debounced Undo Toast */
.undo-toast {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 390px;
  background: #141821;
  color: #ffffff;
  border-radius: 11px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  display: none;
  z-index: 400;
}

.undo-toast.show {
  display: block;
}

.undo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.undo-action-btn {
  background: var(--btn-pink);
  color: var(--red-main);
  border: none;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
}

.undo-progress-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
}

.undo-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--red-main);
  transition: width 4s linear;
}

/* Info Toast */
.info-toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #141821;
  color: #fff;
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 0.76rem;
  font-weight: 700;
  display: none;
  z-index: 350;
}
