*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --teal: #0097a7;
  --teal-dark: #00747e;
  --teal-light: #e3f5f7;
  --teal-tint: #f1fafb;

  --text: #16212b;
  --text-secondary: #647281;
  --muted: #8a96a3;

  --line: #e8ecf0;
  --bg: #eef1f5;
  --card-bg: #ffffff;

  --danger: #e0463c;
  --danger-bg: #fdeceb;
  --success: #2e9e63;
  --warn: #ef8b1a;
  --warn-bg: #fff3e2;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow-card: 0 1px 2px rgba(16,24,40,.04), 0 10px 28px -12px rgba(16,24,40,.16);
  --shadow-pop: 0 12px 32px -8px rgba(16,24,40,.22);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #0aa4b1 0%, #00747e 100%);
  color: #fff;
  padding: calc(1rem + env(safe-area-inset-top)) 1.25rem 1.15rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 6px 20px -8px rgba(0,116,126,.55);
}

.brand {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(2px);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.82;
  margin-top: 0.1rem;
}

/* ── Main layout ── */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Card ── */
.card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.35rem 1.25rem;
  animation: rise 0.35s cubic-bezier(.22,1,.36,1) both;
}
#form-card   { z-index: 2; }
#recent-card { z-index: 1; animation-delay: 0.05s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Status banner ── */
.status-banner {
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.9rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  font-weight: 500;
}
.status-banner.error { background: var(--danger-bg); color: var(--danger); }
.status-banner.info  { background: var(--teal-light); color: var(--teal-dark); }

/* ── Form fields ── */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field-group {
  margin-bottom: 0.95rem;
}

label {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

input[type="date"],
input[type="number"],
input[type="text"],
select {
  width: 100%;
  height: 52px;
  padding: 0 0.95rem;
  font-size: 1rem;
  color: var(--text);
  background: #f5f7f9;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

input::placeholder { color: var(--muted); }

input:focus,
select:focus {
  border-color: var(--teal);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0,151,167,0.13);
}

/* Amount field with currency prefix */
.amount-field { position: relative; }

.amount-cur {
  position: absolute;
  left: 0.95rem;
  top: 0;
  height: 52px;
  display: flex;
  align-items: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-secondary);
  pointer-events: none;
}

.amount-field input {
  padding-left: 1.9rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Combobox ── */
.combobox { position: relative; }

.combobox::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 21px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg);
  pointer-events: none;
  transition: transform 0.15s;
}

.combobox-input { padding-right: 2.4rem; cursor: text; }

.combobox-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 230px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-pop);
  animation: pop 0.14s ease-out;
  -webkit-overflow-scrolling: touch;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.combobox-list {
  list-style: none;
  padding: 0.3rem;
}

.combobox-option {
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  font-size: 0.95rem;
  border-radius: 8px;
}

.combobox-option:hover,
.combobox-option:active {
  background: var(--teal-light);
  color: var(--teal-dark);
}

.combobox-empty {
  padding: 0.7rem 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Buttons ── */
.form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.35rem;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 52px;
  padding: 0 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, opacity 0.15s, box-shadow 0.15s;
}
button:active:not(:disabled) { transform: scale(0.975); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, #0aa4b1 0%, #00808b 100%);
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(0,128,139,0.7);
}
.btn-primary:not(:disabled):hover { filter: brightness(1.04); }

.btn-secondary {
  flex: 0 0 auto;
  background: var(--teal-tint);
  color: var(--teal-dark);
  border: 1px solid var(--teal-light);
}
.btn-secondary:not(:disabled):hover { background: var(--teal-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  min-height: auto;
  padding: 0.3rem 0.6rem;
  border-radius: 7px;
}
.btn-ghost:hover { color: var(--danger); background: var(--danger-bg); }

/* ── Spinner ── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Recent entries ── */
.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

#recent-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#recent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

#recent-list li.recent-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  grid-template-areas:
    "avatar desc amount"
    "avatar sub  meta";
  column-gap: 0.75rem;
  row-gap: 0.1rem;
  align-items: center;
  padding: 0.7rem 0.4rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.12s;
}

#recent-list li.recent-item:last-child { border-bottom: none; }

#recent-list li.recent-item:hover,
#recent-list li.recent-item:active {
  background: var(--teal-tint);
}

#recent-list li.recent-item::before {
  content: '$';
  grid-area: avatar;
  align-self: center;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--teal-light);
  color: var(--teal-dark);
  font-weight: 800;
  font-size: 1rem;
}

.recent-desc {
  grid-area: desc;
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-amount {
  grid-area: amount;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  text-align: right;
}

.recent-txn {
  grid-area: sub;
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-date {
  grid-area: meta;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}

.recent-status {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 0.06rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.3rem;
}
.recent-status.pending { background: var(--warn-bg); color: var(--warn); }
.recent-status.failed  { background: var(--danger-bg); color: var(--danger); }

#recent-list li.recent-item.pending { opacity: 0.66; }
#recent-list li.recent-item.failed::before { background: var(--danger-bg); color: var(--danger); }
#recent-list li.recent-item.failed .recent-amount { color: var(--danger); }

#recent-list li.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 1.75rem 0 1.25rem;
}
#recent-list li.empty-state::before {
  content: '🧾';
  display: block;
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
  opacity: 0.7;
}

/* ── Footnote ── */
.footnote {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.25rem 0 0;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: calc(1.4rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1c2630;
  color: #fff;
  padding: 0.75rem 1.3rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 12px 30px -8px rgba(0,0,0,0.45);
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  max-width: 90vw;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.hidden  { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ── Description quick-tags ── */
.desc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.desc-tags:empty { display: none; }

.desc-tag {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal-dark);
  background: var(--teal-tint);
  border: 1px solid var(--teal-light);
  border-radius: 999px;
  cursor: pointer;
}
.desc-tag:hover { background: var(--teal-light); }

/* ── Small screens ── */
@media (max-width: 360px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
}

/* ── Utility ── */
.hidden { display: none !important; }
.toast.hidden { display: block !important; pointer-events: none; }
