:root {
  --orange: #d35400;
  --orange-dark: #a84300;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --gray: #64748b;
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #dbe3ef;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: #111827;
}

button, input, textarea {
  font: inherit;
}

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

.login-card, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

.login-card {
  width: min(420px, 100%);
  padding: 22px;
}

.brand {
  margin: 0 0 6px;
  color: var(--orange-dark);
  font-size: 24px;
  font-weight: 800;
}

.muted {
  color: var(--gray);
  font-size: 13px;
}

.field {
  width: 100%;
  min-height: 46px;
  border: 1px solid #9aa8ba;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: #111827;
  outline: none;
}

.field::placeholder {
  color: #53657d;
  opacity: 1;
}

.field:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(211, 84, 0, .12);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--orange);
  color: #fff;
  font-weight: 800;
}

.btn.blue {
  background: var(--blue);
}

.btn.green {
  background: var(--green);
}

.btn.red {
  background: var(--red);
}

.btn.gray {
  background: var(--gray);
}

.btn.block {
  width: 100%;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--orange);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
}

.top h1 {
  margin: 0;
  font-size: 18px;
}

.top .muted {
  color: rgba(255, 255, 255, .88);
}

.tabs {
  position: sticky;
  top: 65px;
  z-index: 18;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  background: #eef4fb;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 0 0 auto;
  padding: 10px 13px;
  border: 1px solid #c7d3e2;
  border-radius: 999px;
  background: #fff;
  color: var(--orange-dark);
  font-weight: 800;
}

.tab.active {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}

.page {
  padding: 12px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

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

.stats {
  grid-template-columns: repeat(2, 1fr);
}

.card {
  padding: 14px;
}

.label {
  color: #52627a;
  font-size: 13px;
  font-weight: 700;
}

.value {
  margin-top: 6px;
  color: var(--green);
  font-size: 22px;
  font-weight: 900;
}

.value.red {
  color: var(--red);
}

.value.blue {
  color: var(--blue);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row > * {
  min-width: 0;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

button.item,
button.finance-row {
  width: 100%;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}

.editable-item {
  cursor: pointer;
}

.item-title {
  font-weight: 850;
}

.item-sub {
  margin-top: 4px;
  color: #4b5f79;
  font-size: 13px;
}

.cart-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.suggest {
  border: 1px solid #f59e0b;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 6px;
  background: #fff;
}

.suggest button {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #edf1f7;
  padding: 10px;
  background: #fff;
  color: #111827;
}

.suggest button:last-child {
  border-bottom: 0;
}

.paybox {
  position: sticky;
  bottom: 0;
  margin: 12px -12px calc(-80px - env(safe-area-inset-bottom));
  padding: 12px;
  background: #eef4fb;
  border-top: 1px solid var(--line);
}

.pay-title {
  color: var(--orange-dark);
  font-size: 16px;
  font-weight: 900;
  margin-bottom: 10px;
}

.pay-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
}

.pay-line.strong {
  font-weight: 900;
}

.pay-line.strong strong {
  color: var(--blue);
  font-size: 18px;
}

.pay-input {
  width: 138px;
  min-height: 38px;
  padding: 8px 10px;
  text-align: right;
}

.pay-suggest {
  margin: 8px 0;
  padding: 8px;
  border-radius: 10px;
  background: #e2e8f0;
}

.pay-radio {
  min-height: 38px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  color: #111827;
}

.pay-radio input {
  width: 20px;
  height: 20px;
}

.calendar-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

.calendar-nav {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  align-items: center;
  text-align: center;
}

.calendar-title {
  color: var(--orange-dark);
  font-size: 19px;
  font-weight: 900;
}

.calendar-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.calendar-week div {
  padding: 7px 2px;
  border-radius: 8px;
  background: var(--orange);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-top: 5px;
}

.calendar-day {
  min-height: 64px;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  padding: 6px 4px;
  background: #fff;
  color: #111827;
  text-align: left;
  overflow: hidden;
}

.calendar-day.empty {
  background: transparent;
  border-color: transparent;
}

.calendar-day.has-task {
  background: #e5e7eb;
  border-color: #cbd5e1;
  color: #0f172a;
  font-weight: 900;
}

.calendar-day.has-finance:not(.selected) {
  background: #f8fafc;
}

.calendar-day.selected {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.calendar-day.today:not(.selected) {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.day-number {
  display: block;
  font-size: 16px;
  font-weight: 900;
}

.lunar-date {
  display: block;
  margin-top: 1px;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
}

.calendar-day.selected .lunar-date {
  color: rgba(255, 255, 255, .9);
}

.day-info {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 800;
}

.cell-money {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.05;
  font-weight: 900;
  white-space: nowrap;
}

.cell-money.income {
  color: #0ea5e9;
}

.cell-money.expense {
  color: #ea580c;
}

.calendar-day.selected .cell-money {
  color: #fff;
}

.day-note {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-item.done {
  opacity: .72;
}

.task-item.done .item-title {
  text-decoration: line-through;
}

.task-form-card {
  margin-top: 10px;
}

.selected-day-panel {
  scroll-margin-top: 150px;
}

.day-section-card {
  margin-top: 10px;
}

.day-profit-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: #374151;
  font-weight: 900;
}

.day-profit-line strong {
  font-size: 20px;
}

.task-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.finance-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
  padding: 12px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.finance-summary span {
  display: block;
  color: #4b5563;
  font-size: 13px;
  font-weight: 900;
}

.finance-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
  line-height: 1.1;
}

.finance-income {
  color: #0ea5e9;
}

.finance-expense {
  color: #ea580c;
}

.finance-list {
  margin-top: 10px;
  padding: 0;
  overflow: hidden;
}

.finance-day-section {
  scroll-margin-top: 150px;
}

.finance-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #f1f5f9;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: #374151;
  font-weight: 900;
}

.finance-day-section:first-child .finance-day-header {
  border-top: 0;
}

.finance-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid #edf1f7;
  background: #fff;
}

.check-line {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #374151;
  font-weight: 800;
}

.check-line input {
  width: 20px;
  height: 20px;
}

.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(15, 23, 42, .55);
}

.editor-card {
  width: min(620px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--orange-dark);
  font-size: 18px;
}

.finance-row.income strong {
  color: #0ea5e9;
}

.finance-row.expense strong {
  color: #475569;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, .72);
}

.scanner-card {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

#scannerVideo {
  width: 100%;
  margin: 12px 0 8px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
  background: #0f172a;
}

.pill-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0;
}

.pill {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid #c7d3e2;
  background: #fff;
}

.error {
  color: var(--red);
  font-weight: 700;
  margin-top: 10px;
}

.notice {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  background: #fff7ed;
  color: #9a3412;
  font-weight: 700;
  line-height: 1.35;
}

@media (min-width: 720px) {
  .page {
    max-width: 900px;
    margin: 0 auto;
  }

  .task-form {
    grid-template-columns: repeat(2, 1fr);
  }
}
