:root {
  color-scheme: light dark;
  --background: #f2f2f7;
  --card: #ffffff;
  --soft-card: #f7f7fb;
  --text: #111111;
  --secondary: #7d7d85;
  --separator: #e2e2e7;
  --segmented: #e7e7ec;
  --field: #fafafd;
  --tabbar: rgb(250 250 252 / 0.92);
  --tab-active: #111111;
  --tab-active-text: #ffffff;
  --control-surface: #ffffff;
  --pending-bg: rgb(10 132 255 / 0.08);
  --blue: #0a84ff;
  --orange: #c06b00;
  --orange-bg: #fff8ee;
  --danger: #d70015;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Apple SD Gothic Neo",
    "Noto Sans KR", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111216;
    --card: #1c1d22;
    --soft-card: #202127;
    --text: #f4f4f6;
    --secondary: #9b9ca5;
    --separator: #33343b;
    --segmented: #2a2b31;
    --field: #18191e;
    --tabbar: rgb(24 25 30 / 0.92);
    --tab-active: #0a84ff;
    --tab-active-text: #ffffff;
    --control-surface: #25262d;
    --pending-bg: rgb(10 132 255 / 0.14);
    --blue: #0a84ff;
    --orange: #ff9f0a;
    --orange-bg: #2a2118;
    --danger: #ff453a;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text);
}

body {
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

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

button {
  border: 0;
}

.app-shell {
  width: min(780px, 100%);
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

h1 {
  margin: 12px 0 18px;
  font-size: clamp(34px, 9vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 10px;
  font-size: 17px;
  letter-spacing: 0;
}

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

.title-row h1 {
  flex: 1;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--control-surface);
  color: var(--blue);
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.05);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
  min-height: 40px;
  margin-bottom: 14px;
  padding: 3px;
  border-radius: 999px;
  background: var(--segmented);
}

.segmented button {
  min-width: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}

.segmented button.active,
.segmented button[aria-selected="true"] {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.07);
}

.section-block {
  margin: 14px 0 16px;
}

.pending-section {
  margin: 0 0 14px;
}

.stack {
  display: grid;
  gap: 8px;
}

.summary-card {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--soft-card);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.04);
}

.summary-card.hero {
  padding: 18px;
}

.summary-card.highlight {
  border: 1px solid rgb(255 149 0 / 0.45);
  background: var(--orange-bg);
}

.summary-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.summary-title {
  flex: 1;
  min-width: 0;
  font-weight: 800;
  font-size: 18px;
  line-height: 1.1;
}

.hero .summary-title {
  font-size: 34px;
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--card);
  color: var(--secondary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.hero .chip {
  color: var(--text);
  background: #eeeeF3;
}

.progress {
  width: 100%;
  height: 7px;
  margin: 12px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #dedee5;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.highlight .progress-fill {
  background: #ff9500;
}

.metric-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 16px;
  font-size: 14px;
}

.hero .metric-grid {
  gap: 10px 20px;
  font-size: 21px;
}

.metric-label {
  color: var(--secondary);
}

.metric-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.metric-value.warn {
  color: var(--orange);
}

#summary-list .summary-card {
  padding: 10px 12px;
}

#summary-list .summary-header {
  align-items: center;
}

#summary-list .summary-title {
  font-size: 16px;
}

#summary-list .chip {
  padding: 5px 9px;
  font-size: 11px;
}

#summary-list .progress {
  height: 6px;
  margin: 9px 0;
}

#summary-list .metric-grid {
  gap: 4px 14px;
  font-size: 12px;
}

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

.quarter-flow {
  display: grid;
  gap: 10px;
}

.quarter-hero {
  padding: 10px;
  border: 1px solid rgb(255 149 0 / 0.45);
}

.quarter-hero .summary-title {
  font-size: 19px;
}

.quarter-rate {
  margin-top: 8px;
  color: var(--orange);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.quarter-hero .progress {
  height: 6px;
  margin: 7px 0;
}

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

.quarter-metrics div {
  min-width: 0;
}

.quarter-metrics span {
  display: block;
  margin-bottom: 1px;
  color: var(--secondary);
  font-size: 10px;
  font-weight: 700;
}

.quarter-metrics b {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 850;
}

.quarter-months {
  display: grid;
  gap: 10px;
}

.flow-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.flow-heading h3 {
  margin: 0;
  font-size: 17px;
}

.flow-heading span {
  color: var(--secondary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.flow-month-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
}

.flow-month-card {
  min-width: 0;
  padding: 8px 7px;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.03);
}

.flow-month-card.over,
.flow-month-card.borrowed {
  border-color: rgb(255 149 0 / 0.52);
  background: var(--orange-bg);
}

.flow-month-card.over .progress-fill {
  background: var(--danger);
}

.flow-month-card.borrowed .progress-fill {
  background: #ff9500;
}

.flow-month-card .progress {
  height: 6px;
  margin: 8px 0;
}

.flow-month-title {
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.flow-rate {
  margin-bottom: 4px;
  color: var(--orange);
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
}

.flow-month-card.over .flow-rate {
  color: var(--danger);
}

.flow-metrics {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 3px 5px;
  margin-top: 7px;
  font-size: 10px;
}

.flow-metrics span {
  color: var(--secondary);
}

.flow-metrics b {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  text-align: right;
}

.flow-metrics .warn {
  color: var(--orange);
}

.flow-metrics .danger {
  color: var(--danger);
}

@media (max-width: 360px) {
  .flow-month-card {
    padding: 9px 7px;
  }

  .flow-month-title {
    font-size: 13px;
  }

  .flow-rate {
    font-size: 17px;
  }

  .flow-metrics {
    font-size: 10px;
  }
}

.compact-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgb(255 149 0 / 0.45);
  border-radius: var(--radius);
  background: var(--orange-bg);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.04);
}

.compact-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 17px;
  white-space: nowrap;
}

.compact-rate {
  margin-bottom: 4px;
  color: var(--orange);
  font-size: 22px;
  font-weight: 850;
}

.compact-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  color: var(--secondary);
  font-size: 11px;
}

.compact-row b {
  color: var(--text);
}

.list-card {
  overflow: hidden;
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.03);
}

.expense-row,
.budget-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  padding: 12px 14px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.expense-row + .expense-row,
.budget-row + .budget-row {
  border-top: 1px solid var(--separator);
}

.pending-row {
  background: var(--pending-bg);
}

.pending-row .merchant::after {
  content: "확인";
  display: inline-block;
  margin-left: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: 11px;
  font-weight: 800;
  vertical-align: middle;
}

.expense-main,
.budget-main {
  flex: 1;
  min-width: 0;
}

.merchant,
.month-label {
  margin-bottom: 3px;
  font-size: 17px;
  font-weight: 800;
}

.meta,
.note {
  color: var(--secondary);
  font-size: 13px;
}

.note {
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount {
  font-size: 18px;
  font-weight: 850;
  white-space: nowrap;
}

.budget-row input {
  width: 140px;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: right;
  font-size: 18px;
  font-weight: 800;
}

.budget-preview {
  color: var(--secondary);
  font-size: 12px;
  text-align: right;
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgb(0 0 0 / 0.08);
  background: var(--tabbar);
  backdrop-filter: blur(18px);
}

.tab {
  position: relative;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  background: transparent;
  color: var(--secondary);
  font-size: 15px;
  font-weight: 750;
}

.tab-label {
  display: inline-block;
  padding-right: 0;
}

.tab:has(.tab-badge:not([hidden])) .tab-label {
  padding-right: 12px;
}

.tab.has-badge .tab-label {
  padding-right: 12px;
}

.tab-badge {
  position: absolute;
  top: 6px;
  right: 20px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border: 2px solid var(--tabbar);
  border-radius: 999px;
  background: #ff3b30;
  color: #ffffff;
  font-size: 10px;
  font-weight: 850;
  line-height: 13px;
  text-align: center;
}

.tab.active,
.tab[aria-selected="true"] {
  background: var(--tab-active);
  color: var(--tab-active-text);
}

dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 22px 70px rgb(0 0 0 / 0.25);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
}

#expense-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

#share-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-header h2 {
  flex: 1;
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 12px;
  background: #fafafd;
  background: var(--field);
  color: var(--text);
  font-size: 16px;
}

input[type="date"] {
  display: block;
  min-height: 46px;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
  display: block;
  min-width: 0;
  text-align: left;
}

textarea {
  resize: vertical;
}

pre {
  overflow: auto;
  white-space: pre-wrap;
  color: var(--secondary);
  font-size: 12px;
}

.dialog-actions {
  justify-content: flex-end;
}

.plain-button {
  padding: 8px 10px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--blue);
}

.plain-button:disabled,
.primary-button:disabled {
  opacity: 0.45;
}

.compact-segmented {
  margin-bottom: 0;
}

.share-filter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  background: var(--soft-card);
  color: var(--secondary);
  font-size: 13px;
  font-weight: 750;
}

.share-filter input {
  width: auto;
  min-width: 150px;
  border: 0;
  background: transparent;
  padding: 4px 0;
  text-align: right;
  font-weight: 800;
}

.share-selection {
  display: grid;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  background: var(--field);
}

.share-selection-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
  background: var(--soft-card);
  color: var(--secondary);
  font-size: 12px;
  font-weight: 800;
}

.share-selection-head button {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--control-surface);
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.share-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-top: 1px solid var(--separator);
  color: var(--text);
  font-size: 14px;
}

.share-row:first-child {
  border-top: 0;
}

.share-row input {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--blue);
}

.share-row b,
.share-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-preview-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  background: var(--soft-card);
}

.share-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.share-preview-head span,
.share-preview-head strong,
.share-preview-head b {
  display: block;
}

.share-preview-head span {
  margin-bottom: 2px;
  color: var(--secondary);
  font-size: 11px;
  font-weight: 800;
}

.share-preview-head strong {
  font-size: 15px;
}

.share-preview-head b {
  color: var(--blue);
  font-size: 16px;
  white-space: nowrap;
}

#share-preview {
  min-height: 154px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 16px;
  line-height: 1.35;
}

.share-row small {
  margin-top: 2px;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
}

.primary-button,
.danger-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius);
  color: white;
  font-weight: 800;
}

.primary-button {
  background: var(--blue);
}

.danger-button {
  margin-right: auto;
  background: var(--danger);
}

.empty {
  padding: 28px 16px;
  color: var(--secondary);
  text-align: center;
}

@media (max-width: 360px) {
  .compact-grid {
    grid-template-columns: 1fr;
  }

  .amount {
    font-size: 18px;
  }
}
