/* GhostBudget — haunted mansion theme. Dark, gothic, but always readable.
   System font stacks only: the app must work fully offline (PWA). */
:root {
  --bg: #0d0a14;
  --bg-2: #14101f;
  --card: #1a1428;
  --card-2: #211a33;
  --line: #332a4d;
  --text: #efeaf7;
  --muted: #a99dc4;
  --violet: #8b5cf6;
  --violet-soft: #b79cfa;
  --pumpkin: #f97316;
  --pumpkin-soft: #fdba74;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* The overlay/toast use the `hidden` attribute; without this, their
   `display` rules would override it and they would block the page. */
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(139, 92, 246, .18), transparent),
    radial-gradient(ellipse 60% 30% at 90% 0%, rgba(249, 115, 22, .08), transparent);
  background-attachment: fixed;
}

h1, h2, h3 {
  font-family: Palatino, "Palatino Linotype", Georgia, "Times New Roman", serif;
  letter-spacing: .04em;
  margin: 0 0 .5rem;
}

h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; color: var(--violet-soft); }
p { margin: .25rem 0 .75rem; }

a { color: var(--violet-soft); }

/* ---------- header ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(13, 10, 20, .85);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: .8rem; }
.ghost-logo { width: 46px; height: 46px; animation: float 4s ease-in-out infinite; }
.tagline { color: var(--muted); margin: 0; font-size: .9rem; font-style: italic; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.top-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.currency-label { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .4rem; }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  padding: .5rem .9rem;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
}
.btn:hover { border-color: var(--violet); }
.btn-primary {
  background: var(--violet);
  border-color: var(--violet);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #7c4dff; }
.btn-ghost { background: transparent; }
.btn-danger {
  background: transparent;
  border-color: #5b2333;
  color: var(--red);
}
.btn-danger:hover { border-color: var(--red); }

select, input[type="number"], input[type="text"], input[type="date"], input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .6rem;
  width: 100%;
}
select:focus, input:focus { outline: 2px solid var(--violet); outline-offset: 1px; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  padding: .8rem clamp(1rem, 4vw, 2.5rem) 0;
}
.tab {
  font: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: .55rem 1rem;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--card);
  color: var(--text);
  border-color: var(--line);
  font-weight: 600;
}
.badge {
  background: var(--pumpkin);
  color: #1a1005;
  border-radius: 999px;
  padding: 0 .45rem;
  font-size: .75rem;
  font-weight: 700;
  margin-left: .25rem;
}

/* ---------- layout ---------- */
main { padding: 0 clamp(1rem, 4vw, 2.5rem) 2rem; max-width: 1100px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-top: 1rem;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.card-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.big-number { display: block; font-size: 1.9rem; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.big-number .per { font-size: 1rem; color: var(--muted); }
.income { color: var(--green); }
.expense { color: var(--pumpkin-soft); }
.ghost { color: var(--violet-soft); }
.card-sub { color: var(--muted); font-size: .88rem; }
.haunt-card { border-color: #4c2a6d; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: .9rem; }
.form-error { color: var(--red); font-size: .9rem; margin: .5rem 0 0; }

/* ---------- forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .8rem;
  align-items: end;
}
.span-2 { grid-column: span 2; }
@media (max-width: 520px) { .span-2 { grid-column: span 1; } }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: .8rem; }
.filters select, .filters input { width: auto; flex: 1 1 160px; }

/* ---------- lists ---------- */
.tx-list, .ghost-list, .legend { list-style: none; margin: 0; padding: 0; }
.tx-list li, .ghost-list li {
  display: flex;
  gap: .8rem;
  align-items: center;
  padding: .65rem .2rem;
  border-bottom: 1px solid var(--line);
}
.tx-list li:last-child, .ghost-list li:last-child { border-bottom: none; }
.tx-icon, .ghost-icon {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  background: var(--card-2);
  border: 1px solid var(--line);
}
.tx-main, .ghost-main { flex: 1 1 auto; min-width: 0; }
.tx-note, .ghost-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta, .ghost-meta { color: var(--muted); font-size: .85rem; }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--pumpkin-soft); }
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; cursor: pointer; padding: .3rem .55rem; font: inherit;
}
.icon-btn:hover { color: var(--red); border-color: var(--red); }
.ghost-item { border: 1px solid #4c2a6d; border-radius: 12px; padding: .8rem; margin-bottom: .7rem; background: var(--bg-2); }
.ghost-item.charging-soon { border-color: var(--amber); box-shadow: 0 0 14px rgba(251, 191, 36, .18); }
.soon-tag { color: var(--amber); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.ghost-item.banished { border-color: var(--line); opacity: .75; }
.ghost-cost { text-align: right; }
.ghost-cost strong { display: block; font-variant-numeric: tabular-nums; }
.saved { color: var(--green); font-size: .85rem; }

/* ---------- charts ---------- */
.donut-wrap { display: flex; justify-content: center; }
.legend li { display: flex; gap: .5rem; align-items: center; padding: .2rem 0; font-size: .92rem; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.legend .legend-amount { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars-wrap svg { width: 100%; height: auto; display: block; }

/* ---------- ghost meter ---------- */
.ghost-meter {
  height: 14px; border-radius: 999px; background: var(--bg-2);
  border: 1px solid var(--line); overflow: hidden; margin: .6rem 0 .3rem;
}
.ghost-meter-fill {
  height: 100%; background: linear-gradient(90deg, var(--violet), var(--pumpkin));
  transition: width .5s ease;
}
.ghost-meter-label { color: var(--muted); font-size: .92rem; }
.ghost-intro p { max-width: 70ch; }

/* ---------- mansion rooms ---------- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.room {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.room h3 { color: var(--text); }
.room .room-name { color: var(--muted); font-size: .85rem; margin-top: -.4rem; }
.room .bar { height: 10px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); overflow: hidden; margin: .5rem 0 .3rem; }
.room .bar-fill { height: 100%; transition: width .4s ease; }
.room.calm .bar-fill { background: var(--green); }
.room.stirring .bar-fill { background: var(--amber); }
.room.possessed { border-color: #7f1d1d; box-shadow: 0 0 18px rgba(248, 113, 113, .25); }
.room.possessed .bar-fill { background: var(--red); }
.room .room-numbers { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.room .room-status { font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }
.room.calm .room-status { color: var(--green); }
.room.stirring .room-status { color: var(--amber); }
.room.possessed .room-status { color: var(--red); }
.room .budget-edit { display: flex; gap: .5rem; margin-top: .7rem; }
.room .budget-edit input { flex: 1; }

/* ---------- footer / toast / dialog ---------- */
footer {
  max-width: 1100px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem) 2rem;
  color: var(--muted); font-size: .88rem;
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
}
.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--violet);
  color: var(--text); border-radius: 10px; padding: .7rem 1.1rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5); z-index: 50; max-width: 90vw;
}
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .65);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem;
}
.dialog {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.4rem; max-width: 420px; width: 100%;
}
.dialog-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.exorcised { animation: banish .6s ease forwards; }
@keyframes banish {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(1.04) rotate(-1deg); }
  100% { opacity: 0; transform: scale(.9) translateY(-8px); }
}
