/*
 * Espetinhos — one dark surface for a counter used at night, warm ember accent, dense money tables.
 * Tokens first, then layout, then components. Mobile is the primary size.
 */

:root {
  --bg: #12100f;
  --bg-rail: #14110f;
  --surface: #1a1715;
  --surface-2: #221e1b;
  --surface-3: #2b2622;
  --line: #322b27;
  --line-soft: #262120;
  --text: #f4eee8;
  --text-2: #bfb3aa;
  --text-3: #9b8f86;
  --ember: #ff7a45;
  --ember-strong: #ff9764;
  --ember-soft: rgb(255 122 69 / 14%);
  --ember-ink: #1a0f09;
  --good: #5ec98f;
  --good-soft: rgb(94 201 143 / 13%);
  --bad: #f2807f;
  --bad-soft: rgb(242 128 127 / 13%);
  --warn: #e6b45e;
  --warn-soft: rgb(230 180 94 / 13%);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --gap: 16px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 24px -18px rgb(0 0 0 / 70%);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Author `display` rules outrank the UA sheet's `[hidden]`, so state that depends on `hidden` needs this. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 520px at 18% -8%, rgb(255 122 69 / 7%), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ul,
ol {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

a {
  color: var(--ember-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--ember);
  color: var(--ember-ink);
}

:focus-visible {
  outline: 2px solid var(--ember-strong);
  outline-offset: 2px;
  border-radius: 4px;
}

input,
select {
  caret-color: var(--ember-strong);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

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

[data-series="0"] {
  background: #ff7a45;
}

[data-series="1"] {
  background: #5ec98f;
}

[data-series="2"] {
  background: #e6b45e;
}

[data-series="3"] {
  background: #8aa9ff;
}

[data-series="4"] {
  background: #c58bff;
}

[data-series="5"] {
  background: #f2807f;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ------------------------------------------------------------------ layout */

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.app[data-ready="false"] {
  grid-template-columns: minmax(0, 1fr);
}

.app[data-ready="false"] .rail,
.app[data-ready="false"] .tabbar,
.app[data-ready="false"] .topbar {
  display: none;
}

.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px 18px;
  background: var(--bg-rail);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 4px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--ember-soft);
  color: var(--ember);
  flex: none;
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand-mark-lg {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  margin-bottom: 18px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}

.nav button svg {
  width: 18px;
  height: 18px;
  color: var(--text-3);
  transition: color 160ms ease;
}

.nav button:hover {
  background: var(--surface);
  color: var(--text);
}

.nav button[aria-current="page"] {
  background: var(--ember-soft);
  color: var(--text);
  font-weight: 550;
}

.nav button[aria-current="page"] svg {
  color: var(--ember);
}

.rail-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.rail-note {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-3);
  padding: 0 4px;
}

.rail-foot .btn {
  justify-content: flex-start;
}

.shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: none;
}

.main {
  padding: 30px clamp(18px, 3vw, 36px) 56px;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
}

.tabbar {
  display: none;
}

/* ------------------------------------------------------------------- login */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(390px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 26px 26px;
  display: grid;
  gap: 16px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 2px;
}

.login-brand .brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
}

.login-brand .brand-mark svg {
  width: 25px;
  height: 25px;
}

.login-card h1 {
  font-size: 1.375rem;
}

.login-sub {
  color: var(--text-2);
  font-size: 0.8125rem;
  margin-top: 2px;
}

/* ---------------------------------------------------------------- view head */

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.view-head .sub {
  margin-top: 4px;
  color: var(--text-2);
  font-size: 0.875rem;
}

.period {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.period button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 0.8125rem;
  padding: 6px 11px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}

.period button:hover {
  color: var(--text);
}

.period button[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 550;
}

.range-custom {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin: -8px 0 18px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
}

.subtabs button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 0.875rem;
  padding: 9px 12px 11px;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 160ms ease, border-color 160ms ease;
}

.subtabs button:hover {
  color: var(--text);
}

.subtabs button[aria-selected="true"] {
  color: var(--text);
  font-weight: 550;
  border-bottom-color: var(--ember);
}

/* ----------------------------------------------------------------- metrics */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 15px;
  display: grid;
  gap: 3px;
  align-content: start;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-3);
}

.metric-value {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.metric-note {
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.metric-primary .metric-value {
  color: var(--ember-strong);
}

.tone-good {
  color: var(--good) !important;
}

.tone-bad {
  color: var(--bad) !important;
}

.tone-warn {
  color: var(--warn) !important;
}

/* ------------------------------------------------------------------ panels */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
  min-width: 0;
}

.grid-2 > .panel {
  margin-bottom: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 24px;
}

.panel-note {
  font-size: 0.75rem;
  color: var(--text-3);
  text-align: right;
}

.panel-link {
  font-size: 0.8125rem;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-head .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin: 0 5px 0 10px;
  vertical-align: baseline;
}

.dot:first-child {
  margin-left: 0;
}

.dot-ember {
  background: var(--ember);
}

.dot-good {
  background: var(--good);
}

.count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* ------------------------------------------------------------------ charts */

.chart svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart .grid-line {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.chart .axis-label {
  fill: var(--text-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chart .bar {
  fill: var(--ember);
  opacity: 0.82;
}

.chart .bar:hover {
  opacity: 1;
}

.chart .profit-line {
  fill: none;
  stroke: var(--good);
  stroke-width: 2;
  stroke-linejoin: round;
}

.chart .profit-dot {
  fill: var(--good);
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: 8px 0;
  color: var(--text-3);
  font-size: 0.8125rem;
  text-align: center;
  text-wrap: balance;
}

/* ---------------------------------------------------------------- segments */

.segment-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
  margin-bottom: 14px;
}

.segment-bar span {
  display: block;
  height: 100%;
}

.segment-legend {
  display: grid;
  gap: 9px;
}

.segment-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  font-size: 0.8125rem;
}

.segment-swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
}

.segment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
}

.segment-value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.segment-extra {
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-width: 54px;
  text-align: right;
}

/* ------------------------------------------------------------ ranked lists */

.rank-list {
  display: grid;
  gap: 2px;
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.rank-row:last-child {
  border-bottom: 0;
}

.rank-name {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-value {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.rank-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.rank-track {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.rank-track span {
  display: block;
  height: 100%;
  background: var(--ember);
  opacity: 0.75;
  border-radius: inherit;
}

/* ------------------------------------------------------------------ tables */

.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

caption {
  text-align: left;
  color: var(--text-3);
  font-size: 0.75rem;
  padding-bottom: 8px;
}

th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: rgb(255 255 255 / 2%);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cell-strong {
  font-weight: 550;
}

.cell-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 1px;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ------------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.6;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}

.badge-good {
  background: var(--good-soft);
  color: var(--good);
}

.badge-bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-ember {
  background: var(--ember-soft);
  color: var(--ember-strong);
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease, transform 120ms ease;
  white-space: nowrap;
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--line-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary:disabled {
  opacity: 1;
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text-3);
}

.btn-primary {
  background: var(--ember);
  border-color: var(--ember);
  color: var(--ember-ink);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--ember-strong);
  border-color: var(--ember-strong);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn-quiet:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--bad);
}

.btn-danger:hover {
  background: var(--bad-soft);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.8125rem;
  border-radius: var(--radius-xs);
}

.btn-block {
  width: 100%;
}

/* -------------------------------------------------------------------- forms */

.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.form-inline .form-actions {
  display: flex;
  gap: 8px;
}

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

.field > span {
  font-size: 0.75rem;
  color: var(--text-3);
}

.field em {
  font-style: normal;
  color: var(--text-3);
  opacity: 0.8;
}

.field input,
.field select {
  height: 40px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  min-width: 0;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.field input::placeholder {
  color: var(--text-3);
}

.field input:hover,
.field select:hover {
  border-color: var(--surface-3);
}

.field input:focus,
.field select:focus {
  border-color: var(--ember);
  outline: none;
  box-shadow: 0 0 0 3px rgb(255 122 69 / 18%);
}

.field select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.field-grow {
  flex: 1 1 200px;
}

.field-wide {
  flex: 1 1 100%;
}

.field-xs {
  width: 96px;
  flex: none;
}

.field input[type="date"] {
  min-width: 130px;
}

.form-error {
  flex: 1 1 100%;
  color: var(--bad);
  font-size: 0.8125rem;
}

.form-hint {
  flex: 1 1 100%;
  color: var(--text-3);
  font-size: 0.75rem;
}

.search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-3);
}

.search svg {
  width: 15px;
  height: 15px;
}

.search input {
  border: 0;
  background: transparent;
  height: 100%;
  width: 140px;
  font-size: 0.8125rem;
  outline: none;
}

/* -------------------------------------------------------------------- sale */

.sale-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: var(--gap);
  align-items: start;
  margin-bottom: var(--gap);
}

.sale-layout > .panel {
  margin-bottom: 0;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 430px;
  overflow-y: auto;
  padding-right: 4px;
}

.item-btn {
  display: grid;
  gap: 3px;
  text-align: left;
  padding: 11px 12px;
  min-height: 62px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 120ms ease;
}

.item-btn:hover {
  border-color: var(--ember);
  background: var(--surface-3);
}

.item-btn:active {
  transform: scale(0.985);
}

.item-btn-name {
  font-size: 0.875rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-btn-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.item-btn-price {
  color: var(--text-2);
}

.cart {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 14px;
}

.cart-lines {
  display: grid;
  gap: 8px;
  min-height: 56px;
}

.cart-empty {
  color: var(--text-3);
  font-size: 0.8125rem;
  padding: 10px 0;
}

.cart-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  row-gap: 8px;
  align-items: center;
  gap: 6px 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.cart-line-name {
  grid-column: 1;
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cart-line-price {
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.cart-line-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 2px;
}

.stepper button {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.stepper button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.stepper svg {
  width: 14px;
  height: 14px;
}

.stepper-value {
  min-width: 30px;
  text-align: center;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.stepper-input {
  width: 56px;
  height: 26px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.stepper-input:focus {
  background: var(--surface-3);
  outline: none;
  box-shadow: 0 0 0 2px rgb(255 122 69 / 35%);
}

.cart-line-total {
  grid-column: 2;
  grid-row: 1;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  min-width: 62px;
  text-align: right;
}

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

.cart-total {
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-2);
}

.cart-total-row span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.cart-total-row.is-total {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  padding-top: 4px;
}

.cart-total-row.is-total span:last-child {
  color: var(--ember-strong);
}

.sale-bar {
  display: none;
}

/* ---------------------------------------------------------------- expenses */

.expense-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.expense-row:last-child {
  border-bottom: 0;
}

.expense-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.expense-desc {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-meta {
  font-size: 0.75rem;
  color: var(--text-3);
}

.expense-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  text-align: right;
}

.export-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ------------------------------------------------------------- empty states */

.empty {
  display: grid;
  gap: 6px;
  justify-items: start;
  padding: 20px 0 18px;
  color: var(--text-2);
  font-size: 0.875rem;
}

.empty strong {
  color: var(--text);
  font-weight: 550;
}

.empty p {
  color: var(--text-3);
  font-size: 0.8125rem;
  max-width: 52ch;
}

/* -------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.8125rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 40;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  border-color: rgb(242 128 127 / 45%);
  color: var(--bad);
}

.toast.is-success {
  border-color: rgb(94 201 143 / 40%);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    display: none;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-rail);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
  }

  .topbar-brand svg {
    width: 19px;
    height: 19px;
    color: var(--ember);
  }

  .main {
    padding: 20px 16px 96px;
  }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--bg-rail);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }

  .tabbar button {
    display: grid;
    justify-items: center;
    gap: 3px;
    padding: 5px 2px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-3);
    font-size: 0.6875rem;
    cursor: pointer;
  }

  .tabbar button svg {
    width: 20px;
    height: 20px;
  }

  .tabbar button[aria-current="page"] {
    color: var(--ember);
  }

  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .sale-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .cart {
    position: static;
  }

  /* The bar above the tab bar already submits; a second identical button wastes thumb reach. */
  #sale-submit {
    display: none;
  }

  .item-grid {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .sale-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 29;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  /* The fixed sale bar and tab bar overlap the last fields, so the sale view carries their height. */
  .view[data-view="vendas"] {
    padding-bottom: 92px;
  }

  .sale-bar-info {
    display: grid;
    gap: 1px;
    font-size: 0.75rem;
    color: var(--text-3);
  }

  .sale-bar-info strong {
    font-size: 1rem;
    color: var(--text);
    font-variant-numeric: tabular-nums;
  }

  .toast {
    bottom: calc(120px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  body {
    font-size: 14.5px;
  }

  h1 {
    font-size: 1.25rem;
  }

  .view-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .period {
    width: 100%;
    overflow-x: auto;
  }

  .period button {
    flex: 1;
    padding: 7px 8px;
  }

  .panel {
    padding: 15px;
    border-radius: 12px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    padding: 12px 13px;
  }

  .metric-value {
    font-size: 1.1875rem;
  }

  .cart-fields {
    grid-template-columns: minmax(0, 1fr);
  }


  .subtabs {
    overflow-x: auto;
  }

  /* Dense money tables stay on one line and scroll sideways instead of turning into tall strips. */
  table {
    min-width: 520px;
  }

  .subtabs button {
    white-space: nowrap;
  }

  .login-card {
    padding: 24px 20px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
