:root {
  --paper: #f7f4ec;
  --ink: #20211d;
  --muted: #747166;
  --line: #dfdacd;
  --panel: #fffdf8;
  --green: #2f7d57;
  --red: #b75545;
  --gold: #c99735;
  --blue: #356f9f;
  --shadow: 0 22px 55px rgba(42, 36, 24, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(32, 33, 29, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(32, 33, 29, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 40px 40px;
  color: var(--ink);
  font-family: "Manrope", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: 34px 0 52px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 22px;
}

.brand-compact {
  display: grid;
  gap: 2px;
}

.brand-compact span {
  font-size: 1.28rem;
  font-weight: 900;
}

.brand-compact small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-family: "DM Serif Display", serif;
  font-size: clamp(2.7rem, 7vw, 5.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.18rem;
}

.hero-copy {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.add-button {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fffaf0;
  box-shadow: var(--shadow);
  font-size: 3.2rem;
  font-weight: 500;
  line-height: 1;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gear-button {
  width: 50px;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 1.25rem;
  line-height: 1;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.metric,
.panel,
.dialog-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 142px;
  padding: 20px;
}

.metric.dark {
  background: var(--ink);
  color: #fffaf0;
}

.metric span,
.metric small,
.muted {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric.dark span,
.metric.dark small {
  color: rgba(255, 250, 240, 0.72);
}

.metric strong {
  display: block;
  margin: 10px 0 9px;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
}

.progress-track {
  overflow: hidden;
  height: 10px;
  margin-top: 14px;
  border-radius: 999px;
  background: rgba(32, 33, 29, 0.1);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
  transition: width 200ms ease;
}

.panel {
  margin-top: 14px;
  padding: 20px;
}

.compact-panel {
  padding: 14px;
}

.goal-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.mini-card {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
  padding: 16px;
}

.mini-card span,
.mini-card small {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.mini-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 1.5rem;
}

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

.ghost-button,
.primary-button,
.danger-button,
.icon-button {
  min-height: 44px;
  border-radius: 6px;
  font-weight: 900;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
}

.edit-details-button {
  justify-self: start;
  min-height: 40px;
}

.edit-details-button.active {
  background: var(--surface-soft);
  color: var(--green-deep);
}

.details-panel {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.primary-button {
  border: 0;
  background: var(--green);
  color: #fff;
  padding: 0 18px;
}

.danger-button {
  border: 1px solid #ecd2cb;
  background: #fff6f3;
  color: var(--red);
  padding: 0 16px;
}

.icon-button {
  width: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.4rem;
}

.debt-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 20px;
  color: var(--muted);
  font-weight: 700;
}

.debt-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  color: inherit;
  text-align: left;
}

.debt-card:hover {
  border-color: rgba(47, 125, 87, 0.55);
}

.debt-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}

.type-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--blue);
}

.type-dot.cartao,
.type-dot.mercado {
  background: var(--gold);
}

.type-dot.financiamento {
  background: var(--blue);
}

.type-dot.energia-solar {
  background: var(--green);
}

.debt-title strong {
  display: block;
  font-size: 1.02rem;
}

.debt-title small,
.debt-meta,
.debt-status {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.debt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.debt-amount {
  text-align: right;
}

.debt-amount strong {
  display: block;
  font-size: 1.35rem;
}

.debt-amount .pay-button {
  margin-top: 10px;
}

.debt-status.good {
  color: var(--green);
}

.debt-status.bad {
  color: var(--red);
}

.amount-good {
  color: var(--green);
}

.amount-bad {
  color: var(--red);
}

.status-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.status-row span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  background: #eef3f7;
  color: var(--blue);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.status-pill.pago {
  background: #e7f4ec;
  color: var(--green);
}

.status-pill.fechado {
  background: #fff2d6;
  color: #926616;
}

.status-pill.vencido {
  background: #fff0eb;
  color: var(--red);
}

.status-pill.aberto {
  background: #eef3f7;
  color: var(--blue);
}

.pay-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  padding: 0 12px;
  font-weight: 900;
}

.inline-pay {
  min-height: 32px;
  font-size: 0.78rem;
}

.insight-panel {
  display: grid;
  gap: 16px;
}

.insights {
  display: grid;
  gap: 10px;
}

.insight {
  border-left: 4px solid var(--line);
  padding: 7px 0 7px 12px;
  color: var(--muted);
  font-weight: 800;
}

.insight.good {
  border-color: var(--green);
  color: var(--green);
}

.insight.bad {
  border-color: var(--red);
  color: var(--red);
}

.chart-panel {
  display: grid;
  gap: 16px;
}

.pie-wrap {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
}

.pie-chart {
  display: grid;
  place-items: center;
  width: 220px;
  aspect-ratio: 1;
  border-radius: 50%;
  position: relative;
}

.pie-chart::after {
  content: "";
  position: absolute;
  inset: 54px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
}

.pie-chart span {
  position: relative;
  z-index: 1;
  max-width: 112px;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 900;
}

.pie-legend {
  display: grid;
  gap: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-row small {
  color: var(--muted);
  font-weight: 900;
}

.chart-box {
  min-height: 178px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.chart-box.small {
  min-height: 152px;
}

.chart-box svg {
  display: block;
  width: 100%;
  height: 132px;
}

.chart-box circle {
  fill: var(--green);
}

.chart-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: rgba(47, 125, 87, 0.12);
  stroke: none;
}

.chart-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.chart-caption strong {
  color: var(--ink);
}

.empty-chart {
  display: grid;
  min-height: 120px;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.history-panel {
  display: grid;
  gap: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  font-size: 0.84rem;
}

.history-item span,
.history-item small {
  color: var(--muted);
  font-weight: 800;
}

.dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

.small-dialog {
  width: min(460px, calc(100% - 24px));
}

.dialog::backdrop {
  background: rgba(32, 33, 29, 0.42);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-actions.end {
  justify-content: flex-end;
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 87, 0.14);
}

input:disabled,
select:disabled {
  background: #f5f8f6;
  color: var(--muted);
  opacity: 1;
}


.checkbox-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

@media (max-width: 820px) {
  .topbar,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    gap: 8px;
    padding: 10px 0 12px;
  }

  .brand-compact span {
    font-size: 1.08rem;
  }

  .brand-compact small {
    display: none;
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 0.66rem;
  }

  h1 {
    max-width: 100%;
    margin-bottom: 6px;
    font-size: clamp(2.05rem, 12vw, 3.05rem);
    line-height: 0.95;
  }

  .hero-copy {
    max-width: 23rem;
    font-size: 0.9rem;
    line-height: 1.45;
  }

  .summary-grid,
  .mini-grid,
  .two-columns,
  .goal-form,
  .status-row,
  .pie-wrap {
    grid-template-columns: 1fr;
  }

  .pie-chart {
    width: min(220px, 100%);
  }

  .add-button {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 5;
    width: 64px;
    height: 64px;
    font-size: 2.7rem;
  }

  .debt-card {
    grid-template-columns: 1fr;
  }

  .debt-amount {
    text-align: left;
  }
}

/* Mobile-first usability refresh */
:root {
  --paper: #f3f7f4;
  --surface: #ffffff;
  --surface-soft: #eef6f1;
  --ink: #17231f;
  --muted: #65736d;
  --line: #d9e4dd;
  --panel: #ffffff;
  --green: #12805c;
  --green-deep: #0c5f46;
  --red: #d94f3d;
  --gold: #d89b22;
  --blue: #2775b8;
  --teal: #0f8f86;
  --shadow: 0 18px 45px rgba(27, 58, 47, 0.1);
  --shadow-soft: 0 8px 24px rgba(27, 58, 47, 0.07);
}

body {
  background:
    radial-gradient(circle at top left, rgba(18, 128, 92, 0.11), transparent 34rem),
    linear-gradient(180deg, #f8fbf8 0%, var(--paper) 42%, #eef5f1 100%);
  color: var(--ink);
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  padding: 18px 0 calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  align-items: flex-start;
  padding: 14px 0 16px;
  background: linear-gradient(180deg, rgba(248, 251, 248, 0.98), rgba(248, 251, 248, 0.78));
  backdrop-filter: blur(16px);
}

.eyebrow {
  color: var(--green);
  letter-spacing: 0.14em;
}

h1 {
  max-width: 8ch;
  font-size: clamp(2.55rem, 16vw, 5.4rem);
  line-height: 0.86;
}

.hero-copy {
  max-width: 34rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.top-actions {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 54px 68px;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(217, 228, 221, 0.84);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 42px rgba(18, 62, 47, 0.2);
  backdrop-filter: blur(18px);
}

.gear-button,
.add-button {
  position: static;
  box-shadow: none;
}

.gear-button {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--green-deep);
}

.add-button {
  width: 68px;
  height: 68px;
  background: linear-gradient(135deg, var(--green), var(--teal));
  color: #ffffff;
  font-size: 3rem;
}

.summary-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(272px, 86%);
  grid-template-columns: none;
  gap: 12px;
  overflow-x: auto;
  margin: 8px -14px 14px;
  padding: 0 14px 4px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.summary-grid::-webkit-scrollbar {
  display: none;
}

.metric,
.mini-card,
.panel,
.dialog-card,
.debt-card,
.legend-row,
.history-item,
.chart-box,
.status-row {
  border-color: rgba(217, 228, 221, 0.92);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.metric {
  min-height: 146px;
  scroll-snap-align: start;
}

.metric.dark {
  border-color: rgba(12, 95, 70, 0.35);
  background:
    linear-gradient(135deg, rgba(18, 128, 92, 0.98), rgba(15, 143, 134, 0.94)),
    var(--green);
  color: #ffffff;
}

.metric span,
.mini-card span,
.metric small,
.mini-card small {
  color: var(--muted);
}

.metric.dark span,
.metric.dark small {
  color: rgba(255, 255, 255, 0.78);
}

.metric strong {
  font-size: clamp(1.75rem, 8vw, 2.35rem);
}

.progress-track {
  height: 9px;
  background: rgba(18, 128, 92, 0.12);
}

.progress-fill {
  background: linear-gradient(90deg, var(--green), var(--teal), var(--gold));
}

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

.mini-card {
  min-height: 102px;
  padding: 14px;
}

.mini-card strong {
  font-size: 1.35rem;
}

.panel {
  margin-top: 12px;
  padding: 16px;
}

.panel-heading {
  margin-bottom: 14px;
}

.ghost-button {
  background: var(--surface-soft);
  color: var(--green-deep);
}

.debt-list {
  gap: 12px;
}

.debt-card {
  grid-template-columns: 1fr;
  padding: 14px;
  border-left: 5px solid var(--green);
}

.debt-card:focus-visible,
.gear-button:focus-visible,
.add-button:focus-visible,
.primary-button:focus-visible,
.pay-button:focus-visible {
  outline: 3px solid rgba(18, 128, 92, 0.24);
  outline-offset: 3px;
}

.debt-title {
  align-items: flex-start;
}

.type-dot {
  width: 13px;
  height: 13px;
  margin-top: 4px;
  background: var(--teal);
}

.debt-title strong {
  font-size: 1.08rem;
}

.debt-title small,
.debt-meta,
.debt-status {
  line-height: 1.45;
}

.debt-amount {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  text-align: left;
}

.debt-amount strong {
  font-size: 1.5rem;
}

.inline-pay {
  min-height: 40px;
  padding: 0 16px;
}

.status-pill {
  min-height: 30px;
  padding: 5px 11px;
}

.pay-button,
.primary-button {
  background: linear-gradient(135deg, var(--green), var(--teal));
}

.chart-panel {
  overflow: hidden;
}

.pie-wrap {
  grid-template-columns: 1fr;
  justify-items: center;
}

.pie-chart {
  width: min(240px, 76vw);
  box-shadow: inset 0 0 0 1px rgba(23, 35, 31, 0.06);
}

.pie-chart::after {
  inset: 28%;
}

.pie-legend {
  width: 100%;
}

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

.legend-row small {
  grid-column: 2;
}

.chart-box {
  padding: 12px;
}

.insight {
  border-left-color: var(--green);
  color: var(--ink);
}

input,
select {
  min-height: 50px;
  border-color: var(--line);
  background: #ffffff;
}

.dialog {
  width: min(560px, calc(100% - 18px));
}

.dialog-card {
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 18px;
}

@media (min-width: 821px) {
  .app-shell {
    padding: 34px 0 54px;
  }

  .topbar {
    position: static;
    background: transparent;
    backdrop-filter: none;
  }

  h1 {
    max-width: 760px;
  }

  .top-actions {
    position: static;
    display: flex;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .summary-grid {
    grid-auto-flow: initial;
    grid-auto-columns: initial;
    grid-template-columns: 1.35fr 1fr 1fr;
    overflow: visible;
    margin: 12px 0 14px;
    padding: 0;
  }

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

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

  .debt-amount {
    display: block;
    text-align: right;
  }

  .pie-wrap {
    grid-template-columns: 240px minmax(0, 1fr);
    justify-items: stretch;
  }

  .legend-row {
    grid-template-columns: auto 1fr auto;
  }

  .legend-row small {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 8px;
  }

  .summary-grid {
    grid-auto-columns: minmax(252px, 84%);
    margin-left: -10px;
    margin-right: -10px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .metric {
    min-height: 132px;
    padding: 16px;
  }

  .metric strong {
    font-size: clamp(1.55rem, 8vw, 2rem);
  }

  .panel {
    padding: 14px;
  }

  .dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 18px);
    margin: auto 0 0;
    padding: 0 10px 10px;
  }

  .dialog::backdrop {
    background: rgba(23, 35, 31, 0.48);
  }

  .dialog-card {
    max-height: calc(100dvh - 34px);
    border-radius: 18px 18px 10px 10px;
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .dialog-heading {
    position: sticky;
    top: -14px;
    z-index: 2;
    margin: -14px -14px 2px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .dialog-heading h2 {
    max-width: 15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.08rem;
  }

  .icon-button {
    width: 42px;
    min-height: 42px;
  }

  .status-row {
    gap: 9px;
    padding: 10px;
  }

  .history-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .dialog-actions {
    position: sticky;
    bottom: -14px;
    margin: 2px -14px -14px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .dialog-actions .primary-button,
  .dialog-actions .danger-button {
    min-height: 46px;
  }
}
