@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Work+Sans:wght@400;500;600&display=swap');

:root {
  --ink: #22291F;
  --paper: #F6F3EC;
  --paper-2: #ECE7DA;
  --line: #DAD3C0;
  --moss: #4B6350;
  --moss-dark: #384B3D;
  --clay: #B5652D;
  --violet: #6E6499;
  --rose: #9C3B34;
  --muted: #7B7566;
  --radius: 6px;
}

* { box-sizing: border-box; }

/* Author rules below set `display` on several elements that also get toggled
   via the `hidden` attribute (login/app shells, nav items). Without this,
   the browser's default `[hidden] { display: none }` loses to those rules,
   since author stylesheets always beat the user-agent stylesheet at equal
   importance - so `hidden` silently stops hiding anything. Force it to win. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: 'Work Sans', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Fraunces', serif; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 0.95rem;
}

a { color: var(--moss-dark); }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, transparent 39px, var(--line) 40px) 0 0/100% 40px,
    var(--paper);
}

.login-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 360px;
}

.login-mark {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem;
  font-optical-sizing: auto;
  margin-bottom: 0.15rem;
}

.login-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

.field { margin-bottom: 1.1rem; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--moss);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.6rem 1.1rem;
  font-weight: 500;
  background: var(--moss);
  color: #fff;
  width: 100%;
}
.btn:hover { background: var(--moss-dark); }
.btn.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  width: auto;
}
.btn.secondary:hover { background: var(--paper-2); }
.btn.danger { background: var(--rose); }
.btn.small { width: auto; padding: 0.4rem 0.75rem; font-size: 0.85rem; }

.error-text { color: var(--rose); font-size: 0.85rem; margin-top: 0.75rem; min-height: 1em; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 1.25rem; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 1.5rem 1.1rem;
  display: flex;
  flex-direction: column;
}
.sidebar .mark {
  font-family: 'Fraunces', serif;
  font-size: 1.25rem;
  margin-bottom: 0.15rem;
}
.sidebar .who { color: #A9A594; font-size: 0.78rem; margin-bottom: 2rem; }
.nav-item {
  display: block;
  padding: 0.55rem 0.6rem;
  border-radius: 4px;
  color: #D8D4C6;
  text-decoration: none;
  font-size: 0.92rem;
  margin-bottom: 0.15rem;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: #2E3628; }
.nav-item.active { color: #fff; background: #333D2B; border-left-color: var(--clay); }
.sidebar-footer { margin-top: auto; }
.sidebar-footer button {
  background: none;
  border: 1px solid #454B3C;
  color: #D8D4C6;
  padding: 0.5rem 0.7rem;
  border-radius: 4px;
  width: 100%;
}
.sidebar-footer button:hover { background: #2E3628; }

.main {
  flex: 1;
  padding: 2.25rem 2.75rem;
  max-width: 980px;
}

.page-head { margin-bottom: 1.75rem; }
.page-head h1 { font-size: 1.7rem; }
.page-head p { color: var(--muted); margin-top: 0.35rem; }

/* ---------- Cards / balances ---------- */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2.25rem;
}
.balance-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  background: #fff;
  border-left: 3px solid var(--moss);
}
.balance-card .type-name { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }
.balance-card .amounts { display: flex; align-items: baseline; gap: 0.3rem; }
.balance-card .remaining { font-family: 'Fraunces', serif; font-size: 1.9rem; }
.balance-card .of-total { font-size: 0.85rem; color: var(--muted); }
.balance-card .sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }

/* ---------- Tables ---------- */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  text-align: left;
  padding: 0.7rem 0.9rem;
  background: var(--paper-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FBFAF6; }

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 500;
}
.pill.pending { background: #F2E3D2; color: #7A4A16; }
.pill.approved { background: #DEE7DE; color: var(--moss-dark); }
.pill.rejected { background: #F1DAD8; color: var(--rose); }
.pill.cancelled { background: #EDEBE4; color: var(--muted); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
  font-size: 0.9rem;
}

/* ---------- Forms / sections ---------- */
.section { margin-bottom: 2.25rem; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}
.section-head h2 { font-size: 1.15rem; }

.card-form {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 1.4rem 1.5rem;
  max-width: 480px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }

.tabs { display: flex; gap: 0.4rem; margin-bottom: 1.25rem; }
.tab {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  color: var(--muted);
  font-size: 0.85rem;
}
.tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(34, 41, 31, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.6rem 1.7rem;
  width: 100%;
  max-width: 420px;
}
.modal h3 { margin-bottom: 1.2rem; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.1rem;
  border-radius: 4px;
  font-size: 0.88rem;
  z-index: 100;
}

.text-btn {
  background: none;
  border: none;
  color: var(--moss-dark);
  font-size: 0.85rem;
  padding: 0;
  text-decoration: underline;
}
.text-btn.danger { color: var(--rose); }

.sidebar-footer button + button {
  margin-top: 0.4rem;
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 1rem; overflow-x: auto; }
  .sidebar .who, .sidebar-footer { display: none; }
  .main { padding: 1.5rem 1.25rem; }
  .row-2 { grid-template-columns: 1fr; }
}

.preview-box {
  border: 1px solid var(--line);
  border-left: 3px solid var(--moss);
  border-radius: 4px;
  padding: 0.7rem 0.9rem;
  background: var(--paper-2);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.preview-box strong { font-size: 1rem; }
.preview-box .warn { color: var(--rose); }