/* Sổ nợ (#/so-no, Công cụ → Sổ nợ): a notebook — people + Tổng dư nợ on the left (top on phones), the picked
   person's page on the right (the whole screen on phones, with a "Danh sách" back button).
   Colours of a balance as css/revenue.css .rv-pos / .rv-neg / .rv-zero: blue positive, red negative, grey zero.
   Markup: js/view-so-no.js. Shell, buttons, forms, modals and toasts: ../styles.css. */

.view-so-no { padding: 0 10px 28px; }
.sn-wrap { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 10px; }
.sn-wrap * { box-sizing: border-box; }

/* v1.6.85 (Xám ấm – Bóng 70%): red #dc2626 and grey #6b7280 fell under 4.5:1 on the warm panel and page, the same
   colours darker (#b91c1c, #575e6b; CHANGES-GIAO-DIEN.md); blue #1d4ed8 passes and stays */
.sn-pos { color: var(--toi-chu-1d4ed8, #1d4ed8); }
.sn-neg { color: var(--toi-chu-b91c1c, #b91c1c); }
.sn-zero { color: var(--toi-chu-575e6b, #575e6b); }
.sn-money { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sn-bal { display: inline-flex; align-items: baseline; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.sn-bal-big .sn-money { font-size: 26px; line-height: 1.15; }
.sn-tag-over {
  display: inline-block; padding: 1px 7px; border-radius: 10px; background: var(--toi-nen-fee2e2, #fee2e2); color: var(--toi-chu-b91c1c, #b91c1c);
  font-size: 11px; font-weight: 700; white-space: nowrap; line-height: 1.5;
}

/* ---------------------------------------------------------- left: summary, search, people */
.sn-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
/* Tổng dư nợ: a warm cream panel with the gloss, the red line on its left */
.sn-summary {
  background: linear-gradient(180deg, var(--toi-nen-fbf8ef, #fbf8ef), var(--toi-nen-f2ecda, #f2ecda)) var(--toi-nen-f2ecda, #f2ecda); border: 1px solid var(--toi-vien-ddcfa6, #ddcfa6); border-radius: 8px; padding: 12px 14px;
  box-shadow: inset 4px 0 0 #b91e23, var(--xa-shadow);
}
.sn-sum-title { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--tts-ink, #23334e); font-size: 14px; }
.sn-sum-title .ic { color: var(--toi-chu-b91e23, #b91e23); }
.sn-sum-total { margin: 4px 0 6px; }
.sn-sum-total .sn-bal { justify-content: flex-start; }
.sn-sum-lines { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--toi-chu-4b5563, #4b5563); }
.sn-sum-lines .sn-money { font-weight: 600; }

.sn-search { display: flex; gap: 8px; align-items: stretch; position: relative; }
.sn-search .form-control { flex: 1 1 auto; min-width: 0; padding-left: 32px; height: 40px; }
.sn-search-ic { position: absolute; left: 10px; top: 0; height: 40px; display: flex; align-items: center; color: var(--xa-icon); pointer-events: none; }
.sn-add { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 40px; white-space: nowrap; }

.sn-people { background: var(--xa-gloss-long); border: 1px solid var(--xa-line); border-radius: 8px; overflow: hidden; box-shadow: var(--xa-shadow); }
.sn-list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 330px); min-height: 120px; overflow-y: auto; }
.sn-list li + li { border-top: 1px solid var(--xa-line-2); }
.sn-person {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px;
  width: 100%; min-height: 56px; padding: 9px 12px; background: transparent; border: 0; text-align: left; cursor: pointer; font: inherit; color: inherit;
}
.sn-person:hover { background: var(--xa-hover); }
.sn-person.is-active { background: var(--xa-rose-soft); box-shadow: inset 3px 0 0 #b91e23; }
.sn-person-name { font-weight: 700; color: var(--tts-ink, #23334e); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.sn-person-bal { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; }
.sn-person-sub { font-size: 11.5px; color: var(--xa-grey); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sn-badge { color: var(--toi-chu-146db1, #146db1); font-size: 12px; display: inline-flex; }
.sn-empty { padding: 18px 14px; color: var(--xa-grey); text-align: center; font-size: 13px; line-height: 1.6; }

/* ---------------------------------------------------------- right: one person */
.sn-main { min-width: 0; background: var(--xa-gloss-long); border: 1px solid var(--xa-line); border-radius: 8px; padding: 14px 16px 18px; box-shadow: var(--xa-shadow); }
.sn-placeholder { text-align: center; color: var(--xa-grey); padding: 48px 10px; }
.sn-placeholder .ic { font-size: 40px; color: var(--toi-chu-c9c3b9, #c9c3b9); }
.sn-placeholder p { margin: 10px 0 0; line-height: 1.6; }

.sn-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.sn-back { display: none; align-items: center; gap: 4px; }
.sn-head-name { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sn-head-name h2 { margin: 0; font-size: 20px; font-weight: 800; color: var(--tts-ink, #23334e); overflow-wrap: anywhere; }
.sn-linked { font-size: 12px; color: var(--toi-chu-146db1, #146db1); display: inline-flex; align-items: center; gap: 4px; }
.sn-head-note { font-size: 12.5px; color: var(--xa-grey); overflow-wrap: anywhere; }
.sn-head-acts { display: flex; gap: 6px; flex: none; }
.sn-icon-btn { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--xa-rose-line); }
.sn-danger { color: var(--toi-chu-b91c1c, #b91c1c); }
.btn-light.sn-danger { color: var(--toi-chu-9f1717, #9f1717); } /* on the rose-grey button: 5.4:1 */

.sn-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.sn-stat { background: var(--xa-field); border: 1px solid var(--xa-line-2); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sn-stat > span:first-child { font-size: 12px; color: var(--xa-grey); }
.sn-stat .sn-money { font-size: 15px; overflow-wrap: anywhere; white-space: normal; }
.sn-stat-main { background: var(--toi-nen-f8f3e4, #f8f3e4); border-color: var(--toi-vien-ddcfa6, #ddcfa6); }
.sn-stat-main .sn-bal { justify-content: flex-start; }
.sn-stat-main .sn-bal-big .sn-money { font-size: 24px; }

.sn-form, .sn-history { border-top: 1px dashed var(--xa-line); padding-top: 12px; margin-top: 4px; }
.sn-history { margin-top: 16px; }
.sn-form-title { font-weight: 800; color: var(--tts-ink, #23334e); margin-bottom: 8px; font-size: 14px; }
.sn-form-grid {
  display: grid; gap: 10px 12px; align-items: start;
  grid-template-columns: minmax(130px, 150px) minmax(220px, 260px) minmax(160px, 1fr);
  grid-template-areas: "date kind amount" "note note save";
}
.sn-f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sn-f > label { font-size: 12px; font-weight: 700; color: var(--toi-chu-4b5563, #4b5563); margin: 0; }
.sn-f-date { grid-area: date; }
.sn-f-kind { grid-area: kind; }
.sn-f-amount { grid-area: amount; }
.sn-f-note { grid-area: note; }
.sn-f-save { grid-area: save; justify-content: flex-end; }
.sn-f-save > label { visibility: hidden; }
.sn-form .form-control { height: 40px; }
.sn-save { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; min-width: 120px; font-weight: 700; }

.sn-kind { display: flex; border: 1px solid var(--xa-field-line); border-radius: 6px; overflow: hidden; height: 40px; }
/* v1.6.84: both options always whole ("Nhận tiền trả" was cut to "Nhận" on phones and at 768px): an option may shrink
   and its words wrap inside the box instead of running past it */
.sn-kind-opt { flex: 1 1 50%; min-width: 0; margin: 0; position: relative; cursor: pointer; }
.sn-kind-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sn-kind-opt span {
  display: flex; align-items: center; justify-content: center; gap: 5px; height: 100%; padding: 0 8px;
  font-size: 13px; font-weight: 600; color: var(--toi-chu-4b5563, #4b5563); background: var(--xa-field); white-space: normal; text-align: center; line-height: 1.15;
  overflow-wrap: anywhere; user-select: none;
}
.sn-kind-opt + .sn-kind-opt span { border-left: 1px solid var(--xa-field-line); }
.sn-kind-opt span .ic { font-size: 11px; }
.sn-kind-more input:checked + span { background: #1d4ed8; color: #fff; }
.sn-kind-pay input:checked + span { background: #15803d; color: #fff; }
.sn-kind-opt input:focus-visible + span { outline: 2px solid #4e73df; outline-offset: -3px; }

.sn-money-field { display: flex; flex-direction: column; gap: 3px; }
.sn-money-input { font-variant-numeric: tabular-nums; font-weight: 600; }
.sn-preview { min-height: 18px; font-size: 13px; font-weight: 700; color: var(--toi-chu-1d4ed8, #1d4ed8); }
.sn-preview.is-bad { color: var(--toi-chu-b91c1c, #b91c1c); font-weight: 600; }
.sn-preview.sn-zero { color: var(--toi-chu-575e6b, #575e6b); }
.sn-preview.sn-neg { color: var(--toi-chu-b91c1c, #b91c1c); }
.sn-hint { display: block; color: var(--xa-grey); font-size: 12px; margin-top: 3px; }

/* history */
.sn-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sn-table th {
  background: var(--th-red, #b8030a); color: #fff; font-weight: 600; padding: 8px 10px; text-align: left; white-space: nowrap;
}
.sn-table td { padding: 8px 10px; border-bottom: 1px solid var(--xa-line-2); vertical-align: middle; }
.sn-table .num { text-align: right; }
.sn-table th.num { text-align: right; }
.sn-table tbody tr:hover td { background: var(--xa-hover); }
.sn-row-opening td { background: var(--toi-nen-f3eedf, #f3eedf); color: var(--xa-grey); }
.sn-opening-label { font-weight: 600; }
.sn-row-none td { text-align: center; color: var(--xa-grey); padding: 16px; }
.sn-note-cell { color: var(--toi-chu-4b5563, #4b5563); overflow-wrap: anywhere; min-width: 120px; }
.sn-col-act { width: 1%; white-space: nowrap; text-align: right; }
.sn-act {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; margin-left: 2px;
  border: 1px solid transparent; border-radius: 6px; background: none; color: var(--toi-chu-4e73df, #4e73df); cursor: pointer;
}
.sn-act:hover { background: var(--toi-nen-eef3fd, #eef3fd); border-color: var(--toi-vien-c9d6f7, #c9d6f7); }
.sn-act.sn-danger { color: var(--toi-chu-dc2626, #dc2626); }
.sn-act.sn-danger:hover { background: var(--toi-nen-fee2e2, #fee2e2); border-color: var(--toi-vien-fecaca, #fecaca); }

/* dialogs */
.sn-modal .form-group { margin-bottom: 12px; }
.sn-mode { display: flex; gap: 6px; margin-bottom: 12px; }
.sn-mode-btn {
  flex: 1 1 50%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 8px;
  border: 1px solid var(--xa-field-line); border-radius: 6px; background: var(--xa-field); color: var(--toi-chu-4b5563, #4b5563); font: inherit; font-weight: 600; cursor: pointer;
}
.sn-mode-btn.is-on { background: #4e73df; border-color: #4e73df; color: #fff; }
.sn-pick { margin-top: 6px; border: 1px solid var(--xa-line-2); border-radius: 6px; max-height: 240px; overflow-y: auto; background: var(--xa-field); }
.sn-pick-list { list-style: none; margin: 0; padding: 0; }
.sn-pick-list li + li { border-top: 1px solid var(--xa-line-2); }
.sn-pick-item { display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 10px; min-height: 40px; cursor: pointer; }
.sn-pick-item:hover { background: var(--xa-hover); }
.sn-pick-item input { flex: none; }
.sn-pick-item span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.sn-pick-item small { color: var(--xa-grey); }
.sn-pick-item.is-taken { color: var(--toi-chu-8f897e, #8f897e); cursor: default; }
.sn-pick-item small.sn-pick-twin { flex: none; max-width: 48%; color: var(--toi-chu-9e4807, #9e4807); text-align: right; line-height: 1.25; }
.sn-modal .sn-kind { height: 44px; }

/* ---------------------------------------------------------- tablet: the form wraps */
@media (max-width: 1199.98px) {
  /* the Ngày box keeps its own width, the Loại toggle takes the rest of the row (both options whole at 768px) */
  .sn-form-grid { grid-template-columns: minmax(124px, 150px) minmax(0, 1fr); grid-template-areas: "date kind" "amount amount" "note note" "save save"; }
  .sn-f-save > label { display: none; }
  .sn-save { width: 100%; }
}
@media (max-width: 991.98px) {
  .sn-wrap { grid-template-columns: minmax(230px, 290px) minmax(0, 1fr); gap: 12px; }
  .sn-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------------------------------------------------------- phones: list OR person, stacked, big touch targets */
@media (max-width: 767.98px) {
  .view-so-no { padding: 0 8px 24px; }
  .sn-wrap { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 6px; }
  .sn-wrap.sn-has-person .sn-side { display: none; }
  .sn-wrap:not(.sn-has-person) .sn-main { display: none; }
  .sn-back { display: inline-flex; min-height: 44px; border: 1px solid var(--xa-rose-line); }
  .sn-head-name { order: 3; flex-basis: 100%; }
  .sn-head-acts { margin-left: auto; }
  .sn-icon-btn { min-height: 44px; }
  .sn-main { padding: 12px 12px 16px; }
  .sn-list { max-height: none; }
  .sn-person { min-height: 60px; }
  .sn-bal-big .sn-money { font-size: 24px; }

  .view-so-no input, .view-so-no select, .view-so-no textarea,
  .sn-modal input, .sn-modal select, .sn-modal textarea { font-size: 16px; }
  /* one field per row: Ngày, Loại (both options whole, 320–480px), Số tiền, Ghi chú, Lưu (v1.6.84) */
  .sn-form-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "date" "kind" "amount" "note" "save"; }
  .sn-search .form-control, .sn-add, .sn-form .form-control, .sn-save, .sn-kind { height: 44px; }
  .sn-search-ic { height: 44px; }
  .sn-kind-opt span { font-size: 14px; }
  .sn-modal .btn, .sn-mode-btn { min-height: 44px; }
  .sn-act { width: 44px; height: 44px; }

  /* history as cards: one entry per box, labels from data-label */
  .sn-table, .sn-table tbody, .sn-table tr, .sn-table td { display: block; width: 100%; }
  .sn-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .sn-table tr { border: 1px solid var(--xa-line); border-radius: 8px; margin-bottom: 8px; padding: 6px 10px; position: relative; background: var(--xa-gloss); box-shadow: var(--xa-shadow); }
  .sn-table tbody tr:hover td { background: none; }
  .sn-table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: right; min-height: 26px; }
  .sn-table td[data-label]::before { content: attr(data-label); color: var(--xa-grey); font-size: 12px; font-weight: 600; text-align: left; flex: none; }
  .sn-table td[data-label=""]::before, .sn-table td[data-label="Ghi chú"]:empty, .sn-table td.num:empty { display: none; }
  .sn-table td.sn-col-act { width: auto; justify-content: flex-end; padding-top: 4px; border-top: 1px dashed var(--xa-line-2); margin-top: 4px; }
  .sn-table td.sn-col-act:empty { display: none; }
  .sn-row-opening { background: var(--toi-nen-f3eedf, #f3eedf) !important; }
  .sn-row-opening td { background: none; }
  .sn-row-opening td:first-child { display: none; }
  .sn-row-none td { display: block; text-align: center; }
  .sn-note-cell { min-width: 0; }
}
@media (max-width: 380px) {
  .sn-add span { display: none; }
  .sn-stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .sn-kind-opt span { font-size: 13px; padding: 0 4px; }
}
