:root {
  --paper: #fbf8f0;
  --paper-line: #cfe0ef;
  --margin-red: #e3a9a9;
  --ink: #2b2b2b;
  --ink-soft: #5b5b5b;
  --accent: #2f5da8;
  --accent-dark: #204480;
  --good: #2e7d32;
  --bad: #c62828;
  --border: #d8cdb8;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #e9e2d0;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(0,0,0,0.02), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(0,0,0,0.02), transparent 40%);
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  padding: 20px 0 60px;
}

.hidden { display: none !important; }

.page { width: 100%; display: flex; justify-content: center; }

.notebook {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 16px;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18), 0 1px 0 rgba(255,255,255,0.4) inset;
  overflow: hidden;
  overflow: clip; /* clip (not hidden) lets the menu bar stay in view while scrolling */
}

.login-notebook { max-width: 420px; }

.spiral {
  height: 14px;
  background: repeating-linear-gradient(90deg, #b9b2a0 0 8px, transparent 8px 20px);
  border-bottom: 1px solid #cbc2ab;
}

.page-inner {
  padding: 28px 26px 40px 54px;
  position: relative;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 33px,
    var(--paper-line) 34px
  );
  background-position: 0 90px;
}

.page-inner::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 32px;
  width: 2px;
  background: var(--margin-red);
  opacity: 0.55;
}

.login-inner { padding: 32px 30px 40px; background-image: none; }
.login-inner::before { display: none; }

.brand {
  font-family: 'Kalam', cursive;
  font-size: 1.7rem;
  margin: 4px 0 0;
  color: var(--accent-dark);
}
.brand.small { font-size: 1.3rem; }
.brand-sub {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}
.ruled-gap { height: 20px; }

.field-label {
  display: block;
  font-family: 'Kalam', cursive;
  font-size: 1.05rem;
  margin: 18px 0 8px;
  color: var(--ink-soft);
}

.pin-input {
  width: 100%;
  font-size: 1.6rem;
  letter-spacing: 10px;
  text-align: center;
  padding: 12px 10px;
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
}
.pin-input:focus { outline: none; border-bottom-color: var(--accent-dark); }

.btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-block { width: 100%; margin-top: 18px; padding: 13px; font-size: 1rem; }
.btn-small { padding: 6px 10px; font-size: 0.8rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-dark); text-decoration: underline; }

.msg {
  min-height: 20px;
  font-size: 0.88rem;
  margin-top: 10px;
  font-weight: 700;
}
.msg.error { color: var(--bad); }
.msg.success { color: var(--good); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 6px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.role-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.role-badge.edit { background: var(--good); }

.section-title {
  font-family: 'Kalam', cursive;
  font-size: 1.3rem;
  color: var(--accent-dark);
  margin: 28px 0 14px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 6px;
}

.entry-form { display: flex; flex-direction: column; }
.form-line {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}
.form-line label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.form-line label .hint { font-weight: 400; font-style: italic; color: #8a8a8a; }
.form-line input,
.form-line select {
  padding: 9px 10px;
  border: none;
  border-bottom: 1.5px solid var(--paper-line);
  background: transparent;
  font-size: 1rem;
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
}
.form-line input:focus,
.form-line select:focus { outline: none; border-bottom-color: var(--accent); }

.name-row { display: flex; gap: 8px; align-items: center; }
.name-row select { flex: 1; }

.new-emp-box {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 10px;
  background: rgba(47,93,168,0.06);
  border-radius: 6px;
}
.new-emp-box input,
.new-emp-box select { flex: 1; min-width: 120px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }

.remaining-line { background: rgba(46,125,50,0.08); border-radius: 6px; padding: 10px 12px; }
.remaining-value { font-size: 1.4rem; font-weight: 800; color: var(--good); font-family: 'Kalam', cursive; }

.balances-list, .records-list { display: flex; flex-direction: column; gap: 0; }

.balance-row, .record-card {
  border-bottom: 1px solid var(--paper-line);
  padding: 12px 4px;
}
.balance-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.balance-name { font-weight: 700; }
.balance-cat { font-size: 0.75rem; color: var(--ink-soft); }
.balance-amt { font-weight: 800; font-family: 'Kalam', cursive; font-size: 1.1rem; }
.balance-amt.zero { color: var(--ink-soft); }
.balance-amt.owed { color: var(--bad); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.filter-row select, .filter-row input {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
  font-size: 0.85rem;
  flex: 1 1 130px;
}

.record-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
  padding: 14px 6px;
}
.record-card.editing { background: rgba(47,93,168,0.05); border-radius: 6px; }
.rc-field { display: flex; justify-content: space-between; border-bottom: 1px dotted #d8cfb8; padding: 2px 0; font-size: 0.88rem; }
.rc-field .rc-label { color: var(--ink-soft); }
.rc-field .rc-val { font-weight: 700; }
.rc-field.full { grid-column: 1 / -1; }
.rc-remaining .rc-val { color: var(--good); font-weight: 800; }
.rc-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 8px; }

.edit-inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; grid-column: 1 / -1; }
.edit-inline-form label { font-size: 0.75rem; color: var(--ink-soft); display: block; }
.edit-inline-form input, .edit-inline-form select { width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.edit-inline-form .full { grid-column: 1 / -1; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-box {
  background: var(--paper); border-radius: 8px; padding: 24px; width: 100%; max-width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.modal-box h3 { font-family: 'Kalam', cursive; margin-top: 0; }
.modal-box input {
  width: 100%; font-size: 1.4rem; letter-spacing: 8px; text-align: center;
  padding: 10px; border: none; border-bottom: 2px solid var(--accent); margin-top: 8px; background: transparent;
}
.modal-box input:focus { outline: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.type-btn {
  flex: 1;
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 6px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.type-btn.active { background: var(--accent); border-color: var(--accent-dark); color: #fff; }

.overview-list { display: flex; flex-direction: column; gap: 0; }
.overview-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px dotted var(--paper-line);
  font-size: 0.9rem;
}
.overview-row .ov-label { color: var(--ink-soft); font-weight: 700; }
.overview-row .ov-val { font-family: 'Kalam', cursive; font-size: 1.15rem; font-weight: 800; }
.overview-row .ov-val.out { color: var(--bad); }
.overview-row .ov-val.in { color: var(--good); }

.entry-type-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 12px;
  margin-bottom: 6px;
}
.entry-type-badge.expense { background: #fde3e3; color: var(--bad); }
.entry-type-badge.party_payment { background: #fde3e3; color: var(--bad); }
.entry-type-badge.money_out { background: #fde3e3; color: var(--bad); }
.entry-type-badge.money_in { background: #ddf1de; color: var(--good); }
.entry-type-badge.employee { background: #dde8fb; color: var(--accent-dark); }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.dash-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.dash-card .dash-label { font-size: 0.72rem; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.dash-card .dash-val { font-family: 'Kalam', cursive; font-size: 1.3rem; font-weight: 800; margin-top: 4px; }
.dash-card .dash-val.out { color: var(--bad); }
.dash-card .dash-val.in { color: var(--good); }
.dash-card.wide { grid-column: 1 / -1; }

.sub-toggle { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.party-row, .account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--paper-line);
  padding: 12px 4px;
}
.party-name, .account-name { font-weight: 700; }
.party-type, .account-type { font-size: 0.75rem; color: var(--ink-soft); text-transform: capitalize; }
.party-amt, .account-amt { font-weight: 800; font-family: 'Kalam', cursive; font-size: 1.1rem; }
.party-amt.receivable { color: var(--good); }
.party-amt.payable { color: var(--bad); }
.party-amt.settled { color: var(--ink-soft); }

.attach-list { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(47,93,168,0.08); border-radius: 12px; padding: 3px 8px; font-size: 0.78rem;
}
.attach-chip a { color: var(--accent-dark); text-decoration: none; }
.attach-chip a:hover { text-decoration: underline; }
.attach-del { border: none; background: none; color: var(--bad); cursor: pointer; font-weight: 800; padding: 0 2px; }

@media (max-width: 480px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .record-card { grid-template-columns: 1fr; }
  .edit-inline-form { grid-template-columns: 1fr; }
  .page-inner { padding: 22px 16px 32px 38px; }
  .page-inner::before { left: 20px; }
}


/* ---------- Phase 3: search and reports ---------- */
.rp-lbl { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--ink-soft); flex: 1 1 150px; }
.rp-lbl input { flex: 1; }
.rp-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0 12px; }
.rp-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.rp-card .l { font-size: 0.68rem; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.rp-card .v { font-family: 'Kalam', cursive; font-size: 1.15rem; font-weight: 800; }
.rp-title { font-family: 'Kalam', cursive; font-size: 1.15rem; color: var(--accent-dark); margin: 6px 0 0; }
.rp-sub { font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 4px; }
.rp-wrap { overflow-x: auto; margin: 6px -4px 0; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.rp-table { border-collapse: collapse; width: 100%; font-size: 0.78rem; min-width: 540px; }
.rp-table th { background: #e8eef8; text-align: left; padding: 7px 7px; font-weight: 800; border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.rp-table td { padding: 6px 7px; border-bottom: 1px dotted var(--paper-line); vertical-align: top; }
.rp-table td.nw { white-space: nowrap; }
.rp-table th.num, .rp-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rp-table td.in { color: var(--good); }
.rp-table td.out { color: var(--bad); }
.rp-table td.bal { font-weight: 700; }
.rp-table td.wrap { min-width: 110px; overflow-wrap: anywhere; }
.rp-table tr.opening td, .rp-table tr.closing td { background: rgba(47,93,168,0.07); font-weight: 800; }
.rp-table tr.total td { font-weight: 800; border-top: 2px solid var(--ink-soft); background: #fbf8f0; }
.rp-notes { font-size: 0.75rem; color: var(--ink-soft); font-style: italic; margin: 8px 2px 0; padding-left: 16px; }
.rp-empty { color: var(--ink-soft); padding: 16px 6px; font-style: italic; }
.gs-group { margin-top: 12px; }
.gs-group h3 { font-family: 'Kalam', cursive; font-size: 1rem; color: var(--accent-dark); margin: 0 0 4px; }
.gs-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--paper-line); font-size: 0.85rem; }
.gs-item.click { cursor: pointer; }
.gs-item.click:hover { background: rgba(47,93,168,0.06); }
.gs-main { min-width: 0; }
.gs-title { font-weight: 700; }
.gs-sub { color: var(--ink-soft); font-size: 0.75rem; overflow-wrap: anywhere; }
.gs-right { text-align: right; white-space: nowrap; }
.gs-amt { font-family: 'Kalam', cursive; font-weight: 800; }
.gs-date { font-size: 0.72rem; color: var(--ink-soft); }
.gs-more { font-size: 0.75rem; color: var(--ink-soft); font-style: italic; padding: 4px; }

.rp-swipe { display: none; font-size: 0.72rem; color: var(--ink-soft); margin: 4px 2px 0; }
@media (max-width: 600px) { .rp-swipe { display: block; } }

.due-badge { display: inline-block; font-family: 'Nunito', sans-serif; font-size: 0.72rem; font-weight: 800; border-radius: 12px; padding: 2px 9px; margin-left: 8px; vertical-align: middle; color: #fff; }
.due-badge.bad { background: var(--bad); }
.due-badge.soon { background: #e08a00; }

.due-list { margin-top: 4px; }
.due-item { display: flex; justify-content: space-between; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--paper-line); font-size: 0.85rem; border-left: 4px solid transparent; padding-left: 8px; }
.due-item.od { border-left-color: var(--bad); }
.due-item.td { border-left-color: #e08a00; }
.due-item.soon { border-left-color: var(--border); }
.due-when { font-size: 0.76rem; font-weight: 800; }
.due-item.od .due-when { color: var(--bad); }
.due-item.td .due-when { color: #c27200; }
.due-item.soon .due-when { color: var(--ink-soft); }
.due-check { font-size: 0.74rem; color: #a15c00; font-style: italic; margin-top: 2px; overflow-wrap: anywhere; }
.due-total { text-align: right; font-weight: 800; font-family: 'Kalam', cursive; padding: 8px 4px 0; }

/* ---------- Phase 5: separate pages ---------- */
.pg-hidden { display: none !important; }
#pageNav {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 2px; margin: 0 0 6px;
  position: sticky; top: 0; z-index: 30; background: var(--paper); border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
#pageNav::-webkit-scrollbar { display: none; }
.pn-chip {
  flex: 0 0 auto; position: relative; border: 1px solid var(--border); background: #fff; color: var(--ink);
  border-radius: 16px; padding: 7px 7px; font: inherit; font-size: 0.76rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.pn-chip:hover { border-color: var(--accent); }
.pn-chip.on { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
.pn-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 10px; font-size: 0.68rem; font-weight: 800;
  line-height: 18px; text-align: center; color: #fff; vertical-align: middle;
}
.pn-badge.bad { background: var(--bad); }
.pn-badge.soon { background: #e08a00; }
.pn-badge.hidden { display: none; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.tile {
  display: flex; align-items: center; gap: 10px; text-align: left; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; cursor: pointer; font: inherit; color: var(--ink);
}
.tile:hover { border-color: var(--accent); background: #fdfcf8; }
.tile .t-ic { font-size: 1.5rem; flex: 0 0 auto; }
.tile .t-tx { min-width: 0; flex: 1; }
.tile b { display: block; font-size: 0.9rem; }
.tile small { display: block; color: var(--ink-soft); font-size: 0.72rem; line-height: 1.25; }
#dueSection, #reportsSection { scroll-margin-top: 64px; }

html { scroll-padding-top: 64px; } /* keeps anything scrolled into view from hiding under the menu bar */
