/*
 * M04 · Đề xuất dịch vụ: the new screens on the module menu (design frames DeXuat, PheDuyet, LaySo). Every rule sits under
 * body.ui-m04, which proposal-ui.js sets only while CDLAF_FEATURES.ui('m04') is true (switch ui_proposals with module_nav);
 * without it the pages look as before. Loaded after modnav.css. Colours and sizes from the tokens of index.html.
 */

/* ---- Soạn đề xuất (M04-01) ---------------------------------------------------------------------------------------- */
/* UX-32 (M04#27): the form's one column follows the page, not the widest step button (402px on a 375px phone) */
body.ui-m04 #form { grid-template-columns: minmax(0, 1fr); }
body.ui-m04 #form > * { min-width: 0; }

/* the steps: four boxes of the same width, number in a circle (two rows of two on a phone) */
body.ui-m04 .steps-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; overflow: visible; padding-bottom: 0; }
body.ui-m04 .step { min-width: 0; min-height: 48px; gap: 10px; padding: 6px 12px; font-size: 13px; font-weight: 700; line-height: 1.3; }
body.ui-m04 .step > span:last-child { min-width: 0; overflow-wrap: anywhere; }
body.ui-m04 .step-no { width: 24px; height: 24px; }
body.ui-m04 .step[aria-current="step"] { color: var(--accent); }
body.ui-m04 .steps-nav .btn { min-height: 44px; }
@media (max-width: 560px) { body.ui-m04 .steps-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* "Số báo phí" at the top of the side rail; its "Lấy số" takes the place of the one by "Số báo giá" */
body.ui-m04 .ref-take #ref-take { display: none; }
body.ui-m04 .m4-ref { gap: 6px; }
body.ui-m04 .m4-ref-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
body.ui-m04 .m4-code { font-size: 11px; font-weight: 700; color: var(--accent); }
body.ui-m04 .m4-ref-no { font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
body.ui-m04 .m4-ref-no.none { font-size: 14px; font-weight: 400; color: var(--muted); }
body.ui-m04 .m4-ref-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
body.ui-m04 .m4-ref-acts .btn { width: auto; }

/* "Trạng thái đề xuất" (M04-05): the milestones on top of the panels "Phê duyệt" and "Xác nhận đề xuất", one card */
body.ui-m04 .m4-status { gap: 10px; }
body.ui-m04 .m4-status h2 { font-size: 14px; margin: 0; }
body.ui-m04 .m4-status > .note { margin: 0; font-size: 12px; }
body.ui-m04 .m4-track { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
body.ui-m04 .m4-ms { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
body.ui-m04 .m4-ms > span:last-child { display: grid; min-width: 0; }
body.ui-m04 .m4-ms .note { font-size: 12px; margin: 0; overflow-wrap: anywhere; }
body.ui-m04 .m4-dot { flex: none; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; box-sizing: border-box; border: 2px solid var(--line); background: var(--surface); }
body.ui-m04 .m4-ms.done .m4-dot { background: var(--ok); border-color: var(--ok); }
body.ui-m04 .m4-ms.now .m4-dot { border-color: var(--accent); }
body.ui-m04 .m4-ms.now b { color: var(--accent); }
body.ui-m04 .m4-ms.todo b { color: var(--muted); font-weight: 600; }
body.ui-m04 .m4-ms.rej .m4-dot { background: var(--danger); border-color: var(--danger); }
body.ui-m04 .m4-ms.rej b { color: var(--danger); }
/* the two panels under it read as the rest of the same card (the rail's gap is 14px) */
body.ui-m04 .rail > #m4-status { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
body.ui-m04 .rail > #m4-status ~ #approval-panel:not([hidden]),
body.ui-m04 .rail > #m4-status ~ #confirm-panel:not([hidden]) { margin-top: -15px; border-top-style: dashed; border-radius: 0; }
body.ui-m04 .rail > #m4-status ~ #confirm-panel:not([hidden]),
body.ui-m04 .rail > #m4-status ~ #approval-panel:not([hidden]):not(:has(+ #confirm-panel:not([hidden]))) { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
body.ui-m04 .rail > #m4-status ~ #approval-panel > h2, body.ui-m04 .rail > #m4-status ~ #confirm-panel > h2 { font-size: 13px; color: var(--muted); }

/* "Chọn khách hàng từ danh sách" at the top of the client section */
body.ui-m04 .m4-pick { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
body.ui-m04 .m4-pick .note { margin: 0; }

/* the fee table (step "Phí và thanh toán"; also in the approval request) */
body.ui-m04 .m4-fee-wrap { overflow-x: auto; }
body.ui-m04 .m4-fee { width: 100%; border-collapse: collapse; font-size: 13px; }
body.ui-m04 .m4-fee th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--sunken); padding: 8px 10px; border-bottom: 1px solid var(--line); }
body.ui-m04 .m4-fee td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
body.ui-m04 .m4-fee .num { text-align: right; white-space: nowrap; }
body.ui-m04 .m4-fee tr.head td { font-weight: 700; background: var(--sunken); }
body.ui-m04 .m4-fee tr.disc td:last-child { color: var(--accent); }
body.ui-m04 .m4-fee tr.sub td { font-weight: 600; }
body.ui-m04 .m4-fee tr.total td { font-weight: 700; border-bottom: 0; }

/* step "Lưu ý và xuất": the outputs and "Gửi duyệt" under the notes */
body.ui-m04 .m4-out { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
body.ui-m04 .m4-out .note { margin: 0; }
body.ui-m04 .m4-out-acts { display: flex; flex-wrap: wrap; gap: 8px; }
body.ui-m04 .m4-out-acts .btn { width: auto; min-height: 44px; }
/* D7: the time the proposal was last saved, at the foot of the form */
body.ui-m04 .m4-saved { margin: 12px 0 0; text-align: right; }

/* ---- Phê duyệt (M04-03): the list beside the request that is open ------------------------------------------------- */
@media (min-width: 1100px) {
  body.ui-m04 #view-approvals.m4-split { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); column-gap: 16px; align-items: start; }
  body.ui-m04 #view-approvals.m4-split > * { grid-column: 1 / -1; }
  body.ui-m04 #view-approvals.m4-split > #appr-list { grid-column: 1; }
  body.ui-m04 #view-approvals.m4-split > #appr-detail { grid-column: 2; grid-row: span 2; }
  body.ui-m04 #view-approvals.m4-split .hide-s { display: none; }   /* the narrow list: number, client, progress */
}
body.ui-m04 .m4-appr-head { display: grid; gap: 4px; }
body.ui-m04 .m4-appr-head .note { margin: 0; }
body.ui-m04 .m4-appr-matter { font-size: 13px; justify-self: start; }
body.ui-m04 .appr-detail .m4-fee-wrap { border-top: 1px solid var(--line); }

/* ---- Lấy số (M04-02, the proposal register): the next number large, as in the frame ------------------------------ */
body.ui-m04 #view-numbers .nb-next { gap: 10px 16px; padding: 18px; border-radius: var(--radius); }
body.ui-m04 #view-numbers .nb-next b { font-size: 26px; line-height: 1.2; color: var(--accent); }
body.ui-m04 #view-numbers .nb-next .btn { min-height: 44px; width: auto; }

/* ---- Thư viện mẫu (M04-07, frame ThuVienMau): groups, the list, the template's details ----------------------------- */
body.ui-m04 #view-library { display: grid; gap: 14px; }
body.ui-m04 .m4-lib-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
body.ui-m04 .m4-lib-q { flex: 1 1 300px; min-width: 0; display: flex; }
body.ui-m04 .m4-lib-q input { flex: 1; min-width: 0; min-height: 44px; }
body.ui-m04 .m4-lib-bar .btn { width: auto; min-height: 44px; }
/* groups and list side by side, the details under them; three columns on a wide screen (the module menu takes 232px) */
body.ui-m04 .m4-lib { display: grid; grid-template-columns: minmax(0, 230px) minmax(0, 1fr); gap: 16px; align-items: start; }
body.ui-m04 .m4-lib-detail { grid-column: 1 / -1; }
@media (min-width: 1500px) { body.ui-m04 .m4-lib { grid-template-columns: minmax(0, 230px) minmax(0, 3fr) minmax(0, 2fr); } body.ui-m04 .m4-lib-detail { grid-column: auto; } }
@media (max-width: 760px) { body.ui-m04 .m4-lib { grid-template-columns: minmax(0, 1fr); } }
body.ui-m04 .m4-lib-groups { display: grid; gap: 2px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
body.ui-m04 .m4-lib-groups button { font: inherit; text-align: left; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); cursor: pointer; }
body.ui-m04 .m4-lib-groups button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
body.ui-m04 .m4-lib-no { flex: none; width: 22px; font-size: 12px; font-weight: 700; color: var(--accent); }
body.ui-m04 .m4-lib-gname { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
body.ui-m04 .m4-lib-gname b { font-size: 13px; }
body.ui-m04 .m4-lib-gname .note { font-size: 11.5px; margin: 0; }
body.ui-m04 .m4-lib-n { flex: none; font-size: 12px; color: var(--muted); }
body.ui-m04 .m4-lib-groups > .note { margin: 6px 0 0; padding: 10px 10px 4px; border-top: 1px solid var(--line); font-size: 12px; }
body.ui-m04 .m4-lib-list { display: grid; gap: 10px; min-width: 0; }
body.ui-m04 .m4-lib-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
body.ui-m04 .m4-lib-head h2 { margin: 0; font-size: 17px; }
body.ui-m04 .m4-lib-row { cursor: pointer; }
body.ui-m04 .m4-lib-row.sel td { background: var(--accent-soft); }
body.ui-m04 .m4-lib-row td .note { display: block; font-size: 11.5px; margin: 0; }
body.ui-m04 .m4-lib-none { padding: 16px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 0; }
body.ui-m04 .m4-lib-detail { display: grid; gap: 10px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
body.ui-m04 .m4-lib-detail h3 { margin: 0; font-size: 16px; line-height: 1.35; }
body.ui-m04 .m4-lib-detail .note { margin: 0; }
body.ui-m04 .m4-lib-dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; margin: 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
body.ui-m04 .m4-lib-dl dt { color: var(--muted); }
body.ui-m04 .m4-lib-dl dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
body.ui-m04 .m4-lib-acts { display: flex; flex-wrap: wrap; gap: 8px; }
body.ui-m04 .m4-lib-acts .btn { width: auto; min-height: 40px; }
/* M04-07, the steps of the library: what waits, a version's line, a step's form */
body.ui-m04 .m4-lib-wait { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); }
body.ui-m04 .m4-lib-wait h2 { margin: 0 0 6px; font-size: 15px; }
body.ui-m04 .m4-lib-wait ul, body.ui-m04 .m4-lib-vers ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
body.ui-m04 .m4-lib-wait li .note { display: block; margin: 0; font-size: 12px; }
body.ui-m04 .m4-lib-wait .btn-link { text-align: left; font-weight: 600; }
body.ui-m04 .m4-lib-vers { border-top: 1px solid var(--line); padding-top: 10px; }
body.ui-m04 .m4-lib-vers h4, body.ui-m04 .m4-lib-step h4 { margin: 0 0 8px; font-size: 14px; }
body.ui-m04 .m4-lib-vers li { display: grid; gap: 3px; }
body.ui-m04 .m4-lib-vers li .note { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
body.ui-m04 .m4-lib-vacts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
body.ui-m04 .m4-lib-vacts .btn { width: auto; min-height: 36px; }
body.ui-m04 .m4-lib-step, body.ui-m04 .m4-lib-form { display: grid; gap: 10px; }
body.ui-m04 .m4-lib-step { padding: 12px; margin: 0; }
body.ui-m04 .m4-lib-form input[type="text"], body.ui-m04 .m4-lib-form select, body.ui-m04 .m4-lib-form textarea,
body.ui-m04 .m4-lib-step input[type="text"], body.ui-m04 .m4-lib-step textarea { width: 100%; min-height: 40px; }
body.ui-m04 .m4-lib-form input[type="file"], body.ui-m04 .m4-lib-step input[type="file"] { max-width: 100%; }
body.ui-m04 .m4-lib-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.4; }
body.ui-m04 .m4-lib-check input { margin-top: 3px; flex: none; }
body.ui-m04 .m4-lib-form .row .btn, body.ui-m04 .m4-lib-step .row .btn { width: auto; min-height: 40px; }
body.ui-m04 .m4-lib-fmsg { margin: 0; }
body.ui-m04 .m4-lib-form .seg { flex-wrap: wrap; }

/* M04-08 Danh sách đề xuất dịch vụ (proposals-list.js) */
body.ui-m04 .m4-pl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 12px; }
body.ui-m04 .m4-pl-st { flex-wrap: wrap; border-radius: 14px; }
body.ui-m04 .m4-pl-st button { min-height: 36px; }
body.ui-m04 .m4-pl-st b { font-weight: 700; margin-left: 2px; }
body.ui-m04 .m4-pl-period { display: flex; align-items: center; gap: 6px; }
body.ui-m04 .m4-pl-period select { min-height: 40px; }
body.ui-m04 .m4-pl-bar .btn { width: auto; min-height: 40px; }
body.ui-m04 .m4-pl-row { cursor: pointer; }
body.ui-m04 .m4-pl-row:hover td, body.ui-m04 .m4-pl-row:focus-visible td { background: var(--sunken); }
body.ui-m04 .m4-pl-table td.num { text-align: right; white-space: nowrap; }
/* the shared tables give their second column 220px: here it is the date */
body.ui-m04 .m4-pl-table th:nth-child(2) { min-width: 0; }
body.ui-m04 .m4-pl-table td:first-child b, body.ui-m04 .m4-pl-table td:nth-child(2) { white-space: nowrap; }
body.ui-m04 .m4-pl-table th:nth-child(4) { min-width: 130px; }
body.ui-m04 .m4-pl-table td .note { display: block; font-size: 12px; margin: 2px 0 0; }
body.ui-m04 .m4-pl-err { color: var(--danger); }
@media (max-width: 760px) {
  body.ui-m04 .m4-pl-table td.num { text-align: left; }
}
