:root {
  --bg: #eef5ff;
  --bg-2: #f8fafc;
  --panel: rgba(255, 255, 255, .88);
  --panel-2: rgba(255, 255, 255, .96);
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, .12);
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #e11d48;
  --red-soft: #ffe4e6;
  --yellow: #b45309;
  --yellow-soft: #fef3c7;
  --shadow: 0 20px 60px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.13), transparent 34%),
    radial-gradient(circle at bottom right, rgba(5,150,105,.11), transparent 32%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

a { color: inherit; text-decoration: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.container {
  width: min(1180px, calc(100% - 28px));
  margin: 24px auto 60px;
}

.topbar {
  width: min(1180px, calc(100% - 28px));
  margin: 18px auto 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(16px);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  box-shadow: var(--shadow);
}

.brand { font-size: 21px; font-weight: 900; color: #0f172a; }

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

nav a {
  padding: 10px 12px;
  border-radius: 12px;
  color: #334155;
  transition: .18s ease;
  font-weight: 700;
}

nav a:hover, nav a.active {
  background: var(--blue-soft);
  color: var(--blue);
  transform: translateY(-1px);
}

.logout-form { margin: 0; }
.logout-form input { display: none; }
.logout-form button {
  width: auto;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  color: #334155;
  background: transparent;
  box-shadow: none;
  font-weight: 700;
}
.logout-form button:hover {
  background: var(--blue-soft);
  color: var(--blue);
  transform: translateY(-1px);
}

.card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(14px);
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  padding: 28px;
}

.logo-circle {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: white;
  font-size: 28px;
  font-weight: 900;
  margin-bottom: 12px;
}

h1, h2, h3 { margin: 0 0 10px; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.form {
  display: grid;
  gap: 10px;
}

.form label {
  color: #334155;
  font-weight: 500;
  font-size: 14px;
  margin-top: 4px;
}

input, select, textarea, button {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  font: inherit;
  outline: none;
}

input, select, textarea {
  background: #ffffff;
  color: var(--text);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(37,99,235,.75);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

button {
  cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  font-weight: 900;
  border: none;
  transition: .18s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

button.ghost {
  background: #ffffff;
  border: 1px solid var(--line);
}

.danger-btn { color: var(--red); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

.form-row > div { min-width: 0; }

.field-error {
  color: var(--red);
  font-size: 13px;
  margin-top: -4px;
}

.flash {
  padding: 12px 14px;
  border-radius: 14px;
  margin: 12px 0;
  border: 1px solid var(--line);
  font-weight: 700;
}
.flash.success { background: var(--green-soft); color: #065f46; }
.flash.error { background: var(--red-soft); color: #9f1239; }

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: var(--blue);
  font-weight: 500;
}

.month-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  text-align: center;
  margin-bottom: 18px;
}

.month-panel a {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat {
  display: grid;
  gap: 9px;
}

.stat span {
  color: var(--muted);
  font-weight: 500;
}

.stat strong {
  font-size: clamp(27px, 3vw, 38px);
  letter-spacing: -.03em;
}

.stat small {
  color: #334155;
  font-size: 15.5px;
  font-weight: 500;
  line-height: 1.35;
}

.stat.positive strong { color: var(--green); }
.stat.danger strong { color: var(--red); }
.stat.warning strong { color: var(--yellow); }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.plan-card {
  margin-bottom: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(239,246,255,.92));
}

.plan-list {
  display: grid;
  gap: 12px;
}

.plan-item {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 15px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: white;
}

.plan-item.income { border-left: 5px solid var(--green); }
.plan-item.expense { border-left: 5px solid var(--red); }
.plan-item.credit { border-left: 5px solid var(--yellow); }

.plan-date {
  display: grid;
  gap: 4px;
}

.plan-date strong {
  font-size: 18px;
}

.plan-date span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.plan-main p {
  margin: 4px 0 0;
  color: var(--muted);
}

.plan-amount {
  font-size: 20px;
  font-weight: 900;
  white-space: nowrap;
}

.plan-item.income .plan-amount { color: var(--green); }
.plan-item.expense .plan-amount, .plan-item.credit .plan-amount { color: var(--red); }

.timeline {
  display: grid;
  gap: 10px;
}

.event-row, .list-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}

.event-row p, .list-item p { margin: 4px 0 0; color: var(--muted); }

.date {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
}

.event-row.income strong { color: var(--green); }
.event-row.expense strong, .event-row.credit strong { color: var(--red); }

.hint {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  font-weight: 700;
}

.hint.good { background: var(--green-soft); color: #065f46; }
.hint.bad { background: var(--red-soft); color: #9f1239; }

.big-line {
  font-size: 18px;
  color: #334155;
  font-weight: 700;
}

.big-line b {
  font-size: 22px;
  color: #0f172a;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.week {
  color: var(--muted);
  font-weight: 900;
  text-align: center;
  padding: 6px;
}

.day {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: white;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day.empty {
  opacity: .35;
  background: rgba(255,255,255,.55);
}

.pill {
  display: inline-block;
  padding: 5px 7px;
  border-radius: 999px;
  font-size: 12px;
  width: fit-content;
  font-weight: 900;
}

.pill.income { background: var(--green-soft); color: #047857; }
.pill.expense, .pill.credit { background: var(--red-soft); color: #be123c; }

.credit-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  margin-bottom: 12px;
}

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

.credit-head p { margin: 4px 0 0; color: var(--muted); }

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  color: #334155;
}

.fade-in {
  animation: fadeIn .28s ease both;
}

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

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  nav { justify-content: flex-start; }
  .stats-grid, .grid-2 { grid-template-columns: 1fr; }
  .calendar { gap: 6px; }
  .day { min-height: 86px; padding: 7px; }
  .month-panel { flex-direction: column; }
  .plan-item {
    grid-template-columns: 1fr;
  }
  .plan-amount {
    font-size: 22px;
  }
}

@media (max-width: 560px) {
  .container { width: min(100% - 18px, 1180px); }
  .topbar { width: min(100% - 18px, 1180px); }
  .card, .auth-card { padding: 16px; border-radius: 20px; }
  .form-row { grid-template-columns: 1fr; }
  .event-row, .list-item { grid-template-columns: 1fr; }
  .calendar {
    grid-template-columns: repeat(7, minmax(38px, 1fr));
    overflow-x: auto;
  }
  .day {
    min-width: 42px;
    min-height: 74px;
    font-size: 12px;
  }
  .pill {
    font-size: 10px;
    padding: 4px 5px;
  }
}


/* Past events accordion */
.past-box{
  margin-top:24px;
  border:1px solid var(--line);
  border-radius:18px;
  overflow:hidden;
  background:linear-gradient(180deg,#fff,#fafcff);
}
.past-box summary{
  list-style:none;
  cursor:pointer;
  padding:18px 20px;
  font-weight:700;
  display:flex;
  align-items:center;
  justify-content:space-between;
  transition:all .25s ease;
}
.past-box summary::-webkit-details-marker{display:none;}
.past-box summary::after{
 content:"+";
 font-size:24px;
 transition:transform .25s ease;
 opacity:.7;
}
.past-box[open] summary::after{transform:rotate(45deg);}
.past-box summary:hover{background:rgba(0,0,0,.03);}
.past-box .plan-list{
 padding:0 16px 16px;
 animation:accordionDrop .28s ease;
}
@keyframes accordionDrop{
 from{opacity:0; transform:translateY(-8px)}
 to{opacity:1; transform:translateY(0)}
}
