/* Uday Raj Purchase Ledger
   ---------------------------------------------------------------------------
   No webfont: a self-hosted family would eat most of the 50 KB budget and add
   an HTTP request, and this is a data tool, not a brochure. System UI faces
   instead, with tabular figures wherever money appears -- in a ledger, digits
   that line up column-wise matter more than digits with personality.
   --------------------------------------------------------------------------- */

:root {
  --ink:      #16202b;
  --muted:    #5c6b7a;
  --rule:     #dde3e9;
  --paper:    #ffffff;
  --sunk:     #f4f6f8;
  --accent:   #14566b;
  --ok:       #1a7f4b;
  --warn:     #9a6700;
  --bad:      #b42318;
  --radius:   3px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--sunk);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* --- Top bar -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 0 20px;
  background: var(--ink);
  color: #fff;
}

.brand {
  font-weight: 600;
  letter-spacing: .01em;
  color: #fff;
  text-decoration: none;
  padding: 14px 0;
  white-space: nowrap;
}

.topbar nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }

.topbar nav a {
  color: #b8c4ce;
  text-decoration: none;
  padding: 14px 12px;
  border-bottom: 3px solid transparent;
}

.topbar nav a:hover { color: #fff; }
.topbar nav a.on { color: #fff; border-bottom-color: var(--accent); }

.who { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #b8c4ce; }
.who a { color: #b8c4ce; }

/* --- Page ----------------------------------------------------------------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

main.bare { max-width: 420px; padding-top: 8vh; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }

.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

a { color: var(--accent); }

/* --- Login / narrow forms ------------------------------------------------- */

.login {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 28px;
}

.login h1 { margin-bottom: 2px; }
.login .sub { margin-bottom: 20px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 4px;
}

input[type=text], input[type=password], input[type=date],
input[type=number], input[type=email], select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #c3ccd5;
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

input[type=number], .num { font-variant-numeric: tabular-nums; }

button {
  margin-top: 20px;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: #0f4353; }

/* --- Flash messages ------------------------------------------------------- */

.flash {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  border-left: 3px solid;
}

.flash.ok    { background: #eaf6ef; border-color: var(--ok);   color: #125c36; }
.flash.info  { background: #eef2f6; border-color: var(--muted);color: #3a4855; }
.flash.error { background: #fdeeec; border-color: var(--bad);  color: #8f1d13; }

/* --- Cards ---------------------------------------------------------------- */

.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 24px; }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .figure { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }

.note {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--muted);
  font-size: 14px;
}

.note p { margin: 0 0 8px; }
.note p:last-child { margin: 0; }

/* --- Tables --------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

td { padding: 8px 10px; border-bottom: 1px solid #eef1f4; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }

td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* Match status. These colours carry meaning -- they are the app's whole
   point -- so they are never used decoratively elsewhere. */
.st { font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-matched, .st-matched_late { color: var(--ok); }
.st-awaiting, .st-manual_review { color: var(--warn); }
.st-not_filed, .st-value_mismatch { color: var(--bad); }

/* --- Small screens -------------------------------------------------------- */

@media (max-width: 640px) {
  .topbar { gap: 0 16px; }
  .topbar nav a { padding: 10px 8px; font-size: 14px; }
  main { padding: 16px 12px 48px; }
  main.bare { padding-top: 4vh; }
  .login { padding: 20px; }
}

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

/* --- Filter bar ----------------------------------------------------------- */

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.filters input[type=text], .filters select { width: auto; }

.filters button.small { margin-top: 0; padding: 8px 14px; }

.filters .clear { font-size: 13px; color: var(--muted); }

.btn-link {
  margin-left: auto;
  padding: 8px 14px;
  background: var(--paper);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 400;
  color: var(--ink);
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
}

label.inline input { width: auto; }

/* --- Forms ---------------------------------------------------------------- */

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px 22px;
  max-width: 640px;
}

.field { margin-bottom: 4px; }
.field label { margin-top: 16px; }
.panel .field:first-child label { margin-top: 0; }

.row { display: flex; gap: 14px; }
.row .field { flex: 1; }

.err { color: var(--bad); font-size: 13px; margin: 4px 0 0; font-weight: 600; }
.err a { color: var(--bad); }

input[readonly] { background: var(--sunk); color: var(--muted); }

/* --- Table extras --------------------------------------------------------- */

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.tiny { font-size: 12px; color: var(--muted); }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  color: var(--muted);
  margin-left: 4px;
  vertical-align: 1px;
}

tr.dim td { color: var(--muted); }

.pager {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .row { flex-direction: column; gap: 0; }
  .btn-link { margin-left: 0; }
  table { font-size: 13px; }
  td, th { padding: 7px 8px; }
}

.grouprow {
  background: var(--sunk);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

/* --- Bill entry ----------------------------------------------------------- */

.panel.wide { max-width: 860px; }

fieldset.money {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 4px 16px 16px;
  margin: 20px 0 4px;
}

fieldset.money legend {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 0 6px;
}

input.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }

/* Autocomplete */
.ac { position: relative; }

.ac-list {
  position: absolute;
  z-index: 20;
  left: 0; right: 0;
  background: var(--paper);
  border: 1px solid var(--accent);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(22, 32, 43, .10);
}

.ac-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #eef1f4; }
.ac-item:last-child { border-bottom: 0; }
.ac-item.on, .ac-item:hover { background: #eef4f6; }
.ac-item strong { display: block; font-weight: 600; font-size: 14px; }
.ac-item span {
  font-size: 12px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Live tally */
.tally {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--sunk);
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: center;
  font-variant-numeric: tabular-nums;
  min-height: 38px;
}

.t-part { color: var(--ink); }
.t-ok   { color: var(--ok);   font-weight: 600; }
.t-bad  { color: var(--bad);  font-weight: 600; }
.t-warn { color: var(--warn); font-weight: 600; }
.t-note { color: var(--muted); }

.tally button {
  margin: 0 0 0 6px;
  padding: 3px 8px;
  font-size: 12px;
  background: var(--bad);
}
.tally button:hover { background: #8f1d13; }

/* Delete */
form.danger { margin-top: 28px; max-width: 860px; }

.danger-btn {
  background: var(--paper);
  color: var(--bad);
  border: 1px solid var(--bad);
  font-weight: 600;
  padding: 8px 14px;
  margin: 0;
}
.danger-btn:hover { background: var(--bad); color: #fff; }

input[type=file] {
  font: inherit;
  font-size: 14px;
  padding: 7px 0;
  width: 100%;
}

@media (max-width: 640px) {
  fieldset.money { padding: 4px 10px 12px; }
  .tally { font-size: 12px; }
}
