:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-strong: #eef5ec;
  --ink: #17211c;
  --muted: #647067;
  --line: #dfe7df;
  --brand: #24745a;
  --brand-strong: #155b46;
  --brand-soft: #dcefe7;
  --amber: #c8831d;
  --amber-soft: #fff2d6;
  --coral: #c85b4b;
  --sky-soft: #e8f1f6;
  --red: #b64646;
  --blue: #326f9f;
  --shadow: 0 20px 60px rgba(27, 48, 39, 0.12);
  --shadow-soft: 0 10px 28px rgba(27, 48, 39, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(36, 116, 90, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(200, 131, 29, 0.12), transparent 30%),
    linear-gradient(180deg, rgba(50, 111, 159, 0.1), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(223, 231, 223, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  animation: enter 520ms ease both;
}

.login-logo {
  width: 74px;
  height: 74px;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
}

.login-card h1 {
  color: var(--ink);
  font-size: clamp(2rem, 9vw, 3.4rem);
}

.login-card input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: 0;
}

.login-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(36, 116, 90, 0.14);
}

.eyebrow.dark {
  margin-bottom: -4px;
  color: var(--muted);
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 700;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 40px);
}

.topbar {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(22px, 4vw, 44px);
  min-height: 242px;
  border-radius: var(--radius);
  background:
    linear-gradient(118deg, rgba(23, 33, 28, 0.98), rgba(23, 33, 28, 0.78) 56%, rgba(50, 111, 159, 0.64)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.1) 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 48px),
    #173128;
  color: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: enter 620ms ease both;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 8px;
  background: linear-gradient(90deg, var(--brand), var(--amber), var(--blue));
}

.topbar::after {
  content: "";
  position: absolute;
  right: clamp(18px, 8vw, 120px);
  bottom: -34px;
  width: min(420px, 48vw);
  height: 170px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 0 18%, rgba(255, 255, 255, 0.18) 18% 19%, transparent 19% 36%, rgba(255, 255, 255, 0.18) 36% 37%, transparent 37% 62%, rgba(255, 255, 255, 0.18) 62% 63%, transparent 63%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px 42px),
    rgba(255, 255, 255, 0.08);
  opacity: 0.7;
  transform: rotate(-4deg);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2vw, 22px);
}

.app-logo {
  width: clamp(58px, 8vw, 86px);
  height: clamp(58px, 8vw, 86px);
  border-radius: 18px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

.topbar > * {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.83rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.month-control {
  display: grid;
  gap: 8px;
  width: min(430px, 100%);
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(16px);
}

.month-control label {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.month-picker {
  display: grid;
  grid-template-columns: 38px minmax(116px, 1fr) minmax(88px, 0.72fr) 38px;
  gap: 8px;
}

.month-control input,
.month-control select,
.period-button {
  width: 100%;
  border: 0;
  color: var(--ink);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.month-control select {
  min-width: 0;
}

.period-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 0;
  color: var(--brand-strong);
  font-size: 1.5rem;
  font-weight: 800;
}

.month-control small {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: capitalize;
}

.storage-notice {
  display: flex;
  align-items: center;
  min-height: 46px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  box-shadow: var(--shadow-soft);
  font-size: 0.9rem;
  font-weight: 700;
  animation: enter 520ms ease both;
}

.storage-notice::before {
  content: "";
  display: inline-block;
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  margin-right: 10px;
  border-radius: 999px;
  background: var(--brand);
}

.storage-notice.is-warning {
  border-color: #f0c9c4;
  background: #fff3f1;
  color: #86382f;
}

.storage-notice.is-warning::before {
  background: var(--coral);
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.compact-button {
  width: auto;
  min-height: 38px;
  padding: 0 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 14px;
  margin-top: 14px;
}

.metric-card,
.data-card,
.control-panel,
.projection-card {
  border: 1px solid rgba(223, 231, 223, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
}

.metric-card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 142px;
  padding: 22px;
  animation: enter 620ms ease both;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.metric-card:hover,
.data-card:hover,
.projection-card:hover {
  box-shadow: var(--shadow);
}

.metric-card:hover {
  transform: translateY(-2px);
}

.metric-card:nth-child(2) {
  animation-delay: 70ms;
}

.metric-card:nth-child(3) {
  animation-delay: 140ms;
}

.metric-card:nth-child(4) {
  animation-delay: 210ms;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 5px;
  height: 100%;
  background: var(--brand);
}

.metric-card.balance-card::before {
  background: var(--blue);
}

.metric-card.free-card::before {
  background: var(--amber);
}

.metric-card.food-balance-card::before {
  background: var(--brand);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin: 18px 0 8px;
  max-width: 100%;
  font-size: clamp(1.24rem, 1.7vw, 2rem);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.metric-card small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

.control-panel,
.data-card,
.projection-card {
  padding: 18px;
}

.control-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 18px;
  animation: enter 620ms ease both;
}

.control-panel::before {
  content: "";
  height: 4px;
  margin: -18px -18px 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, var(--brand), var(--blue), var(--amber));
}

.data-card,
.projection-card {
  transition: box-shadow 180ms ease;
}

.planning-area {
  display: grid;
  gap: 16px;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin-bottom: 16px;
}

.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.field-group {
  display: grid;
  gap: 8px;
}

label,
.label-row {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.account-group {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #d8e7dc;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.account-group h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.2;
}

.account-group label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.person-icon,
.account-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
}

.person-icon {
  background: var(--brand-strong);
}

.nubank-icon {
  background: #7b2cbf;
}

.bb-icon {
  background: #e1ad01;
  color: #17211c;
}

.inter-icon {
  background: #f47b20;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quick-food {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #d8e7dc;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(36, 116, 90, 0.1), transparent),
    var(--surface-strong);
}

.quick-food-grid {
  display: grid;
  grid-template-columns: minmax(74px, 0.62fr) minmax(120px, 1fr);
  gap: 10px;
}

.quick-food > input,
.quick-food-grid > input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: 0;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.money-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 0 12px;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.money-input:focus-within,
.entry-row > input:focus,
.quick-food > input:focus,
.quick-food-grid > input:focus,
.month-control input:focus,
.month-control select:focus,
.period-button:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(36, 116, 90, 0.14);
  outline: 0;
}

.money-input span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.money-input input,
.entry-row > input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.money-input.compact {
  min-height: 42px;
}

.range {
  width: 100%;
  accent-color: var(--brand);
}

.ghost-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--brand-strong);
  font-weight: 800;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.primary-button {
  min-height: 44px;
  border: 1px solid var(--brand-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  color: #fff;
  font-weight: 800;
  transition: transform 180ms ease, filter 180ms ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.ghost-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.ghost-button:active,
.icon-button:active {
  transform: translateY(0);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  transition: transform 180ms ease, background 180ms ease;
}

.remove-button {
  background: #fff;
  color: var(--red);
}

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

.entry-row {
  display: grid;
  gap: 10px;
  align-items: center;
  animation: rowIn 220ms ease both;
}

.bill-row {
  grid-template-columns: minmax(120px, 1fr) minmax(130px, 0.7fr) 38px;
}

.food-row,
.food-head {
  grid-template-columns: minmax(130px, 1.4fr) minmax(96px, 0.62fr) minmax(130px, 0.82fr) 38px;
}

.food-head {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.entry-row > input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 0 12px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}

.total-row strong {
  color: var(--ink);
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 8px 0 2px;
}

.projection-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(64px, 1fr);
  align-items: end;
  gap: 10px;
  min-height: 190px;
}

.bar-item {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  min-width: 64px;
}

.bar {
  align-self: end;
  min-height: 6px;
  width: 100%;
  border: 0;
  padding: 0;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  transform-origin: bottom;
  animation: growBar 520ms ease both;
  transition: filter 180ms ease;
}

.bar:hover {
  filter: brightness(1.06);
}

.bar.negative {
  background: linear-gradient(180deg, #d56a5f, #9f3434);
}

.bar-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
}

.projection-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.projection-month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.projection-month > * {
  min-width: 0;
}

.projection-month:hover {
  border-color: #c9dccf;
  background: #f7fbf8;
  transform: translateY(-1px);
}

.projection-month span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.projection-month strong {
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  text-align: right;
}

.negative-text {
  color: var(--red);
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes growBar {
  from {
    transform: scaleY(0.05);
  }
  to {
    transform: scaleY(1);
  }
}

@media (max-width: 1120px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-panel .panel-header,
  .control-panel::before,
  .quick-food,
  .control-panel .ghost-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    min-height: 260px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .tables-grid,
  .control-panel,
  .projection-list {
    grid-template-columns: 1fr;
  }

  .bill-row {
    grid-template-columns: 1fr 1fr 38px;
  }

  .food-head {
    display: none;
  }

  .food-row {
    grid-template-columns: 1fr 1fr 38px;
  }

  .food-row .food-product {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .metric-card,
  .data-card,
  .control-panel,
  .projection-card {
    padding: 14px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .brand-lockup {
    display: grid;
  }

  .month-picker {
    grid-template-columns: 38px 1fr 38px;
  }

  .month-picker select {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
  }

  .month-picker input {
    grid-column: 1 / -1;
    grid-row: 2 / 3;
  }

  .month-picker #prevMonthButton {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
  }

  .month-picker #nextMonthButton {
    grid-column: 3 / 4;
    grid-row: 3 / 4;
  }

  .app-logo {
    width: 58px;
    height: 58px;
  }

  .quick-food-grid {
    grid-template-columns: 1fr;
  }

  .bill-row,
  .food-row {
    grid-template-columns: 1fr 38px;
  }

  .bill-row .entry-name,
  .food-row .food-product,
  .food-row .food-quantity,
  .food-row .money-input {
    grid-column: 1 / 2;
  }

  .bill-row .remove-button,
  .food-row .remove-button {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }
}
