* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #f1f4fb;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
}

body {
  margin: 0;
  padding: 20px 14px 80px;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Inter,
    sans-serif;
  background:
    radial-gradient(1100px 500px at 8% -10%, #e0e7ff 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14.5px;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

h1 {
  font-size: clamp(20px, 3.5vw, 28px);
  margin: 0;
  letter-spacing: -0.025em;
}

header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-chip {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 99px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-ghost {
  padding: 8px 14px;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: #334155;
  transition: 0.15s;
}

.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tabs {
  display: flex;
  gap: 4px;
  background: #eef2f9;
  padding: 5px;
  border-radius: 14px;
  margin-bottom: 18px;
  overflow-x: auto;
}

.tabs button {
  flex: 1;
  min-width: 120px;
  padding: 11px 14px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  color: #475569;
  font-family: inherit;
  transition: 0.15s;
  white-space: nowrap;
}

.tabs button.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.tab {
  display: none;
}

.tab.active {
  display: block;
  animation: fade 0.22s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 12px 32px -16px rgba(15, 23, 42, 0.15);
  margin-bottom: 14px;
}

.card h2 {
  font-size: 14px;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card h2 .sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field {
  margin-bottom: 12px;
}

label.lbl {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="month"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fbfcfe;
  transition: 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: #fff;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-month {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.row-month input {
  flex: 1;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(79, 70, 229, 0.6);
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-add {
  background: #eef2ff;
  color: var(--primary);
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn-del {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  transition: 0.15s;
}

.btn-del:hover {
  background: #fef2f2;
  color: var(--red);
}

.item-row {
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}

.item-row.expense {
  grid-template-columns: 140px 1fr 130px 32px;
}

.item-row.debt {
  grid-template-columns: 1fr 120px 130px 32px;
}

@media (max-width: 620px) {
  .item-row.expense {
    grid-template-columns: 1fr 1fr 32px;
  }

  .item-row.expense select {
    grid-column: 1/-1;
  }

  .item-row.debt {
    grid-template-columns: 1fr 1fr 32px;
  }

  .item-row.debt input:nth-child(3) {
    grid-column: 1/-1;
  }
}

.empty-note {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 0;
  text-align: center;
  font-style: italic;
}

.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 700;
  padding-top: 8px;
  border-top: 1.5px dashed var(--line);
  margin-top: 6px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 720px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.kpi {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.kpi span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.kpi strong {
  font-size: 15.5px;
  letter-spacing: -0.02em;
  display: block;
}

.kpi small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.kpi.ok {
  border-color: #a7f3d0;
  background: #ecfdf5;
}

.kpi.ok strong {
  color: #047857;
}

.kpi.warn {
  border-color: #fde68a;
  background: #fffbeb;
}

.kpi.warn strong {
  color: #b45309;
}

.kpi.bad {
  border-color: #fecaca;
  background: #fef2f2;
}

.kpi.bad strong {
  color: #b91c1c;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 99px;
}

.status-badge.ok {
  background: #d1fae5;
  color: #047857;
}

.status-badge.warn {
  background: #fef3c7;
  color: #b45309;
}

.status-badge.bad {
  background: #fee2e2;
  color: #b91c1c;
}

.history-card {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  background: #fcfdff;
  transition: 0.15s;
  cursor: pointer;
}

.history-card:hover {
  border-color: #c7d2fe;
  background: #fff;
}

.history-card.active-month {
  border-color: #a5b4fc;
  background: #f5f7ff;
}

.hc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.hc-month {
  font-weight: 700;
  font-size: 14.5px;
}

.hc-tag {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
}

.hc-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  font-size: 12.5px;
}

@media (max-width: 620px) {
  .hc-metrics {
    grid-template-columns: 1fr 1fr;
  }
}

.hc-metrics > div span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.hc-metrics > div strong {
  font-size: 13px;
}

.delta {
  font-size: 11.5px;
  font-weight: 700;
  margin-left: 4px;
}

.delta.up {
  color: var(--red);
}

.delta.down {
  color: var(--green);
}

.delta.flat {
  color: var(--muted);
}

.chart-wrap {
  overflow-x: auto;
  padding: 4px 0;
}

.rec {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 9px;
  border-left: 4px solid;
  display: flex;
  gap: 11px;
  align-items: flex-start;
}

.rec.danger {
  background: #fef2f2;
  border-color: var(--red);
}

.rec.warn {
  background: #fffbeb;
  border-color: var(--amber);
}

.rec.ok {
  background: #ecfdf5;
  border-color: var(--green);
}

.rec.info {
  background: #eff6ff;
  border-color: #3b82f6;
}

.rec-icon {
  font-size: 20px;
  line-height: 1.2;
}

.rec-body h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
}

.rec-body p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: #475569;
}

.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: step;
}

.steps-list li {
  counter-increment: step;
  position: relative;
  padding: 10px 0 10px 34px;
  font-size: 13px;
  line-height: 1.55;
  border-bottom: 1px dashed var(--line);
}

.steps-list li:last-child {
  border-bottom: none;
}

.steps-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #eef2ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cat-row {
  margin-bottom: 10px;
}

.cat-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 4px;
}

.cat-head .cat-name {
  font-weight: 600;
}

.cat-head .cat-val {
  color: var(--muted);
  font-weight: 600;
}

.cat-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}

.cat-bar div {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: 0.3s;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.hint-note {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2ff;
  color: var(--primary);
}

/* Auth screen */
#authScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90vh;
  padding: 20px;
}

.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 50px -20px rgba(15, 23, 42, 0.2);
}

.auth-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.auth-card .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13.5px;
}

.auth-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #eef2f9;
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 20px;
}

.auth-toggle button {
  padding: 10px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  color: #475569;
  transition: 0.15s;
}

.auth-toggle button.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.auth-error {
  background: #fef2f2;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  margin-bottom: 12px;
  display: none;
}

.auth-info {
  background: #eff6ff;
  color: #1e40af;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  margin-bottom: 12px;
  display: none;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(241, 244, 251, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e0e7ff;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.save-indicator {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  transition: 0.2s;
  opacity: 0.7;
}

.save-indicator.saving {
  color: var(--amber);
}

.save-indicator.saved {
  color: var(--green);
}
