/* ============================================================
   Marty — core design system (tokens + layout + shared components)
   Page-specific styles live in assets/css/pages/*.css
   ============================================================ */

:root {
  --bg: #F4F6F3;
  --card: #FFFFFF;
  --ink: #22312B;
  --muted: #7A857F;
  --green: #17A34A;
  --green-dark: #12813B;
  --green-soft: #E4F4EA;
  --green-softer: #F0F9F3;
  --red: #DC5B4E;
  --red-soft: #FBEAE8;
  --amber: #E8A13C;
  --amber-soft: #FBF3E4;
  --blue: #4A7FDB;
  --line: #E7EBE7;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 1px 3px rgba(34, 49, 43, .06), 0 4px 16px rgba(34, 49, 43, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }
a { color: var(--green-dark); text-decoration: none; }
button { font-family: inherit; }

/* ------------------------------------------------ layout ---- */

#page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 28px);
  min-height: 100vh;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}
.page-head h1 { font-size: 22px; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 20px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ------------------------------------------------ cards ----- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }

/* ------------------------------------------------ buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--green-soft);
  color: var(--green-dark);
  transition: transform .06s ease, opacity .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* ------------------------------------------------ chips ----- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

/* ------------------------------------------------ forms ----- */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  font-family: inherit;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--green); }
.field-error { color: var(--red); font-size: 13px; margin-top: 5px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* ------------------------------------------------ lists ----- */

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-ico {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
  background: var(--green-softer);
}
.list-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-title {
  display: block;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-sub {
  display: block;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-amt {
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.amount-pos { color: var(--green-dark); }
.amount-neg { color: var(--ink); }
.amount-muted { color: var(--muted); }

/* ------------------------------------------------ badges ---- */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
}
.badge-green { background: var(--green-soft); color: var(--green-dark); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: #A96F1B; }

/* ------------------------------------------------ progress -- */

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width .4s ease;
}
.progress-bar.amber { background: var(--amber); }
.progress-bar.over { background: var(--red); }
.amount-over { color: var(--red); }
.amount-warn { color: #A96F1B; }

/* ------------------------------------------------ avatar ---- */

.avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--green-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

/* ------------------------------------------------ skeleton -- */

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #ECEFEB 25%, #F5F7F4 50%, #ECEFEB 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.4s infinite;
  color: transparent !important;
  min-height: 16px;
}
@keyframes skeleton-wave {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ------------------------------------------------ empty ----- */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .empty-ico { font-size: 44px; margin-bottom: 10px; }
.empty-state .empty-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty-state .empty-sub { font-size: 14px; }

/* ------------------------------------------------ nav ------- */

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 60;
}
#bottom-nav[hidden] { display: none; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  min-width: 56px;
  padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--green-dark); }
.nav-ico { font-size: 21px; line-height: 1; filter: grayscale(1) opacity(.6); }
.nav-item.active .nav-ico { filter: none; }
.nav-add-btn {
  width: 52px;
  height: 52px;
  margin-top: -26px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 30px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(23, 163, 74, .35);
}

/* ------------------------------------------------ modal ----- */

#modal-root .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 34, 29, .45);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in .18s ease;
}
#modal-root .modal-panel {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slide-up .22s ease;
}
@media (min-width: 640px) {
  #modal-root .modal-backdrop { align-items: center; }
  #modal-root .modal-panel { border-radius: 24px; max-height: 86vh; }
}
.modal-grabber {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 14px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------ toast ----- */

#toast-root {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
}
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  animation: slide-up .2s ease;
}
.toast.success { background: var(--green-dark); }
.toast.error { background: var(--red); }
.toast-action {
  margin-left: auto;
  background: rgba(255, 255, 255, .18);
  border: none;
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
}

/* ------------------------------------------------ misc ------ */

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.hidden { display: none !important; }
