/* M02 Quản lý khách hàng và vụ việc, the new screens (design "Ứng dụng CDLAF – Thiết kế theo 9 module", 2026-10-29).
   Loaded after modnav.css. Everything here applies only when the module's new screens are on: the .m2-* blocks are drawn
   by client-list.js and matter-list.js only then, and the rules for Khởi tạo vụ việc (tracking.js) need the body of the
   new screens (body.mn-on: module_nav; no .feat-off-ui_clients: the module's switch). */

/* ---------------------------------------------------------------- shared: the bar above a list, the table */
.m2 { display: flex; flex-direction: column; gap: 14px; }
.m2-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.m2-search { flex: 1 1 300px; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 44px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.m2-search svg { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.m2-search input { flex: 1; min-width: 0; font: inherit; font-size: 13px; border: 0; outline: none; background: transparent; color: var(--ink); }
.m2-search:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.m2 .m2-btn { width: auto; min-height: 44px; padding: 0 16px; font-size: 13px; text-decoration: none; }
.m2-btn-line { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.m2-pick { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; }
.m2-pick select { font: inherit; font-weight: 400; font-size: 13px; min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.m2-note { margin: 0; font-size: 12px; color: var(--muted); }
.m2-muted { color: var(--muted); }
.m2-sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); }
.m2-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.m2-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.m2-table th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; background: var(--sunken); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.m2-table td { padding: 9px 12px; border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); vertical-align: top; }
.m2-table .num { text-align: right; }
.m2-table tr.m2-sel td { background: var(--accent-soft); }
.m2-code, .m2-link { font: inherit; font-weight: 700; color: var(--accent); background: none; border: 0; padding: 0; min-height: 28px; cursor: pointer; text-decoration: underline; text-align: left; }
.m2-link { font-weight: 400; }

/* ---------------------------------------------------------------- M02.1 Khách hàng: the list and the record beside it */
.m2-split { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.m2-main { flex: 999 1 560px; min-width: 0; }
.m2-main .m2-table { min-width: 560px; }
.m2-aside { flex: 1 1 340px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
.m2-rec-head { display: flex; flex-direction: column; gap: 2px; }
.m2-rec-head h2 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.35; }
.m2-rec-head > span { font-size: 12px; }
.m2-tabs { display: flex; gap: 0 18px; border-bottom: 1px solid var(--line); }
.m2-tabs button { font: inherit; font-size: 13px; min-height: 40px; margin-bottom: -1px; padding: 0; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--ink); cursor: pointer; }
.m2-tabs button[aria-selected="true"] { font-weight: 700; color: var(--accent); border-bottom-color: var(--accent); }
.m2-mini { font-size: 12.5px; min-width: 300px; }
.m2-mini th { font-size: 11.5px; padding: 7px 8px; }
.m2-mini td { padding: 7px 8px; }
.m2-mini td:first-child, .m2-mini td:nth-child(3) { white-space: nowrap; }
.m2-info { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.m2-kv { display: flex; justify-content: space-between; gap: 10px; }
.m2-kv > span:first-child { color: var(--muted); flex: none; }
.m2-kv > span:last-child { text-align: right; overflow-wrap: anywhere; }
.m2-kv-col { flex-direction: column; }
.m2-kv-col ul { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
.m2-acts { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.m2-acts .btn { width: auto; min-height: 40px; }
.m2-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 12px; }
.m2-form .span-all { grid-column: 1 / -1; }
.m2-form .field { display: grid; gap: 3px; font-size: 13px; }
.m2-form input, .m2-form select, .m2-form textarea { font: inherit; padding: 8px 10px; min-height: 40px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); width: 100%; box-sizing: border-box; }
/* the same client twice: red when it cannot be added, amber when staff must look (design KhoiTao) */
.m2-dupe:empty { display: none; }
.m2-dupe { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 6px; font-size: 13px; }
.m2-dupe ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.m2-dupe-stop { border: 1px solid var(--accent); background: var(--accent-soft); }
.m2-dupe-stop > b { color: var(--accent); }
.m2-dupe-ask { border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line)); background: var(--warn-soft); }
.m2-dupe-ask > b { color: var(--warn); }

/* ---------------------------------------------------------------- M02.2 Danh sách vụ việc */
.m2-reg { min-width: 880px; }
.m2-step { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--sunken); color: var(--ink); border: 1px solid var(--line); }
.m2-step-pre, .m2-step-proposal, .m2-step-sent, .m2-step-won { background: color-mix(in srgb, #2f5a96 10%, var(--surface)); color: color-mix(in srgb, #2f5a96 85%, var(--ink)); border-color: transparent; }
.m2-step-work { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); color: var(--ok); border-color: transparent; }
.m2-step-hold { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.m2-step-done { background: color-mix(in srgb, #8a4223 10%, var(--surface)); color: color-mix(in srgb, #8a4223 85%, var(--ink)); border-color: transparent; }

/* ---------------------------------------------------------------- phones: the rows as labelled cards (gridtable), the record below */
@media (max-width: 760px) {
  .m2 .m2-btn { flex: 1 1 auto; }
  .m2-aside { position: static; }
  .m2-main .m2-table, .m2-reg { min-width: 0; }
  .m2-table, .m2-table tbody, .m2-table tr, .m2-table td { display: block; width: auto; min-width: 0; }
  .m2-table thead { display: none; }
  .m2-table tbody tr { border-bottom: 1px solid var(--line); padding: 8px 10px; }
  .m2-table tbody tr:last-child { border-bottom: 0; }
  .m2-table td { border: 0; padding: 3px 0; }
  .m2-table td.num { text-align: left; }
  .m2-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 1px; }
}

/* ---------------------------------------------------------------- Khởi tạo vụ việc (tracking.js, design KhoiTao)
   Its own page while it is open: the board, its header and figures hide (tracking.js draws them; :has keeps them as they are). */
#view-tracking:has(> .m2-new) > :not(.m2-new):not(.tk-scrim):not(.tk-drawer) { display: none; }
.m2-new { display: flex; flex-direction: column; gap: 16px; margin: 0 0 16px; }
.m2-new-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.m2-new-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.m2-new-head span { font-size: 12px; color: var(--muted); }
.m2-new-cols { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.m2-new-form { flex: 3 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.m2-sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.m2-sec h3 { margin: 0; font-size: 15px; font-weight: 700; }
.m2-sec .field { display: grid; gap: 4px; font-size: 13px; }
.m2-sec input, .m2-sec select, .m2-sec textarea { font: inherit; min-height: 40px; box-sizing: border-box; }
.m2-kind { display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.m2-kind button { font: inherit; font-size: 13px; min-height: 42px; padding: 0 16px; border: 0; background: var(--surface); color: var(--ink); cursor: pointer; }
.m2-kind button + button { border-left: 1px solid var(--line); }
.m2-kind button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.m2-find input { width: 100%; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.m2-results { display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.m2-pick-row { font: inherit; font-size: 13px; text-align: left; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); cursor: pointer; }
.m2-pick-row:hover, .m2-pick-row:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.m2-dupes:empty { display: none; }
.m2-dupes { display: grid; gap: 8px; }
.m2-confirm { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.m2-confirm input { width: 18px; height: 18px; accent-color: var(--accent); }
.m2-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; }
.m2-foot .btn { width: auto; min-height: 44px; padding: 0 16px; }
.m2-stop { font-size: 12px; color: var(--accent); }
.m2-after { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; }
.m2-after h3 { margin: 0; font-size: 14px; font-weight: 700; }

/* ---------------------------------------------------------------- Xoá vụ việc at the foot of the matter's panel (design HoSoVuViec) */
.m2-del { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--sunken); font-size: 13px; }
.m2-del-text { flex: 1 1 260px; display: flex; flex-direction: column; gap: 4px; }
.m2-del .btn { width: auto; min-height: 40px; }
.m2-del .btn-danger:not(.btn-ghost) { border-color: var(--danger); color: var(--danger); }
.m2-del-why { flex: 1 1 100%; display: grid; gap: 4px; }
.m2-del-why textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }

/* ---------------------------------------------------------------- M02-08 Xoá và khôi phục vụ việc, Cổng Quản trị viên (matters-deleted.js) */
.m2-h { margin: 8px 0 0; font-size: 16px; font-weight: 700; }
.m2-h .m2-muted { font-size: 12px; font-weight: 400; margin-left: 6px; }
.m2 .btn-ghost { border-color: transparent; background: transparent; }
/* "Sửa vụ việc" (matter-record.js; the rule index.html kept for data-te, before the move) */
.tk-edit textarea[data-rec-e="title"] { font-weight: 600; }
/* "Chuyển cơ hội thành vụ việc" (M10): where the form came from */
.m2-opp { padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--sunken); color: var(--ink); }
.m2-opp-err { border-color: var(--accent); background: var(--accent-soft); }
