:root {
  --bg: #e8f0ec;
  --bg-deep: #0b3d2e;
  --surface: #f7fbf8;
  --ink: #12241c;
  --muted: #5a7266;
  --line: rgba(11, 61, 46, 0.12);
  --accent: #1f8a5b;
  --accent-deep: #0f5c3d;
  --danger: #c23b3b;
  --profit: #0f7a4a;
  --loss: #b83232;
  --shadow: 0 12px 40px rgba(11, 61, 46, 0.14);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Noto Sans SC", "Outfit", system-ui, sans-serif;
  color: var(--ink);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 100% -10%, #b8e0cb 0%, transparent 55%),
    radial-gradient(90% 60% at -20% 20%, #c9ddd4 0%, transparent 50%),
    linear-gradient(180deg, #dceae3 0%, var(--bg) 40%, #d5e4db 100%);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

button {
  margin: 0;
  color: inherit;
  background: none;
  border: none;
  border-radius: 0;
}

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 20px 16px calc(100px + var(--safe-bottom));
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(145deg, #2eb87a 0%, var(--bg-deep) 100%);
  box-shadow: 0 8px 20px rgba(11, 61, 46, 0.28);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 12px 10px 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 4px;
  border-right: none;
  border-bottom: none;
  transform: rotate(-18deg);
}

.brand h1 {
  margin: 0;
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  max-width: 12em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.btn-icon {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(247, 251, 248, 0.8);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.btn-icon:active {
  transform: scale(0.96);
}

.summary {
  background: linear-gradient(160deg, var(--bg-deep) 0%, #14523d 55%, #1a6b4d 100%);
  color: #f3faf6;
  border-radius: 24px;
  padding: 20px 18px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}

.summary::before {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -40px;
  top: -60px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.16), transparent 70%);
  pointer-events: none;
}

.summary-main .label,
.summary-grid .label {
  display: block;
  opacity: 0.72;
  font-size: 0.75rem;
  margin-bottom: 4px;
}

.summary-main strong {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.summary-main strong.neg {
  color: #ffb4b4;
}

.summary-formula {
  margin: 6px 0 0;
  font-size: 0.75rem;
  opacity: 0.65;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.summary-grid strong {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 0.98rem;
  font-weight: 600;
}

.period-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.period-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(247, 251, 248, 0.7);
  border: 1px solid var(--line);
}

.period-modes .mode {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.period-modes .mode.active {
  background: #fff;
  color: var(--bg-deep);
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(11, 61, 46, 0.08);
}

.period-nav {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
}

.period-nav.compact {
  margin-bottom: 14px;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(247, 251, 248, 0.85);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.period-label {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.period-today {
  align-self: center;
}

.list-wrap {
  background: #f7fbf8;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px;
  overflow: hidden;
}

.list-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  margin: 0 0 12px;
  border-radius: 14px;
  background: rgba(11, 61, 46, 0.08);
  width: 100%;
  box-sizing: border-box;
}

.list-tab {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  margin: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  padding: 10px 8px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.list-tab .tab-count {
  font-style: normal;
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: inherit;
  opacity: 0.7;
}

.list-tab.active {
  background: #fff;
  color: var(--bg-deep);
  box-shadow: 0 2px 10px rgba(11, 61, 46, 0.12);
}

.list-tab.active .tab-count {
  color: var(--accent);
  opacity: 1;
}

.status-row {
  display: block;
  margin: 0 0 12px;
  min-height: 0;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.status-chips[hidden],
.status-hint[hidden] {
  display: none !important;
}

.status-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.status-row .chip {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.status-row .chip.active {
  background: rgba(31, 138, 91, 0.12);
  border-color: rgba(31, 138, 91, 0.28);
  color: var(--accent-deep);
  font-weight: 600;
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 10px;
}

.list-head h2 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
}

.list-head span {
  font-size: 0.75rem;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.field > span em {
  font-style: normal;
  color: var(--accent);
  margin-left: 2px;
}

.field > span small {
  color: #8aa094;
  font-weight: 400;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 138, 91, 0.18);
}

.btn-ghost {
  height: 36px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(247, 251, 248, 0.75);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.order-list[hidden],
.promo-list-main[hidden] {
  display: none !important;
}

.order-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid transparent;
}

.order-item .row-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  cursor: pointer;
}

.order-item .row-main:active {
  opacity: 0.85;
}

.order-item .meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.order-item .title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.order-item .title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.4;
}

.badge.ongoing {
  color: #9a6700;
  background: #fff4d6;
}

.badge.done {
  color: var(--profit);
  background: #dff3e8;
}

.order-item .sub {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.order-item .money {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.order-item .profit {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.order-item .profit.pos {
  color: var(--profit);
}

.order-item .profit.neg {
  color: var(--loss);
}

.order-item .price-line {
  font-size: 0.72rem;
  color: var(--muted);
}

.item-actions {
  display: flex;
  gap: 8px;
}

.item-actions button {
  flex: 1;
  border: 1px solid var(--line);
  background: #f3f8f5;
  color: var(--ink);
  border-radius: 12px;
  padding: 9px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.item-actions button.accent {
  background: #e5f5ec;
  border-color: rgba(31, 138, 91, 0.25);
  color: var(--accent-deep);
}

.item-actions button:active {
  transform: scale(0.98);
}

.empty {
  text-align: center;
  padding: 36px 16px 42px;
  color: var(--muted);
  font-size: 0.9rem;
}

.fab-group {
  position: fixed;
  right: max(18px, calc(50% - 220px));
  bottom: calc(22px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
}

.fab {
  -webkit-appearance: none;
  appearance: none;
  height: 52px;
  min-width: 52px;
  padding: 0 18px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(160deg, #2eb87a, var(--bg-deep));
  color: #fff;
  box-shadow: 0 14px 30px rgba(11, 61, 46, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.fab-text {
  font-size: 0.9rem;
}

.fab:active {
  transform: scale(0.95);
}

.promo-list-main {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.promo-list-main[hidden] {
  display: none !important;
}

.promo-main-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
}

.promo-main-item .amount {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.promo-main-item .meta-line {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.promo-main-item .chevron {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--accent-deep);
  font-weight: 600;
}

.month-picker {
  padding-bottom: 8px;
}

.month-picker .period-nav {
  justify-items: center;
}

.month-picker .period-nav strong {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 1.1rem;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.month-cell {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 16px 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.month-cell.current {
  border-color: rgba(31, 138, 91, 0.35);
  color: var(--accent-deep);
}

.month-cell.active {
  background: linear-gradient(160deg, #249968, var(--accent-deep));
  border-color: transparent;
  color: #fff;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 28, 20, 0.45);
  backdrop-filter: blur(3px);
  z-index: 30;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 110%);
  width: min(480px, 100%);
  max-height: min(92dvh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(22px + var(--safe-bottom));
  z-index: 40;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet.open {
  transform: translate(-50%, 0);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: rgba(11, 61, 46, 0.18);
  margin: 4px auto 12px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.profit-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, #dff3e8, #eef8f2);
  border: 1px solid rgba(31, 138, 91, 0.2);
}

.profit-preview span {
  color: var(--muted);
  font-size: 0.86rem;
}

.profit-preview strong {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-size: 1.35rem;
  color: var(--profit);
}

.profit-preview strong.neg {
  color: var(--loss);
}

.form-tip {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eef6f1;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.btn-primary,
.btn-danger,
.btn-ghost-block {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(160deg, #249968, var(--accent-deep));
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 92, 61, 0.28);
}

.btn-danger {
  background: #f8e8e8;
  color: var(--danger);
  flex: 0.7;
}

.btn-ghost-block {
  background: #eef3f0;
  color: var(--muted);
  width: 100%;
  flex: 1 1 100%;
}

.btn-primary:active,
.btn-danger:active,
.btn-ghost-block:active {
  transform: scale(0.98);
}

.mini-card {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--muted);
}

.mini-card strong {
  display: block;
  color: var(--ink);
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.section-label {
  margin: 4px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}

.promo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.promo-list:empty::after {
  content: "还没有花费，可随时补记";
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 16px 8px;
  background: #eef3f0;
  border-radius: 12px;
}

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

.promo-item .info {
  min-width: 0;
}

.promo-item .amount {
  font-family: Outfit, "Noto Sans SC", sans-serif;
  font-weight: 700;
  color: var(--ink);
}

.promo-item .meta-line {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.promo-item .btn-remove {
  border: none;
  background: #f8e8e8;
  color: var(--danger);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.promo-add {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}

body.sheet-open {
  overflow: hidden;
}

@media (min-width: 520px) {
  .app {
    padding-top: 28px;
  }
}
