/*
 * Budget Mini App — household money picture (Phase 10).
 *
 * Mobile-first. Colours come from Telegram's themeParams; the fallbacks below
 * keep a sensible light theme in a normal browser. script.js mirrors
 * themeParams onto documentElement so themeChanged updates apply immediately.
 */

:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #1a1a1a;
  --tg-theme-hint-color: #707579;
  --tg-theme-link-color: #2481cc;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f1f1f4;
  --tg-theme-section-bg-color: #ffffff;
  --tg-theme-section-separator-color: #e6e6e8;
  --tg-theme-destructive-text-color: #d1453b;
  /* Money in / out. Not Telegram theme vars — a ledger needs its own two,
     muted enough to read in both themes. */
  --money-in: #1f8a4c;
  --money-out: #d1453b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: var(--tg-viewport-stable-height, 100vh);
  background-color: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: calc(16px + env(safe-area-inset-top)) 16px
    calc(16px + env(safe-area-inset-bottom));
}

.app {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#state-ready {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app__header {
  padding: 4px 2px;
}

.app__title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app__identity {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--tg-theme-hint-color);
}

.card {
  background-color: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-theme-section-separator-color);
  border-radius: 12px;
  padding: 16px;
}

.card__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.section__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.pill {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

.muted {
  margin: 0;
  color: var(--tg-theme-hint-color);
}

/* buttons */
.button {
  appearance: none;
  border: 1px solid var(--tg-theme-button-color);
  background-color: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
}

.button--secondary {
  background-color: transparent;
  color: var(--tg-theme-link-color);
  border-color: var(--tg-theme-section-separator-color);
  font-weight: 500;
}

.button--small {
  padding: 5px 12px;
  font-size: 14px;
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.button:active:not(:disabled) {
  opacity: 0.85;
}

/* funds */
.funds__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.funds__label {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.funds__value {
  margin: 6px 0 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.funds__value--negative {
  color: var(--tg-theme-destructive-text-color);
}

.funds__meta {
  margin: 2px 0 0;
  font-size: 13px;
}

.funds__form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.funds__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--tg-theme-section-separator-color);
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 17px;
  padding: 8px 10px;
}

.summary {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--tg-theme-section-separator-color);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-size: 14px;
}

.summary dt {
  color: var(--tg-theme-hint-color);
}

.summary dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* lists */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--tg-theme-section-separator-color);
}

.list .row:first-child {
  border-top: none;
}

.row__body {
  flex: 1 1 auto;
  min-width: 0;
}

.row__title {
  display: block;
  overflow-wrap: anywhere;
}

.row__meta {
  display: block;
  font-size: 13px;
  color: var(--tg-theme-hint-color);
}

.row__amount {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.row__amount--in {
  color: var(--money-in);
}

.row__amount--out {
  color: var(--money-out);
}

.row--paused .row__title {
  text-decoration: line-through;
  color: var(--tg-theme-hint-color);
}

.row__remove {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--tg-theme-hint-color);
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.row__remove:hover,
.row__remove:active {
  color: var(--tg-theme-destructive-text-color);
}

.row__toggle {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--tg-theme-link-color);
  background: none;
  border: none;
  padding: 2px 0;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

.empty {
  margin: 8px 0 0;
  padding: 2px;
}

/* add row */
.add {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--tg-theme-section-separator-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.add__row {
  display: flex;
  gap: 8px;
}

.add__name {
  width: 100%;
}

.add__date {
  flex: 0 0 auto;
  width: 140px;
}

.add__date,
.add__name,
.add__amount,
.add__day {
  border: 1px solid var(--tg-theme-section-separator-color);
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 15px;
  padding: 8px 10px;
}

#txn-form .add__row {
  flex-wrap: wrap;
}

#txn-form .add__name {
  flex: 1 1 120px;
  width: auto;
}

#txn-form .add__amount {
  flex: 0 1 110px;
}

.add__amount {
  flex: 1 1 auto;
  min-width: 0;
}

.add__day {
  flex: 0 0 66px;
}

.add__submit {
  flex: 0 0 auto;
}

.add__name::placeholder,
.add__amount::placeholder {
  color: var(--tg-theme-hint-color);
}

.add__name:focus,
.add__amount:focus,
.add__day:focus,
.add__date:focus,
.funds__input:focus {
  outline: none;
  border-color: var(--tg-theme-button-color);
}

.add__hint {
  font-size: 12px;
}

/* import */
.import {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 6px;
}

.import__file {
  /* The <label> is the button; the input is present but not shown. */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.import__toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  background-color: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-hint-color);
}

.notice[data-kind="error"] {
  color: var(--tg-theme-destructive-text-color);
}

.noscript {
  max-width: 480px;
  margin: 24px auto;
  padding: 0 16px;
  color: #707579;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tg-theme-bg-color: #17212b;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #7d8b99;
    --tg-theme-link-color: #5aa7e0;
    --tg-theme-button-color: #5aa7e0;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #232e3c;
    --tg-theme-section-bg-color: #232e3c;
    --tg-theme-section-separator-color: #2c3a47;
    --tg-theme-destructive-text-color: #ff6259;
    --money-in: #5fd08a;
    --money-out: #ff6259;
  }
}
