/* SafeShift Cash Book
   Design intent: a tool touched fifty times a day. Density and keyboard
   flow over decoration. Green = money in, rust = money out, orange only
   ever means "this button commits money to the books". */

:root {
  --ink:        #16202B;
  --ink-soft:   #33414F;
  --muted:      #6B7785;
  --paper:      #FFFFFF;
  --wash:       #F3F5F7;
  --rule:       #DBE1E7;
  --rule-soft:  #EDF0F3;

  --credit:     #0E7A4D;
  --credit-bg:  #E7F4EE;
  --debit:      #B3261E;
  --debit-bg:   #FBEAE9;
  --accent:     #E07B23;
  --accent-ink: #8A4408;

  --r: 5px;
  --shadow: 0 1px 2px rgba(22,32,43,.07), 0 4px 12px rgba(22,32,43,.05);

  --num: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: var(--ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--wash);
  -webkit-text-size-adjust: 100%;
}

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; gap: 18px;
  background: var(--ink); color: #fff;
  padding: 0 16px; height: 48px;
  position: sticky; top: 0; z-index: 40;
}
.topbar .brand {
  font-weight: 600; letter-spacing: .04em;
  font-size: 13px; text-transform: uppercase;
}
.topbar nav { display: flex; gap: 4px; margin-left: 8px; }
.topbar nav a {
  color: #C4CDD6; text-decoration: none;
  padding: 6px 11px; border-radius: var(--r); font-size: 13px;
}
.topbar nav a:hover { background: rgba(255,255,255,.10); color: #fff; }
.topbar nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; color: #9BA8B4; }
.topbar .who a { color: #C4CDD6; }

.wrap { max-width: 1240px; margin: 18px auto 60px; padding: 0 16px; }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 11px 14px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 12px;
}
.card-head h2 {
  margin: 0; font-size: 12px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.card-body { padding: 14px; }

/* ---------- the signature: projected balance ---------- */

.proj {
  display: flex; align-items: stretch; gap: 0;
  border: 1px solid var(--rule); border-radius: var(--r);
  overflow: hidden; background: var(--paper);
}
.proj-cell { padding: 10px 16px; flex: 1; border-right: 1px solid var(--rule-soft); }
.proj-cell:last-child { border-right: 0; }
.proj-cell .lbl {
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; display: block; margin-bottom: 3px;
}
.proj-cell .val {
  font-family: var(--num); font-size: 19px; font-variant-numeric: tabular-nums;
  font-weight: 600; letter-spacing: -.01em;
}
.proj-cell.after { background: var(--wash); }
.proj-cell.after .val { transition: color .12s ease; }
.proj .val.up   { color: var(--credit); }
.proj .val.down { color: var(--ink); }
.proj .val.neg  { color: var(--debit); }
.proj-warn {
  margin-top: 8px; font-size: 12.5px; color: var(--debit);
  background: var(--debit-bg); border: 1px solid #F2C9C6;
  border-radius: var(--r); padding: 7px 11px; display: none;
}
.proj-warn.show { display: block; }

/* ---------- entry form ---------- */

.grid {
  display: grid; gap: 10px;
  grid-template-columns: 112px 148px 126px minmax(180px, 1fr) 122px 122px;
  align-items: end;
}
.grid.transfer-on { grid-template-columns: 112px 148px 126px minmax(180px, 1fr) 122px 122px; }

.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f label {
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.f input, .f select, .f textarea {
  font-family: var(--ui); font-size: 14px; color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--r);
  padding: 7px 9px; background: var(--paper); width: 100%;
  min-height: 34px;
}
.f input:focus, .f select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.f input.amt {
  font-family: var(--num); font-variant-numeric: tabular-nums;
  text-align: right; font-weight: 600;
}
.f input.amt.credit { color: var(--credit); }
.f input.amt.debit  { color: var(--debit); }
.f input:disabled, .f select:disabled { background: var(--wash); color: #9AA5B0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; margin-top: 10px; }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

.btn {
  font-family: var(--ui); font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  padding: 9px 16px; border-radius: var(--r); cursor: pointer;
}
.btn:hover { background: var(--wash); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  padding: 9px 22px;
}
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.hint { font-size: 12px; color: var(--muted); }
.hint kbd {
  font-family: var(--num); font-size: 11px; background: var(--wash);
  border: 1px solid var(--rule); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 5px;
}

.toggle { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.toggle input { width: 15px; height: 15px; accent-color: var(--accent); }

/* ---------- ledger table ---------- */

table.led { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.led th {
  text-align: left; font-size: 10.5px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
  padding: 8px 10px; border-bottom: 1px solid var(--rule);
  background: var(--wash); position: sticky; top: 48px; z-index: 5;
}
table.led td { padding: 7px 10px; border-bottom: 1px solid var(--rule-soft); }
table.led tbody tr:hover { background: #FAFBFC; }
table.led .num {
  font-family: var(--num); font-variant-numeric: tabular-nums;
  text-align: right; white-space: nowrap;
}
table.led .cr { color: var(--credit); font-weight: 600; }
table.led .dr { color: var(--debit); font-weight: 600; }
table.led .bal { font-weight: 600; }
table.led .bal.neg { color: var(--debit); }
table.led tr.opening td, table.led tr.closing td {
  background: var(--wash); font-weight: 700; border-top: 1px solid var(--rule);
}
table.led tr.fresh { animation: land 1.1s ease; }
@keyframes land {
  from { background: #FFF6E9; }
  to   { background: transparent; }
}

.tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 3px; vertical-align: 1px;
}
.tag-tr { background: #E8EDF7; color: #2A4A8B; }
.tag-cc { background: var(--wash); color: var(--muted); }

.link-del {
  color: var(--muted); text-decoration: none; font-size: 12px;
  border-bottom: 1px dotted var(--rule);
}
.link-del:hover { color: var(--debit); border-bottom-color: var(--debit); }

/* ---------- balance strip ---------- */

.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.strip a {
  text-decoration: none; color: inherit; display: block;
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 11px 13px;
}
.strip a:hover { border-color: var(--ink-soft); }
.strip .bk {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.strip .bl {
  font-family: var(--num); font-variant-numeric: tabular-nums;
  font-size: 20px; font-weight: 600; margin-top: 4px;
}
.strip .bl.neg { color: var(--debit); }
.strip .last { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(14px);
  background: var(--ink); color: #fff; padding: 10px 18px;
  border-radius: var(--r); font-size: 13.5px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .16s ease, transform .16s ease;
  z-index: 90; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--debit); }
.toast.good { background: var(--credit); }

/* ---------- filters / misc ---------- */

.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters .f { min-width: 140px; }
.empty { padding: 34px 14px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-size: 15px; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--ink);
}
.login-box { width: 340px; background: var(--paper); border-radius: var(--r); padding: 26px; }
.login-box h1 { font-size: 15px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 18px; }
.login-box .f { margin-bottom: 12px; }
.login-box .btn-primary { width: 100%; }
.err { background: var(--debit-bg); color: var(--debit); border: 1px solid #F2C9C6;
       border-radius: var(--r); padding: 8px 11px; font-size: 13px; margin-bottom: 12px; }

@media (max-width: 900px) {
  .grid, .grid.transfer-on { grid-template-columns: 1fr 1fr; }
  .grid .f.wide { grid-column: 1 / -1; }
  .row2 { grid-template-columns: 1fr 1fr; }
  .proj { flex-direction: column; }
  .proj-cell { border-right: 0; border-bottom: 1px solid var(--rule-soft); }
  table.led th { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- autocomplete ---------- */

.f { position: relative; }

.ac-list {
  display: none;
  position: absolute;
  top: 100%; left: 0; right: 0;
  z-index: 60;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  max-height: 264px;
  overflow-y: auto;
  margin-top: 3px;
}
.ac-list.open { display: block; }

.ac-item {
  padding: 7px 11px;
  cursor: pointer;
  border-bottom: 1px solid var(--rule-soft);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.on { background: var(--wash); }
.ac-item.on { box-shadow: inset 3px 0 0 var(--accent); }

.ac-main {
  font-size: 13.5px;
  color: var(--ink);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ac-meta {
  font-family: var(--num);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- credit / debit colour coding ----------
   Money in and money out are the two things it must be impossible to
   confuse on this form. Colour the whole field, not just the digits —
   an empty field showed no colour at all, which is exactly when you are
   deciding which box to type into. */

/* Labels must not wrap. A two-line label pushes its input down and the two
   amount fields stop lining up, which is worse than a slightly terse label —
   the coloured dot and fill already say which direction the money goes. */
.grid .f label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 14px;
  line-height: 14px;
}

/* Bottom-align every field in the row so inputs share a baseline whatever
   the label does. */
.grid { align-items: end; }
.grid .f { justify-content: flex-end; }

#creditWrap label { color: var(--credit); }
#debitWrap  label { color: var(--debit); }

#creditWrap label::before,
#debitWrap  label::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
#creditWrap label::before { background: var(--credit); }
#debitWrap  label::before { background: var(--debit); }

#creditWrap input.amt,
#debitWrap  input.amt,
#amountWrap input.amt {
  border-left-width: 3px;
  font-weight: 600;
}
#creditWrap input.amt {
  border-left-color: var(--credit);
  background: var(--credit-bg);
  color: var(--credit);
}
#debitWrap input.amt,
#amountWrap input.amt {
  border-left-color: var(--debit);
  background: var(--debit-bg);
  color: var(--debit);
}

#creditWrap input.amt::placeholder { color: #8FB9A5; }
#debitWrap  input.amt::placeholder,
#amountWrap input.amt::placeholder { color: #D9A6A2; }

#creditWrap input.amt:focus {
  outline-color: var(--credit);
  border-color: var(--credit);
  background: #FFFFFF;
}
#debitWrap input.amt:focus,
#amountWrap input.amt:focus {
  outline-color: var(--debit);
  border-color: var(--debit);
  background: #FFFFFF;
}

/* The disabled side must read as switched off, not as a second live field.
   Only one of the two can hold a value, and the greyed state is the only
   cue that the other is locked. */
#creditWrap input.amt:disabled,
#debitWrap  input.amt:disabled {
  background: var(--wash);
  border-left-color: var(--rule);
  color: #A8B2BC;
  font-weight: 400;
}

/* Ledger tables: reinforce the same two colours in the amount columns. */
table.led td.num.cr { color: var(--credit); }
table.led td.num.dr { color: var(--debit); }

/* ---------- edit mode ----------
   Editing and adding look nearly identical, and the cost of confusing them
   is real: you think you are adding a row and you are overwriting one. The
   whole card changes state, not just the button label. */

#entryCard.editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 123, 35, .13), var(--shadow);
}
#entryCard.editing .card-head { background: #FFF6E9; }

.edit-banner {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  background: #FFF6E9;
  border: 1px solid #F0D6AE;
  color: var(--accent-ink);
  border-radius: var(--r);
  padding: 9px 13px;
  font-size: 13px;
  margin-bottom: 14px;
}
.edit-banner a { color: var(--accent-ink); }

/* Row actions */
td.row-acts { white-space: nowrap; text-align: right; }
.link-act {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  border-bottom: 1px dotted var(--rule);
  margin-right: 10px;
}
.link-act:hover { color: var(--accent-ink); border-bottom-color: var(--accent); }
