@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,650&family=Source+Sans+3:wght@400;500;600;700&display=swap');

:root {
  --bg: #e8e2d6;
  --bg-deep: #d4cdc0;
  --surface: rgba(252, 249, 243, 0.88);
  --ink: #1c241f;
  --ink-muted: #5a655e;
  --accent: #2d4a3e;
  --accent-soft: #3f6b58;
  --olive: #6b7c4c;
  --cost: #8b3a2f;
  --income: #2d4a3e;
  --line: rgba(28, 36, 31, 0.12);
  --shadow: 0 18px 40px rgba(28, 36, 31, 0.08);
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Source Sans 3', 'Segoe UI', sans-serif;
  --space: clamp(1rem, 2vw, 1.75rem);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(63, 107, 88, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(107, 124, 76, 0.14), transparent 50%),
    linear-gradient(165deg, #efe9dd 0%, var(--bg) 45%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

body {
  line-height: 1.45;
}

a { color: var(--accent); }

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  color: #f7f4ee;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

button:hover { background: var(--accent-soft); }
button:active { transform: translateY(1px); }
button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
button.secondary:hover { background: rgba(255,255,255,0.45); }
button.danger-outline {
  background: transparent;
  color: var(--cost);
  border-color: rgba(139, 58, 47, 0.35);
}
button.ghost {
  background: transparent;
  color: var(--ink-muted);
  border: none;
  padding: 0.35rem 0.6rem;
}
button.is-active {
  background: var(--accent);
  color: #fff;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  background: rgba(255,255,255,0.7);
  color: var(--ink);
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
}

.field { margin-bottom: 0.9rem; }

.is-neg { color: var(--cost) !important; }

/* ——— Login ——— */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(28, 36, 31, 0.35), rgba(28, 36, 31, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cpath fill='%232d4a3e' fill-opacity='0.04' d='M0 80h160M80 0v160'/%3E%3C/svg%3E");
  pointer-events: none;
}

.login-panel {
  position: relative;
  width: min(440px, 100%);
  padding: clamp(2rem, 4vw, 3rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand-mark {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 0 0 0.4rem;
  color: var(--accent);
}

.login-panel .tagline {
  margin: 0 0 1.75rem;
  color: var(--ink-muted);
  font-size: 1.05rem;
}

.login-error {
  min-height: 1.25rem;
  color: var(--cost);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.login-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ——— App shell ——— */

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space);
  display: grid;
  gap: 1.25rem;
  animation: rise 0.45s ease both;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: end;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.topbar-left h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.75rem);
  margin: 0;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.top-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.35rem;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.topbar-right {
  text-align: right;
}

.cash {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1;
  margin: 0;
}

.pnl {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 0.45rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.pnl strong { color: var(--ink); font-weight: 600; }

.user-row {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  flex-wrap: wrap;
}

.scenario-chip {
  font-weight: 600;
  color: var(--ink);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-load select {
  width: auto;
  min-width: 9rem;
  max-width: 14rem;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.time-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.85rem 1rem;
  align-items: center;
}

.step-toggle {
  display: flex;
  gap: 0.3rem;
}

.step-toggle button {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.step-toggle button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.slider-wrap {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: center;
  min-width: 0;
}

.slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  padding: 0;
  border: none;
  background: transparent;
}

.slider-bound {
  font-size: 0.8rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.slider-current {
  font-size: 0.95rem;
  min-width: 7.5rem;
  text-align: right;
}

@media (max-width: 960px) {
  .time-bar {
    grid-template-columns: 1fr;
  }
  .slider-current {
    text-align: left;
  }
}

.status-msg {
  font-size: 0.85rem;
  color: var(--ink-muted);
  min-height: 1.2rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: 1fr; }
  .topbar-right, .pnl, .user-row { text-align: left; justify-content: flex-start; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  backdrop-filter: blur(8px);
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 0 0 0.85rem;
  font-weight: 650;
}

.chart-wrap {
  margin-bottom: 1.25rem;
}

.chart-wrap canvas {
  width: 100%;
  height: 180px;
  display: block;
  background: rgba(255,255,255,0.35);
  border-radius: 10px;
}

.chart-dates {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.start-date-field {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  color: var(--ink-muted);
  font-weight: 400;
  margin: 0;
}

.start-date-field input {
  width: auto;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
}

.ledger {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ledger-row, .rule-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.ledger-row .meta, .rule-item .meta {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.15rem;
}

.ledger-row .amt, .rule-item .amt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.ledger-row.income .amt, .rule-item.income .amt { color: var(--income); }
.ledger-row.cost .amt, .rule-item.cost .amt { color: var(--cost); }

.empty {
  color: var(--ink-muted);
  padding: 0.75rem 0;
  list-style: none;
}

.side-stack {
  display: grid;
  gap: 1rem;
}

.side-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.side-actions button { flex: 1; }

#rooms-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#rooms-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}

#rooms-list .room-type {
  display: block;
  color: var(--ink-muted);
  font-size: 0.85rem;
  text-transform: capitalize;
}

.danger-text {
  color: var(--cost) !important;
}

.filters {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.filters button {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.filters button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#rules-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 420px;
  overflow: auto;
}

.rule-item.is-off { opacity: 0.45; }

.rule-actions {
  display: flex;
  gap: 0.25rem;
}

.rule-actions button {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
}

.rule-actions button.danger {
  color: var(--cost);
  border-color: rgba(139, 58, 47, 0.3);
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin: 1.1rem 0 0.35rem;
}

/* Modal */

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(28, 36, 31, 0.35);
  backdrop-filter: blur(3px);
}

.modal-panel {
  width: min(480px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fcf9f3;
  border-radius: 18px;
  padding: 1.35rem 1.4rem 1.2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: rise 0.25s ease both;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
}
