:root {
  color-scheme: light dark;
  --ink: var(--tg-theme-text-color, #14231b);
  --muted: var(--tg-theme-hint-color, #68766e);
  --canvas: var(--tg-theme-secondary-bg-color, #edf1ed);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --input: color-mix(in srgb, var(--surface) 94%, var(--ink));
  --line: color-mix(in srgb, var(--ink) 14%, transparent);
  --line-strong: color-mix(in srgb, var(--ink) 24%, transparent);
  --brand: #175d3e;
  --brand-strong: #10472f;
  --brand-bright: #70c83d;
  --brand-text: #175d3e;
  --brand-soft: color-mix(in srgb, var(--brand) 11%, var(--surface));
  --danger: #b83d36;
  --danger-text: #a9322c;
  --danger-soft: color-mix(in srgb, var(--danger) 10%, var(--surface));
  --warning: #84520d;
  --warning-soft: #fff1d7;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  min-width: 280px;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button { -webkit-tap-highlight-color: transparent; }

h1,
h2,
p { margin: 0; }

h1 {
  color: #ffffff;
  font-size: 22px;
  line-height: 1.12;
  font-weight: 780;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 760;
  text-wrap: balance;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(28px + var(--safe-bottom));
  background: var(--canvas);
}

.app-header {
  padding: var(--safe-top) 16px 16px;
  color: #ffffff;
  background: var(--brand-strong);
}

.header-main {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 14px;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 8px;
  color: var(--brand-strong);
  background: var(--brand-bright);
  font-size: 12px;
  font-weight: 850;
}

.header-title {
  min-width: 0;
}

.eyebrow,
.label,
.field > span:first-child,
legend,
.summary-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  font-weight: 650;
}

.app-header .eyebrow {
  margin-bottom: 2px;
  color: rgba(255, 255, 255, .68);
  font-size: 11px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 255, 255, .42);
  border-radius: 50%;
  background: transparent;
  transition: background-color 180ms var(--ease-out), border-color 180ms var(--ease-out);
}

.status-dot.is-online {
  border-color: rgba(112, 200, 61, .38);
  background: var(--brand-bright);
  box-shadow: 0 0 0 3px rgba(112, 200, 61, .14);
}

.identity-band {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .14);
}

.identity-band > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.identity-band .label {
  color: rgba(255, 255, 255, .6);
  font-size: 11px;
}

.identity-band strong {
  overflow-wrap: anywhere;
  color: #ffffff;
  font-size: 14px;
  font-weight: 720;
}

.identity-date {
  flex: none;
  text-align: right;
}

.mode-banner,
.error-banner {
  margin: 12px 16px 0;
  padding: 12px 13px;
  border: 1px solid #e0bd7d;
  border-radius: 8px;
  color: #69420a;
  background: var(--warning-soft);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 650;
}

.error-banner {
  position: sticky;
  bottom: var(--safe-bottom);
  z-index: 5;
  border-color: color-mix(in srgb, var(--danger) 42%, transparent);
  color: var(--danger-text);
  background: var(--danger-soft);
}

.venue-switch {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  margin: 12px 16px;
  padding: 4px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 7%, var(--canvas));
}

.venue-switch button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 720;
  cursor: pointer;
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.venue-switch button.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(16, 40, 27, .12);
}

.venue-switch button:active { transform: scale(.98); }

.shift-form { display: grid; gap: 10px; }

.section {
  padding: 20px 16px 22px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.state-badge {
  flex: none;
  padding: 5px 7px;
  border-radius: 5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--ink) 7%, var(--surface));
  font-size: 11px;
  line-height: 1.2;
  font-weight: 700;
}

.state-badge.is-ready {
  color: var(--brand-text);
  background: var(--brand-soft);
}

.state-badge.state-loading { animation: loading-pulse 1.4s ease-in-out infinite; }

@keyframes loading-pulse {
  50% { opacity: .55; }
}

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

.field-grid.is-single { grid-template-columns: 1fr; }

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field-wide { margin-bottom: 12px; }

.field > span:first-child,
legend {
  font-size: 13px;
  font-weight: 650;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--ink);
  background: var(--input);
  outline: none;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 160ms var(--ease-out);
}

select,
input {
  height: 54px;
  padding: 0 13px;
}

select { font-size: 16px; }

textarea {
  min-height: 96px;
  padding: 13px;
  line-height: 1.45;
  resize: vertical;
}

select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

.money-input {
  position: relative;
  display: block;
}

.money-input input {
  padding-right: 39px;
  font-size: 19px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.money-input b {
  position: absolute;
  top: 17px;
  right: 13px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}

.crm-facts {
  margin-top: 16px;
  padding: 13px;
  border-radius: 10px;
  background: var(--brand-soft);
}

.crm-facts-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.crm-facts-heading > span:first-child {
  color: var(--brand-text);
  font-size: 12px;
  font-weight: 720;
}

.fact-list { margin: 0; }

.fact-list-compact {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, .65fr);
  gap: 12px;
}

.fact-list-compact > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.fact-list-compact > div:last-child {
  padding-left: 12px;
  border-left: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}

.fact-list dt {
  color: var(--muted);
  font-size: 12px;
}

.fact-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 16px;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.form-group {
  min-width: 0;
  border: 0;
}

.report-fields {
  margin: 18px 0 0;
  padding: 17px 0 0;
  border-top: 1px solid var(--line);
}

.report-fields legend { padding: 0 0 13px; }
.cashless-fields,
.cash-fields { margin: 0; padding: 0; }

.bank-fields {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.field-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.form-group.has-error {
  margin-right: -8px;
  margin-left: -8px;
  padding: 12px 8px 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 44%, transparent);
  border-radius: 10px;
  background: var(--danger-soft);
}

.report-fields.has-error { margin-top: 12px; }

.field.has-error .money-input input,
input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent);
}

.report-totals {
  margin: 0 16px;
  padding: 17px 16px;
  border-radius: 10px;
  color: #ffffff;
  background: var(--brand-strong);
}

.report-totals .summary-label {
  display: block;
  margin-bottom: 9px;
  color: rgba(255, 255, 255, .62);
}

.report-totals > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding: 7px 0;
}

.report-totals > div + div {
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.report-totals > div span {
  color: rgba(255, 255, 255, .72);
  font-size: 13px;
}

.report-totals strong {
  flex: none;
  color: #ffffff;
  font-size: 18px;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.button {
  width: calc(100% - 32px);
  min-height: 54px;
  margin: 2px 16px 0;
  border: 0;
  border-radius: 9px;
  font-weight: 780;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out), transform 160ms var(--ease-out), opacity 160ms var(--ease-out);
}

.button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand-bright) 55%, transparent);
  outline-offset: 2px;
}

.button:active { transform: scale(.98); }

.button:disabled {
  cursor: wait;
  opacity: .52;
}

.button-primary {
  color: #ffffff;
  background: var(--brand);
}

.button-secondary {
  color: #ffffff;
  background: var(--brand);
}

.button-correction {
  border: 1px solid color-mix(in srgb, var(--brand) 24%, transparent);
  color: var(--brand-text);
  background: var(--brand-soft);
}

.result-panel,
.closed-panel {
  display: grid;
  gap: 12px;
  margin: 12px 16px 0;
  padding: 20px 16px;
  border-radius: 10px;
  background: var(--surface);
}

.result-panel .button,
.closed-panel .button {
  width: 100%;
  margin-right: 0;
  margin-left: 0;
}

.result-panel.is-error { color: var(--danger-text); }

.result-icon,
.closed-check {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--brand);
  font-size: 23px;
  font-weight: 800;
}

.result-panel.is-error .result-icon,
.closed-panel.is-error .closed-check { background: var(--danger); }

.issue-list {
  display: grid;
  gap: 8px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

.issue-list li {
  position: relative;
  padding: 12px 12px 12px 38px;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  border-radius: 8px;
  color: var(--danger-text);
  background: var(--danger-soft);
  font-size: 13px;
  line-height: 1.4;
}

.issue-list li::before {
  content: "!";
  position: absolute;
  top: 11px;
  left: 12px;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--danger);
  font-size: 11px;
  font-weight: 800;
}

.closed-panel > p:not(.eyebrow) { color: var(--muted); }

.closed-panel pre {
  max-height: 340px;
  margin: 6px 0 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--input);
  font: 12px/1.5 Consolas, monospace;
  white-space: pre-wrap;
}

[hidden] { display: none !important; }

@media (hover: hover) and (pointer: fine) {
  .venue-switch button:not(.is-active):hover {
    color: var(--ink);
    background: color-mix(in srgb, var(--surface) 62%, transparent);
  }

  .button:not(:disabled):hover { background: var(--brand-strong); }
  .button-correction:not(:disabled):hover {
    color: #ffffff;
    background: var(--brand);
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([style*="--tg-theme-bg-color"]) {
    --ink: #edf5ef;
    --muted: #a6b4aa;
    --canvas: #111915;
    --surface: #18221c;
    --input: #202b24;
    --line: rgba(235, 245, 238, .1);
    --line-strong: rgba(235, 245, 238, .18);
    --brand-soft: #213a2c;
    --brand-text: #78d5a1;
    --danger-soft: #38211f;
    --danger-text: #ff9b94;
  }

  .mode-banner {
    border-color: #6e5427;
    color: #f0cb82;
    background: #332711;
  }
}

@media (min-width: 561px) {
  .app-shell {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }
}

@media (max-width: 360px) {
  .app-header,
  .section { padding-right: 13px; padding-left: 13px; }
  .venue-switch,
  .mode-banner,
  .error-banner,
  .report-totals,
  .result-panel,
  .closed-panel { margin-right: 13px; margin-left: 13px; }
  .button { width: calc(100% - 26px); margin-right: 13px; margin-left: 13px; }
  .money-input input { font-size: 17px; }
  .report-totals > div { gap: 10px; }
}

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