:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eceff2;
  --border: #e3e6ea;
  --text: #14171c;
  --text-muted: #6b7280;
  --accent: #0f9d78;
  --accent-hover: #0c7f61;
  --accent-soft: #e3f5ee;
  --success: #16a34a;
  --danger: #e5484d;
  --warning: #f0a020;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 12px rgba(15,23,42,0.06);
  --shadow-lg: 0 8px 24px rgba(15,23,42,0.10), 0 2px 6px rgba(15,23,42,0.06);
  --radius: 18px;
  --radius-sm: 12px;
}

[data-theme="dark"] {
  --bg: #0b0d10;
  --surface: #15181c;
  --surface-alt: #1c2024;
  --border: #262b31;
  --text: #f2f3f5;
  --text-muted: #8b9099;
  --accent: #17c98f;
  --accent-hover: #3fdba3;
  --accent-soft: #123326;
  --success: #22c55e;
  --danger: #ff5b60;
  --warning: #f5b942;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 20px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5), 0 4px 10px rgba(0,0,0,0.4);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  letter-spacing: -0.01em;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen { display: none; flex: 1; flex-direction: column; padding: 18px; padding-bottom: 100px; }
.screen.active { display: flex; animation: fadeIn 0.25s ease; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.entry-card { cursor: default; }
.entry-card:active { transform: scale(0.99); }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.muted { color: var(--text-muted); font-size: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  letter-spacing: -0.01em;
}
.btn:active { transform: scale(0.96); opacity: 0.9; }
.btn-primary { background: var(--accent); color: #ffffff; box-shadow: 0 4px 14px rgba(15,157,120,0.28); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-danger { background: rgba(229,72,77,0.12); color: var(--danger); box-shadow: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }

.input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
label:first-child { margin-top: 0; }

.bottom-nav {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 456px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 6px max(8px, env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 14px;
  transition: color 0.15s ease, background 0.15s ease;
  flex: 1;
}
.nav-item.active { color: var(--accent); background: var(--accent-soft); }
.nav-item svg { width: 21px; height: 21px; }

#nav-log-btn {
  color: var(--accent);
}
#nav-log-btn svg {
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  padding: 5px;
  box-shadow: 0 4px 12px rgba(15,157,120,0.4);
}
#nav-log-btn.active { background: none; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 18px;
}
.top-bar h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-box, .stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-box .value, .stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; display: block; margin-top: 4px; }
.stat-box .label, .stat-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 280px;
  margin: 24px auto 0;
}
.numpad button {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.numpad button:active { background: var(--surface-alt); transform: scale(0.94); }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 32px 0;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-lg);
}
.autocomplete-list div {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 14px;
}
.autocomplete-list div:hover { background: var(--surface-alt); }

.field-relative { position: relative; }

.toast {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

#log-modal {
  animation: slideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
