:root {
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #102033;
  --muted: #6b7a8d;
  --line: #e6ebf1;
  --teal: #0f9d8a;
  --teal-soft: #e6f7f4;
  --rose: #e5484d;
  --rose-soft: #fdecec;
  --navy: #17324d;
  --shadow: 0 10px 30px rgba(16, 32, 51, 0.06);
  --radius: 20px;
  --font: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(900px 420px at 8% -10%, #d9f3ee 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, #dce7f5 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

.nav {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(16px);
  background: rgba(238, 242, 246, 0.86);
  border-bottom: 1px solid rgba(230, 235, 241, 0.9);
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand-wrap { position: relative; min-width: 160px; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 4px 8px 4px 4px;
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.brand:hover { background: rgba(255, 255, 255, 0.7); }

.logo {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--navy);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand strong { display: block; font-size: 16px; }
.brand span { color: var(--muted); font-size: 12px; }

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 280px;
  background: white;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 35;
  border: 1px solid var(--line);
}
.account-menu.hidden { display: none; }
.menu-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
}
.menu-login label {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.menu-login input {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
}
.menu-btn { width: 100%; }
.btn.danger { background: var(--rose); }
.menu-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}
.menu-email {
  margin: 0;
  font-weight: 700;
  word-break: break-all;
}
.menu-error {
  margin: 10px 0 0;
  color: var(--rose);
  font-size: 12px;
  font-weight: 700;
}
.menu-error.hidden { display: none; }
.menu-login.hidden,
.menu-session.hidden { display: none; }

.locked-state {
  display: none;
  place-items: center;
  padding: 80px 24px;
}
.is-locked .locked-state { display: grid; }
.is-locked .page,
.is-locked .periods,
.is-locked .nav-right { display: none; }

.locked-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 420px;
  text-align: center;
}
.locked-card .logo { margin: 0 auto 12px; }
.locked-card h2 { margin: 0 0 8px; }
.locked-card p { margin: 0; color: var(--muted); }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  max-width: 280px;
  text-align: right;
}

.periods {
  display: flex;
  padding: 4px;
  background: #e3e9f0;
  border-radius: 999px;
  gap: 2px;
}

.periods button,
.btn {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.periods button {
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
}

.periods button.active {
  background: white;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(16, 32, 51, 0.08);
}

.periods button.month-pick {
  text-transform: lowercase;
}

.btn {
  background: var(--navy);
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-ghost {
  background: #eef2f6;
  color: var(--text);
}

.btn-ghost:hover {
  background: #e3e9f0;
}

.more-wrap {
  display: flex;
  justify-content: center;
  padding: 14px 0 4px;
}

.more-wrap.hidden {
  display: none;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

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

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

.kpi .label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.kpi .value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.kpi .delta {
  display: inline-flex;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 8px;
  background: #f1f4f8;
  color: var(--muted);
}

.kpi .delta.up { background: var(--rose-soft); color: var(--rose); }
.kpi .delta.down { background: var(--teal-soft); color: var(--teal); }
.kpi.expense .delta.up,
.kpi.income .delta.down,
.kpi.net .delta.down { background: var(--rose-soft); color: var(--rose); }
.kpi.expense .delta.down,
.kpi.income .delta.up,
.kpi.net .delta.up { background: var(--teal-soft); color: var(--teal); }
.kpi.expense .value { color: var(--rose); }
.kpi.income .value { color: var(--teal); }

.grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  margin-bottom: 14px;
}

.grid-ops {
  grid-template-columns: minmax(240px, 0.58fr) minmax(0, 1.42fr);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.info-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  font-style: italic;
  cursor: pointer;
  line-height: 1;
}

.info-btn:hover {
  background: #e3e9f0;
  color: var(--navy);
}

.chart-box { height: 280px; position: relative; }
.chart-pie { height: 300px; }
h2 { margin: 0; font-size: 18px; font-weight: 800; }
.caption { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.account-list { display: grid; gap: 8px; }
.account {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 14px;
}

.account:hover { background: #f6f8fb; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal);
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: 0 0 auto;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.account > .meta-col {
  min-width: 0;
  flex: 1;
}
.account .name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account .note { color: var(--muted); font-size: 12px; }
.account .num {
  margin-left: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 11px 8px;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.ops tbody tr { border-top: 1px solid var(--line); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.amount { font-weight: 700; }
.amount.neg { color: var(--rose); }
.amount.pos { color: var(--teal); }

.when { white-space: nowrap; }
.when .time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}
.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2f6;
  color: var(--muted);
}
.chip.expense { background: var(--rose-soft); color: var(--rose); }
.chip.income { background: var(--teal-soft); color: var(--teal); }

.table-wrap { overflow-x: auto; }
.ops td:nth-child(4) {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.acc {
  white-space: nowrap;
}
.acc-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bank-ico {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: cover;
  flex: 0 0 auto;
  background: #eef2f6;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 51, 0.28);
  display: grid;
  place-items: center;
  z-index: 40;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: white;
  padding: 28px;
  width: min(420px, 90vw);
  border-radius: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card h2 { margin-bottom: 6px; }
.overlay-card p { margin: 0; }
.progress {
  margin: 18px 0 8px;
  height: 8px;
  background: #e6ebf1;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 4%;
  background: linear-gradient(90deg, #0f9d8a, #17324d);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.progress-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #dbe4ee;
  border-top-color: var(--teal);
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 32, 51, 0.34);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: white;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-close {
  border: 0;
  background: #eef2f6;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.modal-close:hover { color: var(--navy); }
.insights-summary {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.insights-list {
  display: grid;
  gap: 10px;
}
.insight {
  border-radius: 16px;
  padding: 12px 14px;
  background: #f6f8fb;
}
.insight.risk { background: var(--rose-soft); }
.insight.watch { background: #fff6e8; }
.insight.ok { background: var(--teal-soft); }
.insight .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.insight.risk .tag { color: var(--rose); }
.insight.watch .tag { color: #b7791f; }
.insight.ok .tag { color: var(--teal); }
.insight h4 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 800;
}
.insight p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: #40566f;
}
.insights-recs {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.insights-recs h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
}
.insights-recs ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: #40566f;
  font-size: 13px;
  line-height: 1.4;
}
.insights-recs.hidden { display: none; }

@media (max-width: 900px) {
  .nav-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  .brand { min-width: auto; }
  .periods {
    order: 3;
    width: 100%;
    margin-top: 10px;
  }
  .periods button { flex: 1; }
  .nav-right { margin-left: auto; }
  .meta { display: none; }
  .kpis, .grid { display: block; }
  .card, .kpi { margin-bottom: 12px; }
  .chart-box { height: 240px; }
  .chart-pie { height: 300px; }
}
