:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #e5e5ea;
  --accent: #0071e3;
  --expense: #d64545;
  --income: #2e9e5b;
  --investment: #7a5af5;
  --transfer: #8a8a8e;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}

header {
  padding: 20px 16px 8px;
  text-align: center;
}

header h1 {
  font-size: 1.25rem;
  margin: 0;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.type-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.type-tab {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 0.75rem;
  text-align: center;
  cursor: pointer;
}

.type-tab.active[data-type="expense"] { background: var(--expense); color: white; border-color: var(--expense); }
.type-tab.active[data-type="income"] { background: var(--income); color: white; border-color: var(--income); }
.type-tab.active[data-type="investment"] { background: var(--investment); color: white; border-color: var(--investment); }
.type-tab.active[data-type="transfer"] { background: var(--transfer); color: white; border-color: var(--transfer); }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 4px;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: white;
  color: var(--text);
  font-family: inherit;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"] {
  /* iOS Safari renders its own control chrome behind the box unless the
     native appearance is fully stripped, which looks like a doubled
     border/shadow offset from our own box. */
  -webkit-appearance: none;
  appearance: none;
}

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

.row > div {
  min-width: 0;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.tag-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  background: white;
}

.tag-chip.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.add-inline {
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 0;
  background: none;
  border: none;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 10px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

.category-tile-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.category-tile-name {
  font-size: 0.7rem;
  text-align: center;
  color: var(--text);
  line-height: 1.15;
}

.category-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.category-banner-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.category-banner span:nth-child(2) {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.category-banner .add-inline {
  padding: 4px 0;
}

button.primary {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary:disabled {
  opacity: 0.5;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
}

.currency-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
  margin-top: 6px;
}

.currency-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

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

.currency-chip.more {
  color: var(--muted);
}

.currency-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.currency-modal {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 75vh;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.currency-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 12px;
}

.currency-modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

.currency-option-list {
  overflow-y: auto;
  margin-top: 10px;
}

.currency-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.currency-option:last-child {
  border-bottom: none;
}

.currency-option-flag {
  font-size: 1.3rem;
}

.currency-option-code {
  font-weight: 600;
  width: 44px;
  flex-shrink: 0;
}

.currency-option-name {
  color: var(--muted);
  font-size: 0.85rem;
}

.entry-list h2 {
  font-size: 1rem;
  margin: 4px 0 10px;
}

.entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.entry:last-child { border-bottom: none; }

.entry-left { flex: 1; min-width: 0; }

.entry-category {
  font-weight: 600;
  font-size: 0.95rem;
}

.entry-desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

.entry-amount {
  text-align: right;
  white-space: nowrap;
  padding-left: 10px;
}

.entry-amount .primary-amt {
  font-weight: 600;
}

.entry-amount .pen-amt {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.type-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.entry-cat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.85rem;
  margin-right: 6px;
  vertical-align: middle;
}

.type-dot[data-type="expense"] { background: var(--expense); }
.type-dot[data-type="income"] { background: var(--income); }
.type-dot[data-type="investment"] { background: var(--investment); }
.type-dot[data-type="transfer"] { background: var(--transfer); }

.setup-screen {
  max-width: 400px;
  margin: 60px auto;
  padding: 0 20px;
  text-align: center;
}

.status-msg {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 20px;
}

[hidden] { display: none !important; }
