:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-strong: #f1f8f5;
  --ink: #202321;
  --muted: #68716d;
  --line: #dce2dd;
  --accent: #1f7a5d;
  --accent-dark: #14533f;
  --blue: #2766a4;
  --danger: #b43d3d;
  --shadow: 0 18px 45px rgba(36, 47, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Segoe UI",
    "Noto Sans KR",
    system-ui,
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 44px);
}

h2 {
  font-size: 18px;
}

.month-control {
  display: inline-grid;
  grid-template-columns: 40px minmax(178px, auto) 40px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.month-selects {
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 6px;
}

.month-selects select {
  min-height: 40px;
  padding: 8px 10px;
  font-weight: 800;
  text-align: center;
}

.icon-button,
.ghost-button,
.primary-button,
.action-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
}

.icon-button {
  width: 40px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  font-size: 26px;
  line-height: 1;
}

.tabbar {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tab-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 8px 18px;
}

.tab-button.active {
  background: var(--surface-strong);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-panel,
.entry-form,
.ledger-panel,
.calendar-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-panel {
  min-height: 112px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-top: 4px solid var(--accent);
}

.summary-panel:nth-child(2) {
  border-top-color: var(--blue);
}

.summary-panel:nth-child(3) {
  border-top-color: #9f6235;
}

.summary-panel.compact {
  border-top-color: #7a4e8f;
}

.subscription-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-panel span,
label,
legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-panel strong {
  font-size: clamp(21px, 3vw, 30px);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.entry-form,
.ledger-panel,
.calendar-panel {
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.entry-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 93, 0.15);
}

textarea {
  resize: vertical;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 7px;
}

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

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

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  border-color: var(--accent);
  background: var(--surface-strong);
  color: var(--accent-dark);
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 10px 14px;
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
  padding: 7px 10px;
}

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

.tools select {
  min-width: 108px;
  padding: 8px 10px;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

#subscriptionsTab table {
  min-width: 640px;
}

.schedule-table {
  min-width: 540px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

td.amount {
  text-align: right;
  font-weight: 800;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pill.income {
  background: #e8f4ec;
  color: #1c6b3b;
}

.pill.expense {
  background: #f6ece9;
  color: #9b3e2f;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.action-button {
  min-width: 38px;
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}

.action-button.delete {
  color: var(--danger);
}

.empty-state {
  padding: 38px 12px;
  color: var(--muted);
  text-align: center;
}

.calendar-panel {
  min-width: 0;
}

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

.weekday-cell {
  color: #a0a7ac;
  font-weight: 800;
  text-align: center;
  padding: 6px 4px;
}

.calendar-day {
  min-height: 104px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.calendar-day.muted {
  opacity: 0.35;
}

.calendar-day.today {
  background: #f4f6f8;
}

.calendar-date {
  color: #4d5359;
  font-size: clamp(18px, 2.4vw, 26px);
  font-weight: 800;
  line-height: 1;
  text-align: left;
}

.calendar-money {
  display: grid;
  gap: 2px;
  margin-top: 8px;
  min-height: 34px;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.calendar-income {
  color: #2f78c4;
}

.calendar-expense {
  color: #d35b63;
}

.calendar-schedules {
  display: grid;
  gap: 3px;
  margin-top: 6px;
}

.calendar-schedule {
  overflow: hidden;
  padding: 3px 5px;
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-schedule.subscription {
  background: #f6ece9;
  color: #9b3e2f;
}

.calendar-layout {
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
  margin-bottom: 18px;
}

.calendar-schedule-list {
  margin-top: 18px;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .month-control,
  .layout {
    width: 100%;
  }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .summary-grid,
  .subscription-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

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

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .tools {
    width: 100%;
  }

  .calendar-grid {
    gap: 6px;
  }

  .weekday-cell {
    font-size: 12px;
  }

  .calendar-day {
    min-height: 96px;
    padding: 7px;
  }

  .calendar-date {
    font-size: 18px;
  }

  .calendar-money {
    font-size: 11px;
    margin-top: 7px;
    text-align: left;
  }
}
