:root {
  color-scheme: light;
  --bg: #f5f5fa;
  --card: #ffffff;
  --muted: #f0f0f6;
  --line: #e5e5ec;
  --text: #050508;
  --secondary: #8b8b94;
  --accent: #0091ff;
  --green: #21bf5a;
  --orange: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 42px rgba(24, 28, 38, 0.06);
  --radius-xl: 30px;
  --radius-md: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

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

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100svh;
  padding: calc(env(safe-area-inset-top) + 12px) 18px calc(env(safe-area-inset-bottom) + 24px);
  overflow-x: hidden;
  background: var(--bg);
}

.app-width {
  width: min(100%, 720px);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 14px;
}

.topbar.list {
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-circle {
  width: 54px;
  height: 54px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--card);
  font-size: 31px;
  line-height: 1;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.action-circle.small-text {
  font-size: 24px;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 3px 5px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.action-group .action-circle {
  width: 42px;
  height: 42px;
  box-shadow: none;
  background: transparent;
  font-size: 24px;
}

.home-title {
  margin: 18px 0 28px;
  font-size: 44px;
  line-height: 1.03;
  letter-spacing: 0;
  font-weight: 900;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px 34px;
  margin: 0 20px 42px;
}

.metric-label {
  display: block;
  color: var(--secondary);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.stat-label {
  display: block;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
}

.metric-value,
.stat-value {
  display: block;
  margin-top: 3px;
  font-size: 26px;
  line-height: 1.18;
  font-weight: 900;
  letter-spacing: 0;
}

.section-title {
  margin: 28px 28px 14px;
  color: var(--secondary);
  font-size: 22px;
  font-weight: 850;
}

.card {
  width: 100%;
  max-width: 100%;
  margin: 0 0 18px;
  padding: 20px;
  border-radius: var(--radius-xl);
  background: var(--card);
  overflow-wrap: break-word;
}

.title-card {
  padding: 22px 28px;
}

.title-card h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.exchange-error {
  margin: 0 0 5px;
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.35;
}

.exchange-updated {
  margin: 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.35;
}

.exchange-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: baseline;
  gap: 18px;
  margin-top: 8px;
  color: var(--secondary);
  font-size: 15px;
  line-height: 1.45;
}

.exchange-code {
  color: var(--text);
  font-weight: 900;
}

.summary-total {
  margin-bottom: 15px;
}

.summary-total strong {
  display: block;
  margin-top: 3px;
  font-size: 24px;
  line-height: 1.2;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-value {
  font-size: 22px;
}

.trip-list {
  padding: 18px 22px;
  overflow: hidden;
}

.trip-item {
  position: relative;
  padding: 7px 0;
  background: var(--card);
}

.trip-item + .trip-item {
  border-top: 1px solid var(--line);
  padding-top: 22px;
  margin-top: 16px;
}

.swipe-row {
  --swipe-x: 0px;
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  touch-action: pan-y;
}

.trip-swipe-row,
.expense-swipe-row {
  border-radius: 22px;
}

.trip-swipe-row + .trip-swipe-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.swipe-content {
  position: relative;
  z-index: 1;
  width: 100%;
  transform: translateX(var(--swipe-x));
  transition: transform 0.2s ease;
  will-change: transform;
}

.swipe-row.swiping .swipe-content {
  transition: none;
}

.swipe-row:focus-within .swipe-content {
  transform: translateX(-144px);
}

.swipe-actions {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
  border-radius: inherit;
  background: var(--line);
}

.swipe-action {
  width: 72px;
  min-height: 100%;
  color: white;
  font-size: 15px;
  font-weight: 900;
}

.swipe-action.edit {
  background: #7d7d88;
}

.swipe-action.delete {
  background: var(--red);
}

.trip-main-row,
.expense-row,
.budget-row,
.modal-actions,
.form-row,
.receipt-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.trip-main {
  flex: 1;
  min-width: 0;
}

.modal-actions {
  position: sticky;
  bottom: -22px;
  flex-wrap: wrap;
  margin: 4px -20px -22px;
  padding: 14px 20px calc(env(safe-area-inset-bottom) + 18px);
  border-top: 1px solid rgba(229, 229, 236, 0.72);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
}

.modal-actions > button {
  flex: 1 1 142px;
  min-width: 0;
}

.trip-title {
  margin: 0;
  font-size: 25px;
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: 0;
}

.trip-subtitle {
  margin: 5px 0 0;
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.35;
}

.status-pill {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--green);
  background: rgba(33, 191, 90, 0.14);
  font-size: 15px;
  font-weight: 850;
}

.status-pill.done {
  color: var(--secondary);
  background: rgba(139, 139, 148, 0.14);
}

.status-pill.future {
  color: var(--accent);
  background: rgba(0, 145, 255, 0.13);
}

.chevron {
  color: #bebec6;
  font-size: 42px;
  line-height: 1;
}

.trip-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.trip-stats .stat-value {
  font-size: 22px;
}

.chips {
  display: flex;
  gap: 8px;
  padding-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--muted);
  font-size: 15px;
  font-weight: 850;
}

.chip.active {
  color: white;
  background: var(--accent);
}

.budget-table {
  border-top: 1px solid var(--line);
  padding-top: 13px;
}

.budget-head,
.budget-row {
  display: grid;
  grid-template-columns: 1.25fr 0.9fr 0.9fr;
  gap: 10px;
  align-items: center;
}

.budget-head {
  padding: 0 14px 8px;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 800;
}

.budget-head span:nth-child(2),
.budget-head span:nth-child(3),
.budget-row .right {
  text-align: right;
}

.budget-row {
  min-height: 66px;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--muted);
}

.budget-name {
  font-size: 16px;
  font-weight: 900;
}

.budget-sub,
.expense-meta,
.empty-copy {
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: break-word;
}

.expense-list {
  display: grid;
  width: 100%;
  max-width: 100%;
  gap: 12px;
}

.expense-row {
  width: 100%;
  min-width: 0;
  padding: 14px;
  border-radius: 22px;
  background: var(--card);
}

.receipt-thumb {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 17px;
  background: var(--muted);
}

.expense-body {
  flex: 1;
  min-width: 0;
}

.expense-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-amount {
  flex: 0 0 auto;
  max-width: 42%;
  text-align: right;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.expense-amount small {
  display: block;
  margin-top: 2px;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
}

.empty-card {
  text-align: center;
  padding: 34px 22px;
}

.empty-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.version {
  margin: 24px 4px 0;
  color: var(--secondary);
  font-size: 13px;
  text-align: right;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.22);
}

.modal-root[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 680px;
  min-width: 0;
  max-height: calc(100svh - 36px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 30px;
  background: var(--card);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.22);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 10px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.modal-title {
  flex: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}

.modal-close {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--muted);
  font-size: 24px;
}

.modal-body {
  padding: 10px 20px 22px;
  min-width: 0;
  overflow-x: hidden;
}

.form-grid {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field label {
  color: var(--secondary);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: 0;
  padding: 12px 14px;
  color: var(--text);
  background: #fafafd;
}

.field textarea {
  min-height: 104px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.form-row .field {
  min-width: 0;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 900;
}

.primary-button {
  color: white;
  background: var(--accent);
}

.secondary-button {
  background: var(--muted);
}

.danger-button {
  color: var(--red);
  background: rgba(220, 38, 38, 0.1);
}

.button-stack {
  display: grid;
  gap: 10px;
}

.menu-button {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border-radius: 18px;
  background: var(--muted);
  text-align: left;
  font-weight: 850;
}

.hint {
  margin: 8px 0 0;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.45;
}

.receipt-preview {
  width: 100%;
  max-height: 62svh;
  object-fit: contain;
  border-radius: 22px;
  background: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  z-index: 30;
  max-width: calc(100% - 36px);
  transform: translate(-50%, 150%);
  opacity: 0;
  padding: 12px 16px;
  border-radius: 999px;
  color: white;
  background: rgba(0, 0, 0, 0.82);
  font-size: 14px;
  font-weight: 750;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.hidden {
  display: none !important;
}

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

  .home-title {
    font-size: 54px;
  }

  .modal-root {
    place-items: center;
  }
}

@media (max-width: 520px) {
  .modal-root {
    padding: 12px;
  }

  .modal {
    max-height: calc(100svh - 24px);
    border-radius: 26px;
  }

  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .modal-actions > button {
    flex-basis: 100%;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .home-title {
    font-size: 39px;
  }

  .metric-grid {
    margin-left: 16px;
    margin-right: 16px;
    gap: 26px 22px;
  }

  .metric-value {
    font-size: 23px;
  }

  .section-title {
    margin-left: 22px;
    margin-right: 22px;
    font-size: 20px;
  }

  .card {
    padding: 18px;
    border-radius: 26px;
  }

  .title-card {
    padding: 20px 24px;
  }

  .title-card h2 {
    font-size: 26px;
  }

  .exchange-row {
    gap: 12px;
    font-size: 14px;
  }

  .trip-title {
    font-size: 23px;
  }

  .trip-subtitle {
    font-size: 15px;
  }

  .stat-row,
  .trip-stats {
    gap: 8px;
  }

  .stat-value,
  .trip-stats .stat-value {
    font-size: 18px;
  }

  .action-group .action-circle {
    width: 38px;
  }

  .expense-row {
    padding: 12px;
  }

  .receipt-thumb {
    width: 52px;
    height: 52px;
    border-radius: 15px;
  }

  .expense-title {
    font-size: 16px;
  }
}
