:root {
  --bg: #0a0a0f;
  --bg-elev: #11131a;
  --bg-elev-2: #161922;
  --line: #1e222d;
  --line-2: #262b38;
  --text: #ececf1;
  --mut: #9aa0ab;
  --brand: #ff7a00;
  --brand-2: #ff9838;
  --brand-glow: rgba(255, 122, 0, 0.22);
  --ok: #22c55e;
  --warn: #eab308;
  --bad: #ef4444;
  --r: 16px;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}
body {
  min-height: 100dvh;
  background: radial-gradient(900px 600px at 10% -10%, rgba(255, 122, 0, 0.1), transparent 60%),
    radial-gradient(700px 500px at 100% 110%, rgba(255, 122, 0, 0.07), transparent 60%), var(--bg);
}
a {
  color: var(--brand);
}
.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: clamp(18px, 5vw, 40px) clamp(16px, 5vw, 28px) 64px;
}
.brand-tag {
  font-size: 12.5px;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}
.brand-tag b {
  color: var(--brand);
}
h1 {
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.14;
  margin: 12px 0 8px;
}
h1 .hl {
  color: var(--brand);
}
.sub {
  color: var(--mut);
  font-size: 15px;
  margin: 0 0 24px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(20px, 5vw, 30px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
}
.field .hint {
  color: var(--mut);
  font-weight: 400;
  font-size: 12.5px;
}
input[type="email"],
input[type="text"],
input[type="tel"],
input[inputmode] {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.input-money {
  position: relative;
}
.input-money::before {
  content: "R$";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mut);
  font-size: 15px;
  pointer-events: none;
}
.input-money input {
  padding-left: 42px;
}
.input-pct {
  position: relative;
}
.input-pct::after {
  content: "%";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mut);
  font-size: 15px;
  pointer-events: none;
}
.otp-input {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 24px;
  font-weight: 700;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  padding: 0 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--brand);
  color: #0a0a0f;
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-2);
}
.btn-ghost:hover {
  border-color: var(--brand);
  color: var(--brand);
}
.btn-link {
  background: none;
  border: none;
  color: var(--mut);
  font-size: 13.5px;
  cursor: pointer;
  padding: 8px;
  width: auto;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.2);
}
.btn-link:hover {
  color: var(--brand);
}
.msg {
  font-size: 13.5px;
  padding: 11px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  display: none;
}
.msg.show {
  display: block;
}
.msg.err {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.32);
  color: #fca5a5;
}
.msg.ok {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.32);
  color: #86efac;
}
.hidden {
  display: none !important;
}
/* display:block das utilitárias vence o [hidden] do UA. Sem isto, o tooltip nasce aberto. */
[hidden] {
  display: none !important;
}
.center {
  text-align: center;
}
.row {
  display: flex;
  gap: 12px;
}
.row > * {
  flex: 1;
}
.foot {
  margin-top: 26px;
  color: var(--mut);
  font-size: 12.5px;
  text-align: center;
}

/* ---- App / calculadora ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 20px;
}
.tab {
  flex: 1;
  height: 42px;
  border: none;
  background: transparent;
  color: var(--mut);
  font-weight: 700;
  font-size: 13.5px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.active {
  background: var(--brand);
  color: #0a0a0f;
}
.result {
  margin-top: 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.result .headline {
  padding: 22px;
  text-align: center;
}
.result .headline .lbl {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mut);
  font-weight: 700;
}
.result .headline .big {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 6px 0 2px;
}
.result.g {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.35);
}
.result.y {
  background: rgba(234, 179, 8, 0.08);
  border-color: rgba(234, 179, 8, 0.35);
}
.result.r {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
}
.result.g .big {
  color: var(--ok);
}
.result.y .big {
  color: var(--warn);
}
.result.r .big {
  color: var(--bad);
}
.result .note {
  font-size: 14px;
  color: var(--text);
  padding: 0 22px 4px;
  text-align: center;
}
.breakdown {
  border-top: 1px solid var(--line);
  padding: 16px 22px 20px;
  background: rgba(255, 255, 255, 0.015);
}
.breakdown .line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 6px 0;
  color: var(--mut);
}
.breakdown .line b {
  color: var(--text);
  font-weight: 600;
}
.breakdown .line.total {
  border-top: 1px dashed var(--line-2);
  margin-top: 6px;
  padding-top: 12px;
  color: var(--text);
  font-weight: 700;
}
.items {
  margin-top: 8px;
}
.item-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.item-row input.iname {
  flex: 1.4;
}
.item-row .input-money {
  flex: 1;
}
.item-row .del {
  flex: 0 0 44px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev-2);
  color: var(--mut);
  font-size: 18px;
  cursor: pointer;
}
.item-row .del:hover {
  border-color: var(--bad);
  color: var(--bad);
}

/* ---- Segmented control (canal, modo de custo) ---- */
.label-txt {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
}
.seg {
  display: flex;
  gap: 10px;
}
.seg-btn {
  flex: 1;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev-2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.seg-btn:hover {
  border-color: var(--brand);
}
.seg-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #0a0a0f;
  font-weight: 700;
}
.seg-btn:focus-visible,
.btn:focus-visible,
.btn-link:focus-visible,
.btn-chip:focus-visible,
.tip:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---- Hints, chips, tooltip ---- */
.hint.block {
  display: block;
  margin: 7px 0 0;
  color: var(--mut);
  font-size: 12.5px;
  line-height: 1.45;
}
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.btn-chip {
  background: var(--bg-elev-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.btn-chip:hover {
  border-color: var(--brand);
  color: var(--brand);
}
.total-chip {
  display: inline-block;
  margin-top: 4px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line-2);
  font-size: 13px;
  color: var(--mut);
}
.total-chip b {
  color: var(--text);
}
.tip {
  width: 20px;
  height: 20px;
  padding: 0;
  margin-left: 2px;
  border-radius: 50%;
  border: 1px solid rgba(255, 122, 0, 0.45);
  background: rgba(255, 122, 0, 0.12);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}
.tip:hover {
  background: rgba(255, 122, 0, 0.22);
}

/* ---- Topbar / resultado ---- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.result.n {
  background: rgba(255, 122, 0, 0.07);
  border-color: rgba(255, 122, 0, 0.32);
}
.result.n .big {
  color: var(--brand);
}
.result.empty {
  background: rgba(255, 255, 255, 0.02);
  border-style: dashed;
  border-color: var(--line-2);
}
.result.empty .note {
  color: var(--mut);
}
#btn-save {
  margin-top: 14px;
}

/* ---- Painel de histórico ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.sheet {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 20px clamp(16px, 5vw, 24px) calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.6);
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up {
  from {
    transform: translate(-50%, 12px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-foot {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn-ghost.danger:hover {
  border-color: var(--bad);
  color: var(--bad);
}
.hist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.hist-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.hist-main b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-num {
  text-align: right;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.hist-num.g {
  color: var(--ok);
}
.hist-num.y {
  color: var(--warn);
}
.hist-num.r {
  color: var(--bad);
}

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