:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #8b5cf6;
  --gradient: linear-gradient(135deg, #2563eb 0%, #8b5cf6 100%);
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 14px rgba(15, 23, 42, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(96px + var(--safe-bottom));
}

/* ---------- Header ---------- */
.app-header {
  background: var(--gradient);
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px;
  color: #fff;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.35);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner { display: flex; align-items: center; gap: 12px; max-width: 560px; margin: 0 auto; }
.header-logo { width: 44px; height: 44px; border-radius: 12px; object-fit: contain; background: #fff; padding: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.18); }
.header-text { flex: 1; }
.header-text h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.header-text p { font-size: 12px; opacity: 0.85; font-weight: 500; }
.header-clear {
  background: rgba(255,255,255,0.16);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.header-clear:active { background: rgba(255,255,255,0.3); }

/* ---------- Cards / Form ---------- */
.app-main { max-width: 560px; margin: 0 auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  border: 1px solid var(--border);
}
.card-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before {
  content: '';
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--gradient);
}
.card-title-row { display: flex; align-items: center; justify-content: space-between; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
input, textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea { resize: vertical; min-height: 90px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 .field { margin-bottom: 0; }

/* ---------- Itens ---------- */
.item-card {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  position: relative;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.item-card .item-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 9px;
  background: #fee2e2;
  color: var(--danger);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.item-card .item-remove:active { background: #fecaca; }
.item-desc label { margin-right: 28px; }
.item-card .item-desc input { font-weight: 500; }
.item-row { display: grid; grid-template-columns: 0.8fr 1fr; gap: 10px; margin-top: 10px; }
.item-amount {
  align-self: flex-end;
  display: inline-block;
  font-size: 17px; /* 1pt maior que o campo de preenchimento (16px) */
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-light);
  padding: 5px 12px;
  border-radius: 10px;
  margin-top: 10px;
  text-align: right;
  letter-spacing: 0.01em;
}

.btn-add, .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn-add {
  width: 100%;
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px dashed var(--primary);
}
.btn-add:active { transform: scale(0.98); }

/* ---------- Desconto ---------- */
.desconto-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--border);
}
.desconto-row label { margin-bottom: 0; font-size: 13px; font-weight: 700; color: var(--text); }
.desconto-input-wrap { position: relative; width: 116px; }
.desconto-input-wrap input { padding-right: 30px; text-align: right; font-weight: 700; }
.desconto-suffix {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}

/* ---------- Resumo ---------- */
.summary { background: linear-gradient(180deg, #ffffff, #f8faff); }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 14px; color: var(--text-muted); }
.summary-row strong { color: var(--text); font-size: 15px; }
.summary-row.total { padding-top: 10px; margin-top: 6px; border-top: 1.5px dashed var(--border); }
.summary-row.total span { font-weight: 800; color: var(--text); font-size: 16px; }
.summary-row.total strong { font-size: 22px; font-weight: 800; color: var(--primary); }

/* ---------- Action bar ---------- */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(241,245,249,0), rgba(241,245,249,0.92) 30%, var(--bg) 55%);
  z-index: 15;
}
.btn-registrar {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  background: var(--gradient);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4);
  transition: transform 0.1s, opacity 0.15s;
}
.btn-registrar:active { transform: scale(0.98); }
.btn-registrar:disabled { opacity: 0.6; }

/* ---------- Banner de instalação ---------- */
.install-hint {
  position: sticky;
  top: calc(76px + env(safe-area-inset-top, 0px));
  margin: -4px auto 0;
  max-width: 532px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12.5px;
  line-height: 1.4;
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  z-index: 12;
}
.install-hint-text { flex: 1; }
.install-hint-text b { color: #fff; }
.install-hint-btn {
  background: var(--gradient);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}
.install-hint-btn:active { transform: scale(0.97); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

@media (min-width: 768px) {
  body { padding-bottom: 88px; }
  .app-header { padding: 20px 24px; }
  .header-inner, .app-main, .btn-registrar { max-width: 680px; }
}