/* =====================================================================
   Look and feel: a clean accounting ledger.
   - Pale green-grey "paper" background, white sheets
   - Deep ledger green for actions and headings
   - Two ink colours, like a real account book:
       blue  = money owed TO the company
       red   = money the company OWES
   - Totals have a double line on top, as in accounting books
   ===================================================================== */

:root {
  --paper: #f1f4f2;
  --sheet: #ffffff;
  --ink: #1d2a29;
  --muted: #5e6d6a;
  --rule: #d3ded9;
  --field: #b9c8c2;
  --ledger: #0d6b57;
  --ledger-dark: #0a5545;
  --ledger-soft: #e2eee9;
  --ink-blue: #1e4e96;
  --ink-red: #a3312b;
  --red-soft: #fbeeec;
  --radius: 8px;
  --font-ui: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --font-title: "Noto Naskh Arabic", "Vazirmatn", Tahoma, serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.75;
}

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

/* Line icons (templates/icons.html) */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar .icon { color: var(--muted); }
.sidebar a.active .icon, .sidebar a:hover .icon { color: var(--ledger); }
a:hover { color: var(--ledger-dark); }

:focus-visible { outline: 3px solid rgba(30, 78, 150, 0.45); outline-offset: 2px; }

h1, h2 { margin: 0; line-height: 1.4; }
h1 { font-family: var(--font-title); font-weight: 700; font-size: 1.85rem; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 2rem 0 0.75rem; }
h2 small, .sub small { color: var(--muted); font-weight: 400; }
small { font-size: 0.82em; }

/* Numbers, dates and codes always read left-to-right and line up in columns */
.num {
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
}
td.num, th.num { text-align: left; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }

/* ---------------------------------------------------------------------
   Layout: top bar + sidebar (right side, because the page is RTL)
   --------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--ledger);
  color: #fff;
}
.brand {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  text-decoration: none;
}
.brand:hover { color: #fff; }
.who { margin-inline-start: auto; font-size: 0.85rem; opacity: 0.92; }
.menu-btn {
  display: none;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0 1rem;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - 56px); }

.sidebar {
  background: var(--sheet);
  border-inline-end: 1px solid var(--rule);
  padding: 1rem 0.75rem 2rem;
}
.nav-group { margin-bottom: 0.9rem; }
.nav-title { margin: 0 0.75rem 0.15rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.sidebar a, .link-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.38rem 0.75rem;
  border-radius: 6px;
  border-inline-start: 3px solid transparent;
  color: var(--ink);
  text-decoration: none;
  text-align: start;
}
.sidebar a:hover, .link-btn:hover { background: var(--ledger-soft); }
.sidebar a.active {
  background: var(--ledger-soft);
  border-inline-start-color: var(--ledger);
  color: var(--ledger-dark);
  font-weight: 700;
}
.link-btn { background: none; border-top: 0; border-bottom: 0; border-inline-end: 0; font: inherit; cursor: pointer; }

/* Collapsible menu sections (version 6.1): only the section names show; a click opens its links.
   Without JavaScript (no "js" class) every section stays open. */
.nav-collapsible { margin-bottom: 0.2rem; }
.nav-toggle {
  display: flex; align-items: center; gap: 0.6rem; width: 100%; margin: 0; padding: 0.5rem 0.75rem;
  border: 0; border-radius: 6px; background: none; color: var(--ink); font: inherit; font-size: 0.95rem;
  font-weight: 700; text-align: start; cursor: pointer;
}
.nav-toggle span { flex: 1; }
.nav-toggle:hover { background: var(--ledger-soft); }
.nav-toggle .icon:last-child { width: 16px; height: 16px; color: var(--muted); transition: transform 0.15s; }
.nav-toggle[aria-expanded="true"] .icon:last-child { transform: rotate(180deg); }
.nav-collapsible.has-active > .nav-toggle { color: var(--ledger-dark); }
.nav-items { padding-inline-start: 0.6rem; margin-bottom: 0.35rem; }
.nav-items a { font-size: 0.92rem; }
html.js .nav-collapsible:not(.open) > .nav-items { display: none; }
@media (prefers-reduced-motion: reduce) { .nav-toggle .icon:last-child { transition: none; } }

.content { padding: 1.5rem 2rem 4rem; max-width: 1240px; width: 100%; }

/* ---------------------------------------------------------------------
   Page header
   --------------------------------------------------------------------- */
.page-head { margin-bottom: 1.25rem; }
.page-head .sub { margin: 0.25rem 0 0; color: var(--muted); max-width: 70ch; }
.quick { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.9rem; }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 1rem;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  gap: 0.45rem;
}
.btn:hover { border-color: var(--ledger); color: var(--ledger-dark); }
.btn-primary { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.btn-primary:hover { background: var(--ledger-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ledger); }
.btn-ghost:hover { background: var(--ledger-soft); border-color: transparent; }
.btn-wide { width: 100%; margin-top: 0.5rem; }
.btn-delete {
  padding: 0.1rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--ink-red);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-delete:hover { border-color: var(--ink-red); background: var(--red-soft); }
form.inline { display: inline; }

/* Button while a form is being saved: spinner + locked */
.is-busy { position: relative; opacity: 0.75; cursor: progress; }
.is-busy::before {
  content: "";
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .is-busy::before { animation-duration: 2s; }
}

/* Page numbers under long lists */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin: 0 0 1rem; }
.pager-info { color: var(--muted); font-size: 0.85rem; }
.pager-links { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.pager-links a, .pager-links span {
  min-width: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--sheet);
  text-decoration: none;
}
.pager-links .current { background: var(--ledger); border-color: var(--ledger); color: #fff; font-weight: 700; }
.pager-links .gap { border-color: transparent; background: none; color: var(--muted); }

/* ---------------------------------------------------------------------
   Messages
   --------------------------------------------------------------------- */
.flash, .errors {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border-inline-start: 4px solid var(--ledger);
  background: var(--ledger-soft);
}
.flash-error, .errors { border-inline-start-color: var(--ink-red); background: var(--red-soft); }
.errors p { margin: 0; font-weight: 700; }
.errors ul { margin: 0.25rem 0 0; padding-inline-start: 1.25rem; }

.empty {
  padding: 1.25rem;
  border: 1px dashed var(--field);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--muted);
}
.empty a { font-weight: 700; }
.hint { color: var(--muted); font-size: 0.82rem; font-weight: 400; }
p.hint { max-width: 80ch; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.sheet h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem 1.5rem; max-width: 860px; }
.form-narrow { max-width: 420px; display: grid; gap: 1rem; }
.span-2 { grid-column: 1 / -1; }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 500; }
input[type="text"], input[type="search"], input[type="tel"], input[type="password"],
input[type="date"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-blue); outline: 3px solid rgba(30, 78, 150, 0.2); }
input[dir="ltr"] { text-align: left; }
input:disabled { background: var(--paper); color: var(--muted); }
textarea { resize: vertical; }

fieldset.paytype { margin: 0; padding: 0.6rem 0.9rem 0.8rem; border: 1px solid var(--rule); border-radius: 6px; }
fieldset.paytype legend { padding: 0 0.35rem; font-size: 0.9rem; font-weight: 500; }
label.radio, label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; min-height: 36px; }
label.radio input, label.check input { width: 20px; height: 20px; accent-color: var(--ledger); }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Live calculation box in the purchase/sale form */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.summary > div { display: flex; flex-direction: column; padding: 0.6rem 0.85rem; background: var(--ledger-soft); }
.summary span { font-size: 0.8rem; color: var(--muted); }
.summary strong { font-size: 1.2rem; text-align: right; }

/* Filters above lists */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.filters label { flex: 0 1 170px; font-size: 0.82rem; }
.filters label.grow { flex: 1 1 220px; }
.filters label.check { flex: 0 0 auto; }
.filters input, .filters select { min-height: 40px; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--rule); }
.tabs a { padding: 0.45rem 0.9rem; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ledger-dark); border-bottom-color: var(--ledger); font-weight: 700; }

/* ---------------------------------------------------------------------
   Ledger tables
   --------------------------------------------------------------------- */
/* Tables scroll inside their own box (up and down, and sideways on phones).
   The heading row stays visible at the top while scrolling. */
.table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  margin-bottom: 0.75rem;
  overscroll-behavior: contain;
}
table.ledger { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
/* Version 5.2: narrower columns (less padding, headings may wrap onto two lines) so wide lists fit on a
   printed page / PDF without being cut off */
table.ledger th, table.ledger td { padding: 0.45rem 0.45rem; text-align: right; vertical-align: top; }
table.ledger thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ledger-soft);
  border-bottom: 0;
  box-shadow: inset 0 -2px 0 var(--ledger);    /* the line under the heading moves with it */
  font-weight: 700;
  white-space: normal;
  vertical-align: bottom;
  line-height: 1.35;
}
table.ledger tbody td, table.ledger tbody th { border-bottom: 1px solid var(--rule); }
table.ledger tbody th { font-weight: 500; }
table.ledger tbody tr:last-child td, table.ledger tbody tr:last-child th { border-bottom: 0; }
table.ledger tfoot .totals th, table.ledger tfoot .totals td { border-top: 3px double var(--ink); font-weight: 700; }
table.ledger.compact th, table.ledger.compact td { padding: 0.35rem 0.45rem; }
/* A date with its weekday under it (version 5.2) */
.date-cell { display: inline-block; line-height: 1.3; text-align: center; white-space: nowrap; }
.date-cell .wd { display: block; color: var(--muted); font-size: 0.78em; direction: rtl; }
table.ledger tr.inactive td { color: var(--muted); }
table.ledger tr.opening td { background: #f7faf8; font-style: italic; }
.col-debit, .col-credit { white-space: nowrap; }
.empty-cell { color: var(--muted); text-align: center !important; padding: 1.25rem !important; }
.row-actions { white-space: nowrap; }
.row-actions > * + * { margin-inline-start: 0.6rem; }
td.has-remaining { color: var(--ink-red); font-weight: 700; }
td.period-cell { white-space: nowrap; }
/* The profit table has many columns: tighter cells, headings may wrap */
table.ledger.profit-table th, table.ledger.profit-table td { padding: 0.5rem 0.55rem; }
table.ledger.profit-table thead th { white-space: normal; vertical-align: bottom; }
.tag {
  padding: 0 0.4rem;
  border-radius: 4px;
  background: var(--ledger-soft);
  color: var(--ledger-dark);
  font-size: 0.75rem;
}
.profit-ink, .profit-ink .num { color: var(--ledger-dark); }
.qty-line { margin: 0 0 1rem; color: var(--muted); }
.qty-line strong { color: var(--ink); }

/* Send statement by WhatsApp / Telegram */
.share { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
.share .hint { flex-basis: 100%; margin: 0; }
.btn-share { border-color: var(--ledger); color: var(--ledger-dark); background: var(--ledger-soft); }
.btn-share:hover { background: var(--ledger); color: #fff; }

/* Who owes whom */
.bal { white-space: nowrap; }
.bal small { color: var(--muted); font-weight: 400; }
.bal-in, .bal-in .num { color: var(--ink-blue); }
.bal-out, .bal-out .num { color: var(--ink-red); }
.bal-zero { color: var(--muted); }
.bal .num { font-weight: 700; }

.balance-now {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  font-size: 1.15rem;
}
.balance-now .unit { color: var(--muted); font-size: 0.85rem; }

/* ---------------------------------------------------------------------
   Home page
   --------------------------------------------------------------------- */
/* Stock per supplier: one ruled strip, like a line in an account book */
.stock-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ledger);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
/* Each cell draws its own ruling; the lines on the outer edges are pushed
   1px outside the strip and hidden, so only the inner lines show. */
.stock-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-inline-start: -1px;
  margin-bottom: -1px;
  padding: 0.9rem 1.1rem 1rem;
  border-inline-start: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: var(--sheet);
  color: var(--ink);
  text-decoration: none;
}
.stock-cell:hover { background: #f7faf8; color: var(--ink); }
.stock-name { font-size: 0.88rem; color: var(--muted); }
.stock-qty { font-size: 2rem; font-weight: 700; line-height: 1.3; color: var(--ledger-dark); text-align: right; }
.stock-cell.is-empty .stock-qty { color: var(--ink-red); }

.money-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
.money-pair.trio { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.money-box {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.15rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
  text-decoration: none;
}
a.money-box:hover { border-color: var(--ledger); color: var(--ink); }
.money-label { color: var(--muted); font-size: 0.88rem; }
.money-value { font-size: 1.6rem; font-weight: 700; text-align: right; }
.money-note { font-size: 0.8rem; color: var(--muted); }
.split-line { display: flex; justify-content: space-between; gap: 1rem; padding: 0.15rem 0; border-bottom: 1px dashed var(--rule); font-size: 0.9rem; }
.split-line:last-child { border-bottom: 0; }
.split-line.strong { font-weight: 700; }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1.5rem; }

.backup-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------------------------------------------------------------------
   Login page
   --------------------------------------------------------------------- */
.guest-main { padding: 1rem; }
.login-card {
  max-width: 400px;
  margin: 10vh auto 0;
  padding: 2rem 1.75rem;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-top: 4px solid var(--ledger);
  border-radius: 10px;
}
.login-card h1 { font-size: 1.6rem; margin-bottom: 1.25rem; }
.login-card form { display: grid; gap: 1rem; }
.login-company { margin: 0; color: var(--ledger); font-weight: 700; }

.print-only { display: none; }
/* Messages from Fargard at the top of the pages (version 6.1) */
.notice {
  display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.75rem; padding: 0.75rem 1rem;
  border-radius: var(--radius); background: var(--notice-bg, #e8f1fb); color: var(--notice-ink, #16365c);
  border: 1px solid rgba(0, 0, 0, 0.08); border-inline-start: 5px solid currentColor;
}
.notice[hidden] { display: none; }
.notice-icon .icon { width: 22px; height: 22px; margin-top: 0.15rem; }
.notice-text { flex: 1; min-width: 0; }
.notice-text p { margin: 0.15rem 0; white-space: pre-line; }
.notice-text small { opacity: 0.8; }
.notice-close { border: 0; background: none; color: inherit; cursor: pointer; padding: 0.2rem; border-radius: 4px; }
.notice-close:hover { background: rgba(0, 0, 0, 0.08); }
.notice-swatch { display: inline-flex; padding: 0.2rem; border-radius: 4px; vertical-align: middle; margin-inline-end: 0.3rem; }
.notice-swatch .icon { width: 14px; height: 14px; }
.pre-line { white-space: pre-line; }
.color-field { display: grid; gap: 0.3rem; align-content: start; }
.color-field input[type="color"] { width: 4rem; height: 2.4rem; padding: 0.1rem; border: 1px solid var(--field); border-radius: 6px; }
.company-picks { display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; margin-top: 0.4rem; padding: 0.5rem 0.25rem 0; }
.company-picks[hidden] { display: none; }
.wide-form { max-width: 860px; }
.wide-form textarea { font-size: 0.95rem; line-height: 1.8; }

/* Quick access tiles on the home page (version 6.1) */
.quick-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; margin: 0 0 1.5rem; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 84px; padding: 0.75rem 0.5rem; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--sheet); color: var(--ink); text-align: center; text-decoration: none; font-weight: 500;
}
.tile .icon { width: 24px; height: 24px; color: var(--ledger); }
.tile:hover { border-color: var(--ledger); background: var(--ledger-soft); color: var(--ledger-dark); }
.tile-main { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.tile-main .icon { color: #fff; }
.tile-main:hover { background: var(--ledger-dark); color: #fff; }
@media screen and (max-width: 520px) { .quick-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .tile { min-height: 74px; font-size: 0.82rem; } }

/* Invoice number search (version 6.1) */
.filters .number-filter { flex: 0 1 9rem; }
.number-note { margin: -0.25rem 0 0.75rem; padding: 0.4rem 0.75rem; border-radius: 6px; background: var(--ledger-soft); }

/* Terms and conditions (version 6.1) */
.terms-text h2 { margin: 1.25rem 0 0.4rem; color: var(--ledger-dark); }
.terms-text h2:first-child { margin-top: 0; }
.terms-text p, .terms-text li { max-width: 80ch; }
.login-links { max-width: 400px; margin: 1rem auto 0; text-align: center; }
.login-links .btn { display: inline-flex; gap: 0.4rem; align-items: center; }

/* Lines of a sale (several suppliers) and of a card deal (version 6.0) */
.sale-lines { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.5rem 0.75rem 0.75rem;
              min-width: 0; }   /* a fieldset is as wide as its content by default: let the table scroll instead */
.lines-wrap { max-height: none; margin-bottom: 0.5rem; }
.lines-table select { min-width: 9.5rem; width: 100%; }
.lines-table input { min-width: 4.5rem; width: 100%; }
.lines-table td { vertical-align: middle; }
.lines-table td:last-child, .lines-table th:last-child { width: 2rem; }
.lines-table [data-line-amount] { white-space: nowrap; }

/* Account transfer preview (version 6.0) */
.transfer-preview { padding: 0.6rem 0.9rem; border: 1px solid var(--ledger); border-radius: var(--radius);
                    background: var(--ledger-soft); }
.transfer-preview[hidden] { display: none; }
.transfer-preview ul { margin: 0.25rem 0 0; padding-inline-start: 1.2rem; }
.rules-table { margin-top: 1rem; max-width: 860px; }
.rules-table h2 { margin-top: 0; }

/* History of changes (version 5.2) */
.muted { color: var(--muted); }
.log-counts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.75rem; }
.log-tag { display: inline-block; padding: 0 0.45rem; border-radius: 999px; font-size: 0.8rem; white-space: nowrap;
           background: var(--ledger-soft); color: var(--ledger-dark); }
.log-tag.log-delete, .log-tag.log-login_failed { background: var(--red-soft); color: var(--ink-red); }
.log-tag.log-edit { background: #fff3cd; color: #6b4e00; }
.log-tag.log-login, .log-tag.log-logout, .log-tag.log-other { background: #eef1f5; color: #3d4b5c; }
.log-details { margin: 0; padding-inline-start: 1rem; font-size: 0.82rem; line-height: 1.55; }
.log-details del { color: var(--ink-red); }
.log-details ins { color: var(--ink-blue); text-decoration: none; font-weight: 600; }
table.log-table td:first-child { width: 6.5rem; }

/* Customer's / supplier's note on the sale and purchase forms (version 5.2) */
.party-note {
  padding: 0.6rem 0.9rem;
  border: 1px solid #e3c35a;
  border-inline-start: 5px solid #d39e00;
  border-radius: var(--radius);
  background: #fff8db;
  color: #4a3b00;
}
.party-note[hidden] { display: none; }
.party-note strong { display: inline-flex; align-items: center; gap: 0.35rem; margin-inline-end: 0.35rem; }
.print-head { display: none; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; padding-bottom: 0.35rem;
              border-bottom: 1px solid #999; }
.print-head span { display: flex; flex-direction: column; line-height: 1.3; }
.print-head small { color: #444; }
.login-logo { display: block; width: 180px; height: auto; margin: 0 auto 0.5rem; }
.login-card h1 { text-align: center; }
.login-version { margin: -1rem 0 1rem; text-align: center; color: var(--muted); font-size: 0.85rem; }

/* ---------------------------------------------------------------------
   Version 5: subscriptions and Fargard's owner panel
   --------------------------------------------------------------------- */
.btn-whatsapp { border-color: var(--ledger); color: var(--ledger-dark); background: var(--ledger-soft); }
.btn-whatsapp:hover { background: var(--ledger); color: #fff; }
.btn-danger { background: var(--ink-red); border-color: var(--ink-red); color: #fff; }
.btn-danger:hover { background: #82241f; color: #fff; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--font-ui);
  vertical-align: middle;
  white-space: nowrap;
}
.badge-trial { background: #e3ecfa; color: var(--ink-blue); }
.badge-active { background: var(--ledger-soft); color: var(--ledger-dark); }
.badge-grace { background: #fdf0d8; color: #8a5300; }
.badge-expired { background: var(--red-soft); color: var(--ink-red); }
.badge-suspended { background: #3b3f3e; color: #fff; }

/* Reminder banner inside a company's system */
.sub-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid #b9cdeb;
  background: #eef3fb;
  color: var(--ink);
}
.sub-banner p { margin: 0; flex: 1 1 22rem; }
.sub-banner.sub-soon { border-color: #ecc77b; background: #fff7e6; }
.sub-banner.sub-grace, .sub-banner.sub-expired { border-color: #e2a8a3; background: var(--red-soft); }
.sub-banner.sub-grace strong, .sub-banner.sub-expired strong { color: var(--ink-red); }
.sub-actions { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.sub-actions a { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 700; color: var(--ledger-dark); }

/* Owner panel */
.owner-app .topbar { background: #183d5d; }
.owner-app .topbar .brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.owner-app .topbar .brand img { border-radius: 6px; background: #fff; }
.owner-app .sidebar a.active { background: #e3ecf5; color: #183d5d; box-shadow: inset -4px 0 0 #183d5d; }
.owner-login .login-company { display: inline-flex; align-items: center; gap: 0.4rem; }
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; gap: 0.2rem; padding: 0.8rem 1rem; background: var(--sheet);
        border: 1px solid var(--rule); border-radius: var(--radius); }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.45rem; font-weight: 700; }
.stat-note { color: var(--muted); font-size: 0.8rem; }
.stat-warn { border-color: #ecc77b; background: #fff7e6; }
.filter-tabs .count { display: inline-block; min-width: 1.5em; padding: 0 0.35rem; border-radius: 999px;
                      background: var(--ledger-soft); font-size: 0.78rem; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { padding: 0.15rem 0.7rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper); font-size: 0.85rem; }
fieldset.choice { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin: 0; }
fieldset.choice legend { padding: 0 0.3rem; font-weight: 500; }
.form-grid.narrow { max-width: 560px; }
/* Search box above long customer/supplier lists (version 6) */
.select-search { margin-bottom: 0.35rem; }
.filters .select-search { min-height: 36px; padding: 0.3rem 0.6rem; }
.plain-list { margin: 1rem 0 0; padding-inline-start: 1.2rem; }
.plain-list li + li { margin-top: 0.35rem; }

/* Payment receipt */
.receipt-actions { margin-bottom: 1rem; }
.receipt { max-width: 720px; }
.receipt-head { display: flex; align-items: center; gap: 0.9rem; padding-bottom: 0.8rem; border-bottom: 2px solid var(--ink); }
.receipt-head img { border-radius: 10px; }
.receipt-head div { display: flex; flex-direction: column; gap: 0.2rem; }
.receipt-head small { color: var(--muted); }
.receipt h1 { font-size: 1.35rem; margin: 1rem 0; }
.receipt-facts { grid-template-columns: max-content minmax(0, 1fr); gap: 0.55rem 1.25rem; }

/* ---------------------------------------------------------------------
   Developer credit (Fargard) and the "about" page
   --------------------------------------------------------------------- */
.dev-credit {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.25rem 0.75rem 0.5rem;
  padding: 0.6rem 0.7rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.5;
}
.dev-credit img { flex: 0 0 auto; border-radius: 6px; }
.dev-credit span { display: flex; flex-direction: column; }
.dev-credit strong { color: var(--ink); font-weight: 700; }
.dev-credit small { font-size: 0.72rem; }
.dev-credit:hover strong { color: var(--ledger-dark); text-decoration: underline; }
.login-credit {
  max-width: 400px;
  margin: 1rem auto 2rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--sheet);
}

.about { max-width: 860px; }
.about-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.about-head img { flex: 0 0 auto; border-radius: 16px; }
.about-head h1 { margin: 0; }
.about-head .sub { margin: 0; }
.latin-name { font-family: "Segoe UI", Tahoma, sans-serif; font-size: 0.6em; color: var(--muted); font-weight: 600; margin-inline-start: 0.4rem; }
.about-lead { font-size: 1.02rem; margin: 0 0 1.25rem; }
.about-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
.about-grid .sheet { margin: 0; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: 0.85rem; }
.facts dd { margin: 0; }
.services { margin: 0; padding-inline-start: 1.2rem; }
.services li + li { margin-top: 0.4rem; }
.contact-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---------------------------------------------------------------------
   Cash box closing
   --------------------------------------------------------------------- */
.closing-wrap { max-width: 640px; }
table.ledger.closing-table th { font-weight: 500; }
table.ledger.closing-table tfoot th { font-weight: 700; }
table.ledger.closing-table td { width: 9rem; white-space: nowrap; }   /* numbers line up by their last digit */
.report-sheet h2 { margin-top: 1.5rem; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 2.5rem; margin-top: 3rem; }
.signatures div { padding-top: 0.5rem; border-top: 1px solid var(--ink); text-align: center; font-size: 0.9rem; }

/* ---------------------------------------------------------------------
   Phones and small screens
   --------------------------------------------------------------------- */
@media screen and (max-width: 900px) {     /* screen only (5.2): paper is narrow too, but must keep the print layout */
  .menu-btn { display: inline-flex; align-items: center; }
  .who { display: none; }
  .shell { display: block; }
  .sidebar {
    display: none;
    position: sticky;
    top: 56px;
    z-index: 9;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    border-inline-end: 0;
    border-bottom: 1px solid var(--rule);
    box-shadow: 0 8px 24px rgba(29, 42, 41, 0.12);
  }
  .sidebar.open { display: block; }
  .content { padding: 1.1rem 1rem 3rem; }
  h1 { font-size: 1.55rem; }
  .form-grid, .money-pair, .money-pair.trio, .two-col, .about-grid { grid-template-columns: minmax(0, 1fr); }
  .receipt-facts { grid-template-columns: minmax(0, 1fr); }
  .stat-value { font-size: 1.2rem; }
  .table-wrap { max-height: 65vh; }
  table.ledger.closing-table { min-width: 0; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 0 1rem; }
  .facts dd { margin-bottom: 0.4rem; }
  .stock-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters label, .filters label.grow { flex: 1 1 140px; }
  table.ledger { font-size: 0.84rem; }
  /* Wide tables keep readable columns and scroll sideways inside their box */
  table.ledger:not(.compact) { min-width: 680px; }
  table.ledger.statement td:nth-child(4) { min-width: 11rem; }
  table.ledger td > a { white-space: nowrap; }      /* names stay on one line */
  .stock-qty { font-size: 1.65rem; }
}

/* ---------------------------------------------------------------------
   Printing (statements and reports)
   --------------------------------------------------------------------- */
/* While printing (set by app.js): the same narrow table cells as on paper, so tables can be measured */
html.is-printing table.ledger { font-size: 8pt; min-width: 0 !important; }
html.is-printing table.ledger th, html.is-printing table.ledger td { padding: 2px 2px; }
html.is-printing table.ledger thead th { font-size: 7.5pt; }
html.is-printing table.ledger th:empty, html.is-printing table.ledger td.row-actions { display: none; }
@page { size: A4; margin: 10mm 8mm; }
@media print {
  body { background: #fff; font-size: 10pt; }
  /* Tight tables on paper: every column of a long list fits the page width */
  table.ledger { font-size: 8pt; width: 100%; min-width: 0 !important; }
  table.ledger th, table.ledger td, table.ledger.compact th, table.ledger.compact td { padding: 2px 2px; }
  table.ledger thead th { font-size: 7.5pt; }
  table.ledger th:empty, table.ledger td.row-actions { display: none; }     /* empty "actions" column */
  .filters button, .filters .btn, .select-search, .quick, .pager { display: none !important; }
  .filters { margin-bottom: 0.4rem; gap: 0.3rem 0.8rem; }
  .filters input, .filters select { border: 0; padding: 0; min-height: 0; height: auto; background: none;
                                     appearance: none; -webkit-appearance: none; font-size: 9pt; }
  table.ledger tr { break-inside: avoid; }
  table.ledger thead { display: table-header-group; }   /* heading repeats on every printed page */
  .date-cell .wd { color: #333; }
  .log-details { font-size: 7.5pt; line-height: 1.35; }
  .print-head { display: flex !important; }
  .topbar, .sidebar, .no-print, .flash, .row-actions, .btn-delete { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .print-only { display: block; color: var(--muted); }
  .table-wrap { overflow: visible; max-height: none; border: 0; }
  table.ledger thead th { position: static; background: none; box-shadow: none; border-bottom: 2px solid #000; }
  .dev-credit { display: none; }
  .sub-banner, .receipt-actions, .notice, .quick-tiles { display: none !important; }
  .receipt { border: 0; box-shadow: none; padding: 0; }
  .signatures { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
