:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #111827;
  --muted: #4b5563;
  --border: #dfe3e8;
  --field-border: #7b8494;
  --brand: #0f766e;
  --brand-hover: #115e59;
  --brand-text: #115e59;
  --brand-soft: #d5f0ec;
  --on-brand: #ffffff;
  --danger: #b42318;
  --danger-soft: #fde7e4;
  --on-danger: #ffffff;
  --warning: #8a4b00;
  --warning-soft: #fdefd3;
  --success: #166534;
  --success-soft: #dcf5e3;
  --whats: #0f7a40;
  --focus: #0f766e;
  --backdrop: rgb(17 24 39 / 0.55);
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 4px 14px rgb(16 24 40 / 0.05);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 48px;
  --nav-height: 4.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #212833;
    --text: #e6edf3;
    --muted: #a3adb8;
    --border: #2c3440;
    --field-border: #6b7685;
    --brand: #2dd4bf;
    --brand-hover: #5eead4;
    --brand-text: #5eead4;
    --brand-soft: #12332f;
    --on-brand: #04201c;
    --danger: #f87171;
    --danger-soft: #3a1614;
    --on-danger: #2a0606;
    --warning: #fbbf24;
    --warning-soft: #3a2a08;
    --success: #4ade80;
    --success-soft: #12301d;
    --whats: #25d366;
    --focus: #5eead4;
    --backdrop: rgb(0 0 0 / 0.65);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #212833;
  --text: #e6edf3;
  --muted: #a3adb8;
  --border: #2c3440;
  --field-border: #6b7685;
  --brand: #2dd4bf;
  --brand-hover: #5eead4;
  --brand-text: #5eead4;
  --brand-soft: #12332f;
  --on-brand: #04201c;
  --danger: #f87171;
  --danger-soft: #3a1614;
  --on-danger: #2a0606;
  --warning: #fbbf24;
  --warning-soft: #3a2a08;
  --success: #4ade80;
  --success-soft: #12301d;
  --whats: #25d366;
  --focus: #5eead4;
  --backdrop: rgb(0 0 0 / 0.65);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 50;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Login */

:root[data-auth="out"] .skip-link,
:root[data-auth="out"] .app-bar,
:root[data-auth="out"] .layout,
:root[data-auth="out"] .screen-nav,
:root:not([data-auth="out"]) .login-screen {
  display: none;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
}

.login-screen .login-card {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem 1.25rem;
}

.login-error {
  color: var(--danger);
  font-size: 0.9375rem;
  font-weight: 500;
}

.account-email {
  color: var(--text);
  overflow-wrap: anywhere;
}

/* App bar */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  min-height: 3.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: var(--brand);
  color: var(--on-brand);
}

.brand h1 {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: none;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.sync-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--muted);
}

.sync-chip[data-status="ready"] .sync-dot {
  background: var(--success);
}

.sync-chip[data-status="saving"] .sync-dot,
.sync-chip[data-status="loading"] .sync-dot {
  background: var(--warning);
}

.sync-chip[data-status="error"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.sync-chip[data-status="error"] .sync-dot {
  background: var(--danger);
}

/* Layout */

.layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem calc(var(--nav-height) + env(safe-area-inset-bottom) + 1.5rem);
  display: grid;
  gap: 1rem;
}

.screen {
  display: none;
  gap: 1rem;
  min-width: 0;
}

.screen.active {
  display: grid;
}

.screen-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.screen-title:focus {
  outline: none;
}

.card {
  display: grid;
  gap: 1rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.meta {
  color: var(--muted);
  font-size: 0.875rem;
}

.empty {
  padding: 1.25rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-align: center;
}

/* Notices */

.notice {
  display: grid;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--text);
  font-size: 0.9375rem;
}

.notice strong {
  color: var(--warning);
}

.notice-error {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.notice-error strong {
  color: var(--danger);
}

/* Stats */

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}

.stat {
  display: grid;
  gap: 0.125rem;
  min-width: 0;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.stat-label {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.stat-value {
  font-size: clamp(1rem, 4.6vw, 1.25rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.stat-main {
  grid-column: 1 / -1;
  padding: 1rem;
  border-color: transparent;
  background: var(--brand);
  color: var(--on-brand);
}

.stat-main .stat-label {
  color: inherit;
  opacity: 0.92;
}

.stat-main .stat-value {
  font-size: clamp(1.625rem, 8vw, 2.125rem);
  line-height: 1.15;
}

/* Forms */

.stacked-form {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.375rem;
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.field-hint {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
}

input:not([type="radio"]):not([type="checkbox"]):not([type="file"]),
select {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
}

input::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[type="file"] {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  font-size: 0.9375rem;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.625rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn:hover {
  border-color: var(--field-border);
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
}

.btn-primary:hover {
  border-color: transparent;
  background: var(--brand-hover);
}

.btn-ghost {
  border-color: var(--brand);
  background: transparent;
  color: var(--brand-text);
}

.btn-ghost:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

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

.btn-danger:hover {
  border-color: var(--danger);
}

.btn-danger-solid {
  background: var(--danger);
  color: var(--on-danger);
}

.btn-whats {
  background: var(--whats);
  color: #ffffff;
}

:root[data-theme="dark"] .btn-whats {
  color: #04200f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-whats {
    color: #04200f;
  }
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 3.5rem;
  font-size: 1.0625rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--field-border);
}

.icon-btn.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon {
  width: 1.375rem;
  height: 1.375rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

/* Pickers (cliente / produto) */

.picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
  min-height: 3.25rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}

.picker-text {
  display: grid;
  min-width: 0;
}

.picker-value {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.picker-value.is-placeholder {
  color: var(--muted);
  font-weight: 400;
}

.picker .icon {
  color: var(--muted);
}

/* Itens da venda */

.sale-items {
  display: grid;
  gap: 0.75rem;
}

.sale-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.sale-item .picker {
  grid-column: 1 / -1;
}

.stepper {
  display: grid;
  grid-template-columns: var(--tap) minmax(3.5rem, 5rem) var(--tap);
  gap: 0.375rem;
  justify-content: start;
}

.stepper .icon-btn {
  border-color: var(--field-border);
  background: var(--surface);
}

.stepper input {
  padding-inline: 0.25rem;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sale-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

.sale-total strong {
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
}

/* Filtros */

.filters {
  display: grid;
  gap: 0.75rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  margin: 0;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
}

.segmented label {
  position: relative;
  display: block;
  min-width: 0;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  padding: 0 0.25rem;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--brand-text);
  box-shadow: 0 0 0 1px var(--brand), var(--shadow);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

/* Listas */

.list {
  display: grid;
  gap: 0.625rem;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.list-item-main {
  display: grid;
  gap: 0.25rem;
  justify-items: start;
  flex: 1;
  min-width: 0;
}

.item-title {
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  flex: none;
  padding: 0.1875rem 0.625rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

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

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

.sale-card {
  display: grid;
  gap: 0.625rem;
  min-width: 0;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.sale-card.is-orphan {
  border-color: var(--warning);
}

.sale-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.sale-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.sale-summary .item-value {
  font-size: 1.25rem;
}

.sale-items-text {
  overflow-wrap: anywhere;
}

.row-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

/* Relatorios e ajustes */

.button-row {
  display: grid;
  gap: 0.625rem;
}

.report-output {
  min-height: 10rem;
  margin: 0;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.55;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.report-output:empty::before {
  content: attr(data-empty);
  color: var(--muted);
  font-family: "Inter", system-ui, sans-serif;
}

.pix-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.625rem;
  min-width: 0;
  margin-top: 0.875rem;
}

.pix-box[hidden] {
  display: none;
}

.pix-qr {
  justify-self: center;
  width: min(14rem, 100%);
  height: auto;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: #fff;
  image-rendering: pixelated;
}

.pix-code {
  min-height: 0;
  font-size: 0.75rem;
}

/* Navegacao inferior */

.screen-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.375rem max(0.375rem, env(safe-area-inset-right)) calc(0.375rem + env(safe-area-inset-bottom))
    max(0.375rem, env(safe-area-inset-left));
}

.screen-nav-inner {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.125rem;
  max-width: 560px;
  margin: 0 auto;
}

.nav-tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.125rem;
  min-width: 0;
  min-height: 3.75rem;
  padding: 0.25rem 0.125rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.nav-icon-wrap {
  display: grid;
  place-items: center;
  width: 3.5rem;
  max-width: 100%;
  height: 2rem;
  border-radius: 999px;
}

.nav-tab[aria-current="page"] {
  color: var(--brand-text);
}

.nav-tab[aria-current="page"] .nav-icon-wrap {
  background: var(--brand-soft);
}

/* Dialogos */

dialog {
  color: var(--text);
}

dialog::backdrop {
  background: var(--backdrop);
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  overflow: hidden;
}

.sheet-body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0.875rem;
  max-height: 88vh;
  max-height: 88dvh;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.selection-options {
  display: grid;
  align-content: start;
  gap: 0.5rem;
  min-height: 8rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.selection-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.selection-option:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.selection-option strong {
  overflow-wrap: anywhere;
}

.selection-option .meta {
  flex: none;
}

.confirm-dialog {
  width: calc(100% - 2rem);
  max-width: 400px;
  padding: 1.25rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
}

.confirm-dialog form {
  display: grid;
  gap: 1rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}

/* Avisos temporarios */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 0.75rem);
  z-index: 40;
  display: grid;
  gap: 0.5rem;
  width: min(100% - 2rem, 480px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  pointer-events: auto;
}

.toast-error {
  background: var(--danger);
  color: var(--on-danger);
}

/* Telas maiores */

@media (min-width: 560px) {
  .hero-stats {
    grid-template-columns: 1.3fr 1fr 1fr;
  }

  .stat-main {
    grid-column: auto;
  }

  .stat-main .stat-value {
    font-size: 1.5rem;
  }

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

  .sheet {
    margin: auto;
    border-radius: 20px;
  }
}

@media (min-width: 960px) {
  .layout {
    max-width: 1080px;
  }

  .screen-split.active {
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    align-items: start;
  }

  .screen-split > .screen-title,
  .screen-split > .hero-stats,
  .screen-split > .notice {
    grid-column: 1 / -1;
  }

  .screen-nav {
    inset: auto auto 1rem 50%;
    width: 560px;
    padding: 0.375rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgb(0 0 0 / 0.14);
    transform: translateX(-50%);
  }

  .layout {
    padding-bottom: calc(var(--nav-height) + 3rem);
  }
}

@media (max-width: 359px) {
  .filter-row {
    grid-template-columns: 1fr;
  }

  .nav-tab {
    font-size: 0.6875rem;
  }

  .sync-label {
    display: none;
  }

  .sync-chip {
    padding: 0 0.875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
