/* ==========================================================================
   TSS Billing · components & layout
   Built on tokens.css. Structure is drawn with rules and spacing, not boxes
   inside boxes. Every interactive element is at least --tap-min.
   ========================================================================== */

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app--has-nav {
  padding-bottom: var(--navbar-h);
}

.app--has-actionbar {
  padding-bottom: var(--actionbar-h);
}

.app--has-nav.app--has-actionbar {
  padding-bottom: calc(var(--navbar-h) + var(--actionbar-h) - 12px);
}

/* For screens that own the whole viewport and scroll internally — the POS and
   the gate check. The page itself never scrolls; the regions inside it do. */
.app--fixed {
  block-size: 100dvh;
  overflow: hidden;
  padding-bottom: 0;
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--page-pad);
  flex: 1;
}

.page--flush {
  padding: 0;
  max-width: none;
}

.page--narrow {
  max-width: 560px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.stack--tight { gap: var(--sp-2); }
.stack--loose { gap: var(--sp-6); }

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }

/* --------------------------------------------------------------------------
   Top bar — the khata's spine
   -------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 60px;
  padding: var(--sp-2) var(--page-pad);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.topbar__mark {
  inline-size: 34px;
  block-size: 34px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--brand-strong);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.topbar__title {
  display: block;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__sub {
  display: block;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.iconbtn {
  inline-size: var(--tap-min);
  block-size: var(--tap-min);
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  color: var(--ink-muted);
  transition: background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.iconbtn:hover {
  background: var(--brand-tint);
  color: var(--ink);
}

.iconbtn[aria-pressed="true"] {
  color: var(--brand);
}

/* --------------------------------------------------------------------------
   Bottom navigation. The Scan slot is the one allowed "special" nav item.
   -------------------------------------------------------------------------- */

.navbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: stretch;
  block-size: var(--navbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface-raised);
  border-top: 1px solid var(--line);
}

.navbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--text-xs);
  position: relative;
  transition: color var(--dur-fast) var(--ease-out);
}

.navbar__item[aria-current="page"] {
  color: var(--brand);
  font-weight: 600;
}

.navbar__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  inline-size: 32px;
  block-size: 3px;
  border-radius: 0 0 var(--r-xs) var(--r-xs);
  background: var(--brand);
  animation: nav-indicator var(--dur-base) var(--ease-out);
}

@keyframes nav-indicator {
  from { transform: scaleX(0.3); opacity: 0; }
  to { transform: scaleX(1); opacity: 1; }
}

.navbar__item--scan {
  flex: 0 0 84px;
}

.navbar__scanbtn {
  inline-size: 56px;
  block-size: 56px;
  margin-top: -18px;
  border-radius: var(--r-pill);
  background: var(--brand-strong);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  box-shadow: var(--e-3);
  border: 3px solid var(--surface-raised);
  transition: transform var(--dur-instant) var(--ease-out);
}

.navbar__scanbtn:active {
  transform: scale(0.94);
}

.navbar__badge {
  position: absolute;
  top: 8px;
  inset-inline-start: 50%;
  margin-inline-start: 4px;
  min-inline-size: 20px;
  block-size: 20px;
  padding-inline: 5px;
  border-radius: var(--r-pill);
  background: var(--brand-strong);
  color: var(--brand-ink);
  font-size: var(--text-xs);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
}

.navbar__badge.is-bumped {
  animation: badge-bump var(--dur-base) var(--ease-spring);
}

@keyframes badge-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-block-size: 52px;
  padding-inline: var(--sp-6);
  border-radius: var(--r-md);
  font-size: var(--text-base);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  transition: transform var(--dur-instant) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--surface-sunken);
  color: var(--ink-faint);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--brand-strong);
  color: var(--brand-ink);
  box-shadow: var(--e-2);
}

.btn--primary:hover:not(:disabled) {
  background: color-mix(in oklab, var(--brand-strong) 92%, #000);
}

/* Focus on a red fill needs a light inner ring as well, or the cobalt ring
   disappears into the lacquer. */
.btn--primary:focus-visible,
.btn--danger:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: var(--e-2), inset 0 0 0 2px var(--brand-ink);
}

.btn--secondary {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--brand-tint);
}

.btn--ghost {
  min-block-size: 44px;
  padding-inline: var(--sp-3);
  color: var(--brand);
  background: transparent;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--brand-tint);
}

.btn--danger {
  background: var(--danger-strong);
  color: var(--danger-ink);
  box-shadow: var(--e-2);
}

.btn--block {
  inline-size: 100%;
}

/* The thumb-zone action. One per screen. Carries the money it moves. */
.btn--hero {
  min-block-size: var(--tap-primary);
  inline-size: 100%;
  border-radius: var(--r-lg);
  font-size: var(--text-xl);
  padding-inline: var(--sp-6);
  justify-content: space-between;
}

.btn--hero .btn__label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.btn--hero .btn__label small {
  font-size: var(--text-sm);
  font-weight: 500;
  opacity: 0.86;
}

.btn__spinner {
  display: none;
  inline-size: 20px;
  block-size: 20px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.btn.is-loading .btn__spinner { display: block; }
.btn.is-loading .btn__label { opacity: 0.4; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   Cards, panels, rules
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface-raised);
  border-radius: var(--r-lg);
  box-shadow: var(--e-2);
  padding: var(--sp-4);
}

.card--flat {
  box-shadow: none;
  border: 1px solid var(--line);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.card__sub {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: var(--sp-2);
}

.hairline {
  border: none;
  border-top: 1px solid var(--line);
  margin-block: var(--sp-3);
}

/* Ornamental Kasuti rule — stepped diamonds, used only at ceremonial moments:
   the invoice header, the login footer, the shift seal. Never wallpaper. */
.kasuti {
  block-size: 14px;
  inline-size: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='14' viewBox='0 0 24 14'%3E%3Cpath d='M12 1 L20 7 L12 13 L4 7 Z' fill='none' stroke='%237A2E1C' stroke-width='1.2'/%3E%3Cpath d='M12 4 L15 7 L12 10 L9 7 Z' fill='none' stroke='%237A2E1C' stroke-width='1'/%3E%3Crect x='11' y='6' width='2' height='2' fill='%23F2C94C'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: center;
  opacity: 0.9;
}

:root[data-theme="dark"] .kasuti,
:root:not([data-theme="light"]) .kasuti {
  filter: saturate(1.3) brightness(1.5);
}

/* --------------------------------------------------------------------------
   Chips & badges — icon or glyph plus a word, never a naked coloured dot.
   -------------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-block-size: 26px;
  padding-inline: var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--surface-sunken);
  color: var(--ink-muted);
  white-space: nowrap;
}

.chip--success { background: var(--success-surface); color: var(--success); }
.chip--warning { background: var(--warning-surface); color: var(--warning); }
.chip--danger { background: var(--danger-surface); color: var(--danger); }
.chip--brand { background: var(--brand-tint); color: var(--brand); }
.chip--accent { background: color-mix(in oklab, var(--accent) 30%, var(--surface)); color: var(--accent-ink); }

.chip--gst {
  font-family: var(--font-mono);
  border-radius: var(--r-xs);
}

.chip--qty {
  min-inline-size: 44px;
  justify-content: center;
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--surface-sunken);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.field__error {
  font-size: var(--text-sm);
  color: var(--danger);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.input {
  min-block-size: 52px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  color: var(--ink);
  inline-size: 100%;
  transition: border-color var(--dur-fast) var(--ease-out);
}

.input::placeholder { color: var(--ink-faint); }
.input:focus { border-color: var(--brand); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input--mono { font-family: var(--font-mono); }
.input--phone { font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235C5546' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-inline-end: var(--sp-10);
}

.field-group {
  display: flex;
  gap: var(--sp-2);
}

.prefix-field {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-raised);
}

.prefix-field:focus-within { border-color: var(--brand); }

.prefix-field__prefix {
  display: grid;
  place-items: center;
  padding-inline: var(--sp-3);
  background: var(--surface-sunken);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  border-inline-end: 1px solid var(--line);
}

.prefix-field .input {
  border: none;
  border-radius: 0;
  background: transparent;
}

/* --------------------------------------------------------------------------
   Toasts — stack above the action bar, never over the hero button.
   -------------------------------------------------------------------------- */

.toast-host {
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--actionbar-h) + var(--sp-2));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding-inline: var(--sp-4);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  inline-size: 100%;
  max-inline-size: 480px;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-raised-2);
  box-shadow: var(--e-3);
  border-inline-start: 3px solid var(--ink-muted);
  font-size: var(--text-base);
  animation: toast-in var(--dur-base) var(--ease-out);
}

.toast--success { border-inline-start-color: var(--success); color: var(--ink); }
.toast--error { border-inline-start-color: var(--danger); }
.toast--warning { border-inline-start-color: var(--warning); }

.toast__icon { flex: none; color: var(--ink-muted); }
.toast--success .toast__icon { color: var(--success); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning .toast__icon { color: var(--warning); }
.toast__msg { flex: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.is-leaving {
  animation: toast-out var(--dur-fast) var(--ease-in) forwards;
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* --------------------------------------------------------------------------
   Action bar — the thumb zone
   -------------------------------------------------------------------------- */

.actionbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-actionbar);
  padding: var(--sp-3) var(--page-pad);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
  background: var(--surface-raised);
  border-top: 1px solid var(--line);
  box-shadow: var(--e-3);
}

.actionbar--with-nav { bottom: var(--navbar-h); }

.actionbar__inner {
  max-inline-size: var(--content-max);
  margin-inline: auto;
  display: flex;
  gap: var(--sp-2);
}

/* --------------------------------------------------------------------------
   Empty states
   -------------------------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4);
  max-inline-size: 320px;
  margin-inline: auto;
}

.empty__art { color: var(--ink-muted); margin-bottom: var(--sp-2); }
.empty__title { font-size: var(--text-lg); font-weight: 600; }
.empty__body { font-size: var(--text-sm); color: var(--ink-muted); }

/* --------------------------------------------------------------------------
   Bilingual labels — Kannada at full size, English one step down and muted.
   Hierarchy by size and colour, never by case.
   -------------------------------------------------------------------------- */

.bi {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.bi__kn {
  /* Kannada glyphs need headroom; do not clip the line box. */
  padding-block: 0.05em;
}

.bi__en {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-weight: 500;
}

.btn--primary .bi__en,
.btn--danger .bi__en,
.btn--hero .bi__en {
  color: inherit;
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Sheets & modals
   -------------------------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--scrim);
  animation: fade-in var(--dur-fast) var(--ease-out);
}

@supports (backdrop-filter: blur(4px)) {
  .scrim { backdrop-filter: blur(4px); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-modal);
  max-block-size: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-raised);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--e-4);
  padding: var(--sp-4) var(--page-pad);
  padding-bottom: max(var(--sp-6), env(safe-area-inset-bottom));
  animation: sheet-in var(--dur-slow) var(--ease-out);
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet__handle {
  inline-size: 36px;
  block-size: 4px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  margin: 0 auto var(--sp-4);
}

.sheet__title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--sp-3);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--sp-4);
}

.modal__panel {
  inline-size: 100%;
  max-inline-size: 400px;
  background: var(--surface-raised-2);
  border-radius: var(--r-xl);
  box-shadow: var(--e-4);
  padding: var(--sp-6);
  animation: modal-in var(--dur-base) var(--ease-out);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Numeral roll — money changes by rolling, never by jumping.
   Dry and precise: the spring easing never touches a numeral.
   -------------------------------------------------------------------------- */

.roll {
  display: inline-flex;
  overflow: hidden;
  block-size: 1.15em;
  vertical-align: baseline;
}

.roll__col {
  display: inline-block;
  transition: transform var(--dur-slow) var(--ease-inout);
}

/* --------------------------------------------------------------------------
   Shared animations
   -------------------------------------------------------------------------- */

@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

.is-shaking { animation: shake 240ms var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  /* The fallback is designed, not merely absent: the border flashes instead
     of the element moving. */
  .is-shaking {
    animation: none;
    outline: 2px solid var(--danger);
    outline-offset: 2px;
  }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fade-up var(--dur-base) var(--ease-out) both; }

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.skeleton {
  background: var(--surface-sunken);
  background-image: linear-gradient(
    100deg,
    transparent 30%,
    color-mix(in oklab, var(--ink) 5%, transparent) 50%,
    transparent 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}

/* --------------------------------------------------------------------------
   HTMX feedback. A request in flight dims its target slightly so the staffer
   knows the tap registered, without a spinner covering the content.
   -------------------------------------------------------------------------- */

.htmx-request.htmx-indicator-target {
  opacity: 0.55;
  transition: opacity var(--dur-fast) var(--ease-out);
}

[data-loading] { display: none; }
.htmx-request [data-loading] { display: inline-flex; }
.htmx-request [data-idle] { display: none; }

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.text-muted { color: var(--ink-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-inline-size: 0;
}

.desktop-only { display: none; }
@media (min-width: 900px) {
  .desktop-only { display: revert; }
  .mobile-only { display: none; }
}
