:root {
  color-scheme: light;
  --bg: #f7f7fb;
  --card: #ffffff;
  --text: #17181c;
  --muted: #5b606b;
  --border: #e6e7ee;
  --primary: #2563eb;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 32px rgba(0, 0, 0, 0.06);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
  background: rgba(247, 247, 251, 0.82);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
}

.header__title p {
  margin: 6px 0 0;
}

.muted {
  color: var(--muted);
}

.auth {
  max-width: 520px;
  margin: 0 auto;
}

.alert {
  border: 1px solid rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.06);
  color: #991b1b;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.main {
  padding: 20px 0 48px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card__title {
  font-size: 16px;
  margin-bottom: 12px;
}

.controls {
  display: grid;
  gap: 16px;
  grid-template-columns: 220px 260px 1fr;
  align-items: end;
}

.grid {
  display: grid;
  gap: 24px;
  grid-template-columns: 400px 1fr;
}

.grid > * {
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  outline: none;
  background: #fff;
}

input:focus,
select:focus {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
  align-items: stretch;
}

.summary__item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

.summary__label {
  font-size: 12px;
  color: var(--muted);
}

.summary__value {
  margin-top: 6px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.form {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.field--span2 {
  grid-column: span 2;
}

.form__actions {
  grid-column: span 2;
  display: flex;
  justify-content: flex-end;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.weekdays {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  user-select: none;
}

.checkbox input {
  width: 16px;
  height: 16px;
}

.btn {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  border-color: rgba(37, 99, 235, 0.3);
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-weight: 600;
}

.btn--ghost {
  background: transparent;
}

.btn--danger {
  border-color: rgba(220, 38, 38, 0.3);
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  font-weight: 600;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  background: #fff;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 10px;
  text-align: left;
  vertical-align: top;
}

.table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.table--dense th,
.table--dense td {
  padding: 8px 10px;
}

.table tbody tr:hover td {
  background: rgba(37, 99, 235, 0.04);
}

.right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.pill--income {
  border-color: rgba(22, 163, 74, 0.3);
  background: rgba(22, 163, 74, 0.08);
  color: #166534;
}

.pill--expense {
  border-color: rgba(220, 38, 38, 0.3);
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
}

.empty {
  padding: 10px 6px 0;
  font-size: 13px;
}

.pager {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pager__info {
  flex: 1;
  text-align: center;
  font-size: 13px;
}

.pager__size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.pager__label {
  font-size: 13px;
}

.pager select {
  height: 34px;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.25);
}

.dialog__inner {
  padding: 16px;
  min-width: min(480px, calc(100vw - 32px));
}

.dialog__title {
  font-size: 16px;
}

.dialog__message {
  margin: 10px 0 0;
  color: var(--muted);
}

.dialog__actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog__grid {
  margin-top: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.btn-row {
  display: inline-flex;
  gap: 8px;
  justify-content: flex-end;
}

.calendar {
  display: grid;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  min-width: 700px;
}

.calendar__weekday {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  min-width: 700px;
}

.cal-cell {
  min-height: 106px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 8px;
  align-content: start;
}

.cal-cell--empty {
  background: transparent;
  border-style: dashed;
  opacity: 0.45;
}

.cal-cell--weekend {
  background: rgba(37, 99, 235, 0.03);
}

.cal-cell--today {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.cal-day__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.cal-day__num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cal-day__w {
  font-size: 12px;
  color: var(--muted);
}

.cal-day__lines {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.cal-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}

.cal-line__label {
  color: var(--muted);
}

.cal-line__value {
  text-align: right;
}

.cal-line--income .cal-line__value {
  color: #166534;
}

.cal-line--expense .cal-line__value {
  color: #991b1b;
}

.cal-line--balance .cal-line__value {
  font-weight: 650;
  color: var(--text);
}

.cal-day__details {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .dialog__grid {
    grid-template-columns: 1fr;
  }
}

.dialog__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.btn--icon {
  padding: 0;
  width: 28px;
  height: 28px;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-list-wrap {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.day-add-form {
  display: grid;
  grid-template-columns: 80px 100px 1fr 60px;
  gap: 8px;
}

.compact-input {
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
}

.btn--compact {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

@media (max-width: 600px) {
  .day-add-form {
    grid-template-columns: 80px 1fr;
  }
  .day-add-form button {
    grid-column: span 2;
  }
}
