:root {
  --navy: #1b2340;
  --navy-deep: #10162b;
  --maroon: #a6304b;
  --maroon-dark: #832540;
  --maroon-light: #f6e2e6;
  --bg: #ffffff;
  --card-bg: #ffffff;
  --border: #e6e1de;
  --border-strong: #d8d3cf;
  --ink: #1b2340;
  --muted: #6b7280;
  --green: #1e8e6e;
  --green-bg: #e6f4ef;
  --red: #d64545;
  --red-bg: #fbe9e8;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

h1, h2, h3, .brand {
  font-family: "Poppins", "Inter", sans-serif;
}

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

a { color: inherit; }

#app {
  min-height: 100dvh;
  position: relative;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.main-col {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.sidebar {
  display: none;
}

.screen {
  flex: 1;
  padding: calc(20px + var(--safe-top)) 20px calc(var(--nav-height) + var(--safe-bottom) + 28px);
}

.screen.no-nav {
  padding-bottom: calc(28px + var(--safe-bottom));
}

/* Header */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--navy);
  font-size: 22px;
  line-height: 1;
  padding: 6px;
  margin: -6px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn:active { background: var(--maroon-light); }

.topbar h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--navy);
  padding: 8px;
  margin: -8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active, .icon-btn:hover { background: var(--maroon-light); color: var(--maroon); }

.subtitle {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: -8px 0 20px;
}

/* Brand header on home */

.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.brand-header img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}
.brand-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
}

/* Form fields */

.field {
  margin-bottom: 18px;
}
.field label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--navy);
  margin-bottom: 8px;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
}
.field textarea {
  min-height: 90px;
  resize: vertical;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--maroon);
  box-shadow: 0 0 0 3px var(--maroon-light);
}

.amount-input {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0 16px;
}
.amount-input span {
  font-size: 18px;
  color: var(--muted);
  margin-right: 6px;
}
.amount-input input {
  border: none !important;
  padding: 14px 0 !important;
  box-shadow: none !important;
  font-size: 18px;
  font-weight: 600;
}
.amount-input:focus-within {
  border-color: var(--maroon);
  box-shadow: 0 0 0 3px var(--maroon-light);
}

.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "\25BE";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--navy);
  pointer-events: none;
  font-size: 16px;
}
.select-wrap select {
  padding-right: 40px;
}

/* Segmented / toggle */

.segment {
  display: flex;
  background: #eef0f4;
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 20px;
}
.segment button {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 10px;
  border-radius: calc(var(--radius-md) - 4px);
  font-weight: 600;
  font-size: 15px;
  color: var(--navy);
  cursor: pointer;
}
.segment button.active {
  background: var(--maroon);
  color: #fff;
}
.segment button.active.in-variant { background: var(--green); }

.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill-group button {
  border: 1.5px solid var(--border-strong);
  background: #fff;
  color: var(--navy);
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  flex: 1;
  min-width: 90px;
}
.pill-group button.active {
  background: var(--maroon);
  border-color: var(--maroon);
  color: #fff;
}

/* Buttons */

.btn-primary {
  width: 100%;
  background: var(--maroon);
  color: #fff;
  border: none;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:active { background: var(--maroon-dark); }
.btn-primary:disabled { opacity: 0.55; }

.btn-secondary {
  width: 100%;
  background: #fff;
  color: var(--maroon);
  border: 1.5px solid var(--maroon);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--maroon);
  color: #fff;
  border: none;
  padding: 16px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}
.btn-add.floating {
  position: sticky;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  box-shadow: 0 8px 20px rgba(166, 48, 75, 0.35);
}

.link-btn {
  background: none;
  border: none;
  color: var(--maroon);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 0;
}

/* Month select bar */

.month-select {
  margin-bottom: 18px;
}
.month-select select {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.filter-row .select-wrap { flex: 1; }
.filter-row select {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 34px 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
}

/* Stat cards */

.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}
.stat-card {
  flex: 1;
  background: #f7f6f4;
  border-radius: var(--radius-md);
  padding: 14px 12px;
  min-width: 0;
}
.stat-card .label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 19px;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-card.in .value { color: var(--green); }
.stat-card.out .value { color: var(--ink); }
.stat-card.balance .value { color: var(--green); }

/* Section heading */

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin: 4px 0 14px;
}

/* Lists */

.list {
  border-top: 1px solid var(--border);
}
.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.list-row:active { background: #faf7f6; }

.row-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.row-icon.in { background: var(--green-bg); color: var(--green); }
.row-icon.out { background: var(--red-bg); color: var(--red); }

.row-body {
  flex: 1;
  min-width: 0;
}
.row-title {
  font-weight: 700;
  color: var(--navy);
  font-size: 15px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-amount {
  text-align: right;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 15px;
}
.row-amount .amt.in { color: var(--green); }
.row-amount .amt.out { color: var(--red); }
.row-amount .dir {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.row-chevron {
  color: var(--border-strong);
  font-size: 20px;
  flex-shrink: 0;
}

/* Activity card (Activities list) */

.activity-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  cursor: pointer;
  background: #fff;
}
.activity-card:active { background: #faf7f6; }
.activity-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.activity-card-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}
.activity-card-stats {
  display: flex;
  gap: 22px;
}
.activity-card-stats div .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.activity-card-stats div .value {
  font-weight: 700;
  font-size: 15px;
  color: var(--navy);
}
.activity-card-stats div.in .value { color: var(--green); }
.activity-card-stats div.out .value { color: var(--red); }

.simple-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 700;
  color: var(--navy);
  font-size: 16px;
}
.simple-card:active { background: #faf7f6; }

/* Empty state */

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 10px;
  font-size: 14px;
}

/* Bottom nav */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.nav-inner {
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  width: 100%;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--maroon); }
.nav-item.active svg { stroke: var(--maroon); }

/* Login */

.login-screen {
  min-height: 100dvh;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 28px calc(28px + var(--safe-bottom));
  padding-top: calc(24px + var(--safe-top));
}
.login-logo {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  margin: 0 auto 20px;
  display: block;
}
.login-screen h1 {
  text-align: center;
  color: var(--navy);
  font-size: 24px;
  margin: 0 0 6px;
}
.login-screen p.sub {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 28px;
}
.login-error {
  color: var(--red);
  font-size: 14px;
  text-align: center;
  margin: -8px 0 14px;
}
.login-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 40vh;
  color: var(--muted);
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  background: var(--navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.danger-btn {
  width: 100%;
  background: none;
  border: 1.5px solid var(--red);
  color: var(--red);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
}

/* Sidebar (desktop nav) */

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  margin-bottom: 28px;
}
.sidebar-brand img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
}
.sidebar-brand span {
  font-family: "Poppins", "Inter", sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--navy);
  line-height: 1.25;
}

.sidebar-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar .nav-item {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
}
.sidebar .nav-item svg { width: 20px; height: 20px; }
.sidebar .nav-item:hover { background: #f7f1f0; }
.sidebar .nav-item.active { background: var(--maroon-light); color: var(--maroon); }

.sidebar-add {
  margin-top: auto;
}

/* Small tablet: keep single column but a touch more breathing room */

@media (min-width: 640px) and (max-width: 899px) {
  .main-col {
    max-width: 560px;
  }
}

/* Desktop */

@media (min-width: 900px) {
  html, body { background: #faf8f7; }

  .app-shell {
    flex-direction: row;
    max-width: 1180px;
    margin: 0 auto;
    align-items: flex-start;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 250px;
    flex-shrink: 0;
    padding: 32px 16px;
    position: sticky;
    top: 0;
    height: 100dvh;
    box-sizing: border-box;
  }

  .main-col {
    max-width: none;
    flex: 1;
    background: var(--bg);
    min-height: 100dvh;
    box-shadow: -1px 0 0 var(--border);
  }

  .screen {
    max-width: 760px;
    padding: 44px 48px 60px;
  }
  .screen.no-nav {
    padding: 44px 48px 60px;
  }

  .bottom-nav { display: none; }

  .topbar h1, .brand-header h1 { font-size: 30px; }
  .section-title { font-size: 22px; }
  .stat-card .value { font-size: 23px; }
  .stat-card { padding: 18px 16px; }
  .activity-card-head h3 { font-size: 18px; }

  .activities-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
  .activity-card { margin-bottom: 0; }

  .btn-primary, .btn-add, .btn-secondary, .danger-btn {
    width: auto;
    min-width: 220px;
  }
  .btn-add.floating { position: static; box-shadow: none; }

  .list-row:hover, .activity-card:hover, .simple-card:hover { background: #faf7f6; }
}
