/* Mobile layout.
 *
 * Loaded after app.css, so everything here is an override rather than a fork.
 * Two things drive it:
 *
 *   - The tab bar does not fit and cannot scroll, and the Lists/Lock buttons end
 *     up off the right edge — so below the breakpoint they all move into a menu.
 *   - Any input under 16px makes iOS Safari zoom the page on focus, and there is
 *     no way to opt out of that other than not doing it.
 */

/* ------------------------------------------------------------------ */
/* The burger, hidden on desktop                                      */
/* ------------------------------------------------------------------ */
.burger {
  display: none;
  border: 0;
  background: none;
  padding: 8px 6px;
  margin-left: -4px;
  cursor: pointer;
  flex: none;
}
.burger span {
  display: block;
  width: 19px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform .16s, opacity .16s;
}
.burger span + span { margin-top: 4px; }
.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* The drawer the tabs move into. Present in the DOM at all sizes, shown only
   when the burger opens it. */
.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(20, 26, 34, .38);
  display: none;
}
.drawer-mask.is-open { display: block; }

.drawer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 262px;
  max-width: 84vw;
  background: var(--panel);
  box-shadow: 4px 0 24px rgba(12, 18, 26, .3);
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 0 max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.drawer-head {
  padding: 10px 16px 12px;
  font-weight: 650;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.drawer-tabs { display: flex; flex-direction: column; padding: 6px 8px; }
.drawer-tabs button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 15px;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  cursor: pointer;
}
.drawer-tabs button:active { background: #eceff3; }
.drawer-tabs button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.drawer-actions {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-actions .btn { width: 100%; padding: 11px; font-size: 15px; }

/* ------------------------------------------------------------------ */
/* Below the breakpoint                                               */
/* ------------------------------------------------------------------ */
@media (max-width: 820px) {

  .burger { display: block; }

  /* The tab strip and the header buttons live in the drawer instead. */
  .topbar > .tabs,
  .topbar-right > #btn-settings,
  .topbar-right > #btn-lock { display: none; }

  .topbar {
    gap: 10px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    height: calc(46px + env(safe-area-inset-top));
  }
  .brand { font-size: 15px; }
  .topbar-right { gap: 8px; }
  .saveflag { min-width: 0; }

  /*
   * 16px minimum on anything focusable. Under that, iOS Safari zooms the page on
   * focus and there is no way to decline; `user-scalable=no` would stop it but
   * also kills deliberate pinch-zoom, which is worse.
   *
   * !important earns its place here: half a dozen rules in app.css set `font`
   * or `font-size` on inputs through class selectors (`.fld > input`,
   * `table.edit input`, `input.mono`, `.mp-foot input`, …) and every one of them
   * outranks a bare `input`. Matching each by hand would mean this silently
   * breaks the next time one is added, and the consequence is a zoomed page.
   */
  input, select, textarea {
    font-size: 16px !important;
  }
  /* Buttons are deliberately not in that list. Only form fields trigger the
     zoom, and forcing buttons to 16px made the row's Add/cancel controls wide
     enough to be clipped out of their own column. */
  input[type=checkbox], input[type=radio] { font-size: inherit !important; }

  /* Roomier hit targets. */
  .btn { padding: 8px 12px; }
  .btn-icon { padding: 7px 11px; }
  .chk { padding-bottom: 0; min-height: 34px; }

  /* Toolbars stack and scroll rather than overflowing off-screen. */
  .toolbar {
    gap: 8px 10px;
    padding: 8px 12px;
    align-items: stretch;
  }
  .toolbar .fld { flex: 1 1 46%; min-width: 0; }
  .toolbar .fld > input { width: 100%; }
  .toolbar .fld-grow { flex: 1 1 100%; }
  .toolbar > .btn-primary { flex: 1 1 100%; }
  .monthnav { flex: 1 1 100%; }
  .btn-month { flex: 1; min-width: 0; }

  /* The desktop hints are noise on a phone. */
  .statusbar .hint, .toolbar .hint { display: none; }
  .statusbar { padding: 6px 12px; gap: 10px; }

  /* The pivots stay tables — they are inherently wide — but the frozen first
     column is what made them impossible to scroll, so let them scroll freely. */
  /* 168px of row header plus 46px of meta is over half a phone, which is what
     made these unscrollable. The name still has to stay put — without it the
     numbers mean nothing — so it stays pinned but narrow, and the meta column
     gives up its pin and scrolls away with the rest. */
  table.pivot td.rowhdr, table.pivot th.rowhdr {
    width: 104px;
    min-width: 104px;
    max-width: 104px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  table.pivot td.meta, table.pivot th.meta {
    position: static;
    box-shadow: none;
  }
  .gridwrap { -webkit-overflow-scrolling: touch; }

  /* Modals become near-full-screen sheets. */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal, .modal-lg {
    width: 100%;
    /* Percent of the mask, not vh: on a phone vh ignores the address bar. */
    max-height: 94%;
    border-radius: 14px 14px 0 0;
    display: flex;
    flex-direction: column;
  }
  /* The body is the only part that gives; a long form otherwise squeezes the
     footer until Save is a sliver off the bottom of the screen. min-height:0
     is what actually lets a flex child scroll instead of growing. */
  .modal-head, .modal-foot { flex: 0 0 auto; }
  .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-foot {
    border-radius: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .modal-foot .btn { flex: 1; padding: 11px; }
  .modal-head h2 { font-size: 15px; }
  .modal-head .sub { display: none; }

  /* The gate screen. */
  .lockbox { width: 100%; padding: 26px 20px 20px; }
  .lockscreen { padding: 16px; align-items: flex-start; padding-top: 12vh; }
}

/* ------------------------------------------------------------------ */
/* Cards                                                              */
/* ------------------------------------------------------------------ */
/* Present at any width — the JS decides which shape to draw — so these are
   outside the media query and the phone-only tweaks are inside it. */
.cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card:active { background: #f4f6f9; }

.card-head { display: flex; align-items: baseline; gap: 10px; }
.card-title {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-net { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.card-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.card-date { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.chip-warn { background: #fdeced; color: var(--neg); }

.card-legs {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.card-legs > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.card-legs span:first-child { color: var(--ink-soft); }
.card-loans > div span:first-child { color: #6b5a2b; }

/* A transaction that needs attention, same language as the grid. */
.card-flag { background: #fdeced; border-color: #f0cdd0; }
.card-flag:active { background: #fbe0e2; }

/* Records cards: a definition list of the fields that have something in them. */
.card-body { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.card-body dt { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .4px; padding-top: 2px; }
.card-body dd { margin: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.card-body dd .rowbtn-copy { position: static; opacity: .6; margin-left: 4px; }

/* ------------------------------------------------------------------ */
/* Modal forms                                                        */
/* ------------------------------------------------------------------ */
.ff { margin-bottom: 11px; }
.ff > label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
.ff > input {
  width: 100%;
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
}
.ff > input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
/* A checkbox reads as a sentence, not as a field caption — so it opts out of
   the small-caps label styling it would otherwise inherit as a direct child. */
.ff > label.ff-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  padding: 6px 0;
  margin-bottom: 0;
}
.ff-check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; }
.ff-check input { width: auto; }

.ff-multi { display: flex; flex-wrap: wrap; gap: 6px; }
.ff-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
}
.ff-chip input { margin: 0; }
.ff-chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.ff-section {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 16px 0 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-weight: 650;
  font-size: 13px;
}
.ff-note { font-weight: 400; font-size: 11px; color: var(--ink-faint); }

.ff-leg { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.ff-leg input { font: inherit; padding: 8px 9px; border: 1px solid var(--line-strong); border-radius: 7px; min-width: 0; }
.ff-leg .leg-account, .ff-leg .loan-who { flex: 1.4; }
.ff-leg .leg-amount, .ff-leg .loan-amount { flex: 1; text-align: right; font-variant-numeric: tabular-nums; }
.ff-leg .rowbtn { flex: none; font-size: 17px; padding: 0 5px; }
.ff-empty { font-size: 12px; color: var(--ink-faint); padding: 4px 0 8px; }

.ff-total {
  display: flex;
  gap: 18px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.ff-total div { font-size: 11px; color: var(--ink-faint); }
.ff-total b { display: block; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

@media (max-width: 820px) {
  /* The entry row belongs to the table; on cards the + button opens the form. */
  .cards { padding: 8px; }
  .card-body { grid-template-columns: 1fr; gap: 1px; }
  .card-body dt { padding-top: 6px; }
}

/* ------------------------------------------------------------------ */
/* Collapsed toolbars                                                 */
/* ------------------------------------------------------------------ */
.mob-filters { display: none; }

@media (max-width: 820px) {
  .toolbar.has-collapse .mob-filters { display: block; order: 99; }
  /* Only what you reach for every time stays out. */
  .toolbar.is-collapsed > *:not(.btn-primary):not(.monthnav):not(.fld-grow):not(.mob-filters) {
    display: none;
  }

  /* Label beside value, not above it — a password card was two lines a field. */
  .card-body {
    grid-template-columns: minmax(78px, auto) 1fr;
    gap: 2px 10px;
    align-items: baseline;
  }
  .card-body dt { padding-top: 0; }
}
