/* ─────────────────────────────────────────────────────────────────────────────
   Ledger & money capture (Phase 3 expense-form; Phase 4 /finances view).
   The `.xf-*` expense form lives in the bottom sheet and is reused by the place
   card's «+ سعر/إيصال» and the standalone «+ مصروف» add.
   ───────────────────────────────────────────────────────────────────────────── */

.xf {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.xf-place {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

/* Amount + currency picker */
.xf-amount-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.xf-amount {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  text-align: start;
}
.xf-amount:focus {
  outline: none;
  border-color: var(--brand);
}
.xf-curs {
  flex: none;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.xf-cur {
  min-width: 42px;
  padding: 6px 8px;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  transition:
    background 0.14s,
    color 0.14s;
}
.xf-cur.is-on {
  color: var(--brand);
  background: var(--surface);
  border-color: color-mix(in srgb, var(--brand) 40%, transparent);
}
.xf-preview {
  margin-top: -6px;
  min-height: 1.3em; /* reserved — the lek→﷼ line appearing must not jump the form */
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
}

/* Backfill (وقت آخر؟) — collapsed by default */
.xf-when {
  margin-top: 2px;
}
.xf-when-sum {
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-2);
}
.xf-when-sum::-webkit-details-marker {
  display: none;
}
.xf-when-sum::after {
  content: " ▾";
  color: var(--muted);
}
.xf-when[open] .xf-when-sum::after {
  content: " ▴";
}
.xf-when-input {
  margin-top: 8px;
  width: 100%;
  padding: 10px 13px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

/* Fields */
.xf-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.xf-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-2);
}
.xf-select,
.xf-note {
  width: 100%;
  padding: 11px 13px;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.xf-select:focus,
.xf-note:focus {
  outline: none;
  border-color: var(--brand);
}

/* Category chips */
.xf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.xf-chip {
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition:
    background 0.14s,
    color 0.14s,
    border-color 0.14s;
}
.xf-chip.is-on {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 13%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
}

/* Participants split override */
.xf-override {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
}
.xf-override-sum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 2px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.xf-override-sum::-webkit-details-marker {
  display: none;
}
.xf-override-hint {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
}
.xf-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 6px 2px 12px;
}
.xf-part {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink);
}
.xf-part-cb {
  width: 17px;
  height: 17px;
  accent-color: var(--brand);
}

/* Receipt */
.xf-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.xf-file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.xf-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.xf-file-name {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}
.xf-file-name.is-set {
  color: var(--brand);
  font-weight: 700;
}

/* Error + submit */
.xf-error {
  font-size: 0.85rem;
  font-weight: 700;
  color: #c0392b;
}
.xf-error:empty {
  display: none;
}
.xf-submit {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: var(--radius-sm);
  transition:
    opacity 0.14s,
    transform 0.1s;
}
.xf-submit:active {
  transform: scale(0.99);
}
.xf-submit:disabled {
  opacity: 0.7;
}

/* Softer error red on dark backgrounds. */
@media (prefers-color-scheme: dark) {
  .xf-error {
    color: #ff8a7a;
  }
}
:root[data-theme="dark"] .xf-error {
  color: #ff8a7a;
}
:root[data-theme="light"] .xf-error {
  color: #c0392b;
}

/* ═════════════════════════════════════════════════════════════════════════════
   «الحساب» — the /finances ledger view (Phase 4). Scoped to .view-finances.
   Reuses the app tokens (style.css) so light/dark + Thmanyah type come for free.
   ═════════════════════════════════════════════════════════════════════════════ */
.view-finances {
  max-width: var(--container-narrow);
  margin: 0 auto;
  padding: 14px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

/* ── Stat strip: the daily glance above everything ───────────────────────────*/
.fin-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.fin-stats:empty {
  display: none;
}
.fin-stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.fin-stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.fin-stat-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.fin-stat.is-plus .fin-stat-value {
  color: var(--brand);
}
.fin-stat.is-minus .fin-stat-value {
  color: var(--flag-red);
}

/* ── Header ──────────────────────────────────────────────────────────────────*/
.fin-head {
  padding: 8px 2px 14px;
}
.fin-eyebrow {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.fin-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.fin-lede {
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: 0.98rem;
  line-height: 1.7;
  max-width: 52ch;
}
.fin-sec-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  margin: 0;
}

/* ── Balances / settle-up panel ──────────────────────────────────────────────*/
.fin-balances {
  margin-top: 8px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.fin-balances-details > .fin-bal-head {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.fin-bal-head::-webkit-details-marker {
  display: none;
}
.fin-bal-head::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.2s ease;
}
.fin-balances-details[open] > .fin-bal-head::after {
  transform: rotate(180deg);
}
.fin-bal-head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.fin-bal-body > :first-child {
  margin-top: 14px;
}
.fin-bal-ico {
  display: inline-flex;
  width: 22px;
  height: 22px;
  color: var(--brand);
}
.fin-bal-ico svg {
  width: 100%;
  height: 100%;
}
.fin-bal-total {
  margin-inline-start: auto;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}
.fin-bal-empty {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.fin-bal-hint {
  margin: 14px 0 0;
  font-size: 0.76rem;
  line-height: 1.6;
  color: var(--muted);
}

/* Settle-up transfer lines — the actionable "who gives whom". */
.fin-settle {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.fin-settle-line {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
  border-radius: var(--radius-sm);
}
.fin-settle-from {
  font-weight: 800;
  color: var(--ink);
}
.fin-settle-give {
  display: inline-flex;
  width: 18px;
  height: 18px;
  color: var(--brand);
}
.fin-settle-give svg {
  width: 100%;
  height: 100%;
}
.fin-settle-to {
  font-weight: 800;
  color: var(--brand);
}
.fin-settle-amt {
  margin-inline-start: auto;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.fin-settle-clear {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--brand);
}
.fin-settle-clear-ico {
  display: inline-flex;
  width: 20px;
  height: 20px;
}
.fin-settle-clear-ico svg {
  width: 100%;
  height: 100%;
}

/* Per-member ledger table (name · paid · owed · net). */
.fin-ledger {
  margin-top: 16px;
  border-top: 1px solid var(--line);
}
.fin-ledger-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.fin-ledger-row.is-head {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 2px;
}
.fin-ledger-row.is-head span:first-child {
  visibility: hidden;
}
.fin-ledger-name {
  font-weight: 800;
  color: var(--ink);
}
.fin-ledger-num {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  text-align: end;
  min-width: 68px;
}
.fin-net {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: end;
  min-width: 84px;
  white-space: nowrap;
}
.fin-net.is-plus {
  color: var(--brand);
}
.fin-net.is-minus {
  color: var(--flag-red);
}
.fin-net.is-zero {
  color: var(--muted);
  font-weight: 700;
}

/* ── Expense list section ────────────────────────────────────────────────────*/
.fin-listwrap {
  margin-top: 22px;
}
.fin-list-title {
  margin-bottom: 4px;
}

/* Filters */
.fin-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 4px;
}
.fin-filters:empty {
  display: none;
}
.fin-filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}
.fin-filter-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  margin-inline-end: 2px;
}
.fin-chip {
  padding: 6px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition:
    background 0.14s,
    color 0.14s,
    border-color 0.14s;
}
.fin-chip.is-on {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 13%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
}

/* Expense rows, grouped by day */
.fin-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 12px;
}
.fin-day {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fin-day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 2px;
}
.fin-day-label {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink);
}
.fin-day-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  padding: 1px 8px;
  border-radius: 999px;
}
.fin-day-total {
  margin-inline-start: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.fin-empty {
  padding: 28px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}
.fin-x {
  display: flex;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.fin-x-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fin-x-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.76rem;
}
.fin-x-cat {
  padding: 2px 9px;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  border-radius: 999px;
}
.fin-x-place {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--ink-2);
  font-weight: 600;
}
.fin-x-place.is-general {
  color: var(--muted);
  font-weight: 600;
}
.fin-x-place-ico {
  display: inline-flex;
  width: 13px;
  height: 13px;
  color: var(--muted);
}
.fin-x-place-ico svg {
  width: 100%;
  height: 100%;
}
.fin-x-when {
  margin-inline-start: auto;
  color: var(--muted);
}
.fin-x-amount {
  display: flex;
  align-items: baseline;
  gap: 9px;
}
.fin-x-orig {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
}
.fin-x-sar {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
}
.fin-x-note {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--ink-2);
}
.fin-x-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.82rem;
  color: var(--ink-2);
}
.fin-x-payer strong {
  color: var(--ink);
  font-weight: 800;
}
.fin-x-split {
  color: var(--muted);
}

/* Side column: receipt thumbnail + delete */
.fin-x-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.fin-receipt {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
}
.fin-receipt-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.fin-receipt-full {
  display: flex;
  justify-content: center;
}
.fin-receipt-full-img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius-sm);
}
.fin-del {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition:
    color 0.14s,
    border-color 0.14s,
    background 0.14s;
}
.fin-del-ico {
  display: inline-flex;
  width: 17px;
  height: 17px;
}
.fin-del-ico svg {
  width: 100%;
  height: 100%;
}
.fin-del-label {
  font-size: 0.78rem;
  font-weight: 800;
}
.fin-del-label:empty {
  display: none;
}
.fin-del.is-armed {
  color: #fff;
  background: var(--flag-red);
  border-color: var(--flag-red);
}

/* Floating standalone add — labeled pill on the inline-end (left in RTL) corner,
   matching the places page FAB so the "standalone add" affordance is consistent. */
.fin-fab {
  position: fixed;
  inset-block-end: calc(18px + env(safe-area-inset-bottom, 0px));
  inset-inline-end: 18px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 13px 18px;
  font-size: 0.92rem;
  font-weight: 800;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 999px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--brand) 40%, transparent);
  transition: transform 0.12s;
}
.fin-fab:active {
  transform: scale(0.95);
}
.fin-fab-ico {
  display: inline-flex;
  width: 18px;
  height: 18px;
}
.fin-fab-ico svg {
  width: 100%;
  height: 100%;
}
