/* รอบ 42: หน้ากลุ่มสิทธิ์พนักงาน (/staff-roles) + ปุ่มลิงก์ในหน้าผู้ใช้ — คลาสทั้งหมดขึ้นต้นด้วย sr- */

@media screen {
  /* ---------- หัวหน้า ---------- */
  .sr-seg {
    display: inline-flex; align-items: center; gap: 3px; padding: 4px; border-radius: 12px; background: var(--chip); flex: none;
  }
  .sr-seg button {
    display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border: 0; border-radius: 9px;
    background: none; color: var(--muted); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  }
  .sr-seg button:hover { color: var(--ink); }
  .sr-seg button.on { background: var(--surface); color: var(--brand-strong, var(--brand)); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
  .srg-tools .btn, .sr-users-link { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  a.sr-users-link, a.sr-users-btn { text-decoration: none; }

  /* ---------- โครง: รายการกลุ่ม | ตัวแก้ไข ---------- */
  .sr-body { min-height: 0; }
  .sr-split { display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); gap: 16px; min-width: 0; }
  .sr-split > .panel { margin: 0; min-width: 0; padding: 0; display: flex; flex-direction: column; }

  /* รายการกลุ่ม */
  .sr-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 8px; }
  .sr-list-head h2 { margin: 0; font-size: 1rem; }
  .sr-list-scroll { display: flex; flex-direction: column; gap: 8px; padding: 4px 12px 14px; }
  .sr-list-sep { margin: 8px 4px 0; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
  .sr-list-empty { margin-top: 6px; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; }
  .sr-list-empty p { margin: 0 0 8px; }

  .sr-card {
    display: flex; flex-direction: column; gap: 5px; width: 100%; padding: 11px 13px; text-align: left; cursor: pointer;
    border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit;
    transition: border-color .12s, background .12s, box-shadow .12s;
  }
  .sr-card:hover { border-color: var(--brand); }
  .sr-card.on { border-color: var(--brand); background: var(--brand-tint); box-shadow: inset 3px 0 0 var(--brand); }
  .sr-card-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .sr-card-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
  .sr-card-sub { font-size: .78rem; }
  .sr-card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--muted); }
  .sr-card-meta b { color: var(--ink); }
  .sr-used { display: inline-flex; align-items: center; gap: 4px; }
  .sr-disc { padding: 1px 7px; border-radius: 999px; background: var(--chip); font-weight: 600; }
  .sr-meter { display: block; height: 5px; border-radius: 999px; background: var(--chip); overflow: hidden; }
  .sr-meter i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }

  .srg-badge {
    flex: none; display: inline-flex; align-items: center; min-height: 20px; padding: 0 8px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-strong, var(--brand)); font-size: .72rem; font-weight: 700; white-space: nowrap;
  }

  /* ตัวแก้ไข */
  .sr-ed-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
  .sr-back { display: none; flex: none; }
  .sr-ed-titles { flex: 1 1 auto; min-width: 0; }
  .sr-ed-titles h2 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sr-ed-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }
  .sr-dirty { display: inline-flex; align-items: center; min-height: 20px; padding: 0 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn-text, #7a5300); font-size: .74rem; font-weight: 700; }
  .sr-ed-acts { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; flex: none; max-width: 60%; }
  .sr-copy {
    min-height: 34px; max-width: 220px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--surface); color: var(--ink); font: inherit; font-size: .85rem; cursor: pointer;
  }
  .sr-del { color: var(--danger); }
  html[data-theme="dark"] .btn.ghost.sr-del { color: var(--danger); }

  .sr-ed-scroll { padding: 14px 16px 16px; }
  .sr-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 2fr); gap: 12px; align-items: start; }
  .sr-form .field small { font-size: .74rem; line-height: 1.35; }
  .sr-pct { display: flex; align-items: center; gap: 6px; }
  .sr-pct input { flex: 1 1 auto; min-width: 0; }
  .sr-pct > span { color: var(--muted); font-weight: 700; }

  .sr-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 14px 0 10px; }
  .sr-legend > span { display: inline-flex; align-items: center; gap: 6px; }

  .sr-sens-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
  .sr-diff-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--brand); flex: none; }
  .sr-shop { display: inline-flex; align-items: center; padding: 0 6px; border-radius: 6px; background: var(--chip); color: var(--muted); font-size: .7rem; font-weight: 700; white-space: nowrap; }

  /* กลุ่มสิทธิ์: เรียงแบบคอลัมน์ให้แน่น */
  .sr-groups { columns: 300px; column-gap: 14px; }
  .sr-grp {
    break-inside: avoid; margin: 0 0 14px; padding: 4px 12px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
    display: block; width: 100%; box-sizing: border-box; min-width: 0;
  }
  .sr-grp.has { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
  .sr-grp-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 0; box-sizing: border-box; }
  .sr-grp-name { font-weight: 700; color: var(--ink); font-size: .92rem; }
  .sr-grp-n { padding: 0 7px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: .74rem; font-weight: 700; }
  .sr-grp-all { margin-left: auto; font-size: .8rem; text-decoration: none; white-space: nowrap; }
  .sr-grp-all:hover { text-decoration: underline; }

  .sr-perm {
    display: flex; align-items: flex-start; gap: 10px; padding: 7px 6px; margin: 0 -6px; border-radius: 8px; cursor: pointer;
    color: var(--ink); font-size: .88rem;
  }
  .sr-perm:hover { background: var(--brand-tint); }
  .sr-perm input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); cursor: pointer; }
  .sr-perm:not(.on) .sr-perm-label { color: var(--muted); }
  .sr-perm-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .sr-perm-label { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; line-height: 1.35; }
  .sr-help { display: flex; align-items: baseline; gap: 6px; color: var(--muted); font-size: .76rem; line-height: 1.35; }
  .sr-help .sr-sens-dot { width: 6px; height: 6px; transform: translateY(-1px); }

  /* แถบบันทึก */
  .sr-ed-foot { border-top: 1px solid var(--line); padding: 10px 16px; background: var(--surface); border-radius: 0 0 var(--radius-lg, 22px) var(--radius-lg, 22px); }
  .sr-err { margin: 0 0 8px; }
  .sr-foot-row { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
  .sr-foot-info { margin-right: auto; }

  .srg-warn { background: var(--warn-soft); color: var(--warn-text, #7a5300); border: 0; }

  /* ---------- มุมมองเปรียบเทียบ ---------- */
  .sr-mx-lead { margin: 0; }
  .sr-mx-wrap { overflow: auto; border-radius: var(--radius-lg, 22px); background: var(--surface); box-shadow: var(--shadow); }
  .sr-mx { width: auto; min-width: 100%; border-collapse: separate; border-spacing: 0; }
  .table.sr-mx th, .table.sr-mx td { padding: 5px 10px; border-bottom: 1px solid var(--line); line-height: 1.35; }
  .sr-mx thead th { position: sticky; top: 0; z-index: 3; background: var(--surface); vertical-align: bottom; }
  .sr-mx .sr-mx-perm {
    position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; font-weight: 500; font-size: .86rem;
    min-width: 220px; max-width: 300px; box-shadow: inset -1px 0 0 var(--line); white-space: normal; color: var(--ink);
  }
  .sr-mx .sr-mx-perm > span { margin-right: 6px; }
  .sr-mx thead .sr-mx-perm { z-index: 4; font-weight: 700; }
  .sr-mx-role { text-align: center; min-width: 96px; }
  .sr-mx-rolebtn {
    display: inline-flex; flex-direction: column; align-items: center; gap: 2px; max-width: 140px; padding: 4px 8px; border: 0; border-radius: 8px;
    background: none; color: var(--ink); font: inherit; cursor: pointer;
  }
  .sr-mx-rolebtn:hover { background: var(--brand-tint); color: var(--brand-strong, var(--brand)); }
  .sr-mx-name { font-weight: 700; font-size: .84rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .sr-mx-rolebtn small { color: var(--muted); font-size: .72rem; }
  .sr-mx-cell { text-align: center; color: var(--muted); }
  .sr-mx-cell.on { color: var(--brand); background: var(--brand-tint); }
  .sr-mx-no { opacity: .45; }
  .sr-mx-grp th {
    position: sticky; left: 0; text-align: left; background: var(--chip); color: var(--ink); font-size: .8rem; font-weight: 700; padding: 6px 10px;
  }
  .sr-mx tbody tr:not(.sr-mx-grp):hover td, .sr-mx tbody tr:not(.sr-mx-grp):hover .sr-mx-perm { background: var(--brand-tint); }

  /* ---------- toast ---------- */
  .sr-toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1200; display: flex; align-items: center; gap: 10px;
    max-width: min(92vw, 480px); padding: 10px 10px 10px 14px; border-radius: 14px; background: var(--ink); color: var(--surface);
    box-shadow: var(--shadow-lg); font-size: .9rem; animation: sr-toast-in .18s ease-out;
  }
  .sr-toast > svg { flex: none; color: var(--brand); }
  html[data-theme="dark"] .sr-toast > svg { color: var(--brand-strong); }
  .sr-toast-x { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 8px; background: none; color: inherit; opacity: .7; cursor: pointer; }
  .sr-toast-x:hover { opacity: 1; }
  @keyframes sr-toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

  /* หน้าผู้ใช้: คำแนะนำใต้รายการสาขา */
  .sr-users-hint { margin: 8px 0 0; }
  .branch-opt > .check { min-width: 0; }
  .branch-opt select { flex: 0 1 auto; min-width: 0; max-width: 62%; text-overflow: ellipsis; }
}

/* ---------- จอคอม: พอดีจอ แต่ละแผงเลื่อนในกรอบ ---------- */
@media screen and (min-width: 1025px) {
  .sr-body { overflow: hidden; }
  .sr-split { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
  .sr-split > .panel { min-height: 0; overflow: hidden; }
  .sr-list-scroll, .sr-ed-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .sr-ed-foot { flex: none; }
  .sr-mx-body { overflow: hidden; }
  .sr-mx-body > .sr-mx-wrap { flex: 1 1 auto; min-height: 0; }
}

/* จอกลาง: ฟอร์มสองคอลัมน์ */
@media screen and (max-width: 1280px) {
  .sr-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- แท็บเล็ต/มือถือ: สลับ รายการ ↔ ตัวแก้ไข ---------- */
@media screen and (max-width: 1024px) {
  .sr-split { grid-template-columns: minmax(0, 1fr); }
  .sr-split:not(.show-editor) > .sr-editor { display: none; }
  .sr-split.show-editor > .sr-list { display: none; }
  .sr-back { display: inline-grid; }
  .sr-ed-foot { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
  .sr-mx-wrap { max-height: 72vh; }
}

@media screen and (max-width: 760px) {
  .srg-tools { flex-wrap: wrap; }
  .srg-tools .sr-seg { flex: 1 1 auto; }
  .srg-tools .sr-seg button { flex: 1 1 0; justify-content: center; }
  .sr-users-btn span, .srg-add-btn span { display: none; }
  .sr-users-link span { display: none; }
  .sr-ed-head { flex-wrap: wrap; padding: 12px; }
  .sr-ed-titles { flex: 1 1 calc(100% - 52px); }
  .sr-ed-acts { max-width: none; width: 100%; justify-content: flex-start; }
  .sr-copy { flex: 1 1 auto; max-width: none; }
  .sr-ed-scroll { padding: 12px; }
  .sr-form { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .sr-groups { columns: auto; }
  .sr-perm { padding: 9px 6px; }
  .sr-ed-foot { bottom: calc(76px + env(safe-area-inset-bottom)); padding: 10px 12px; border-radius: 0; }
  .sr-foot-info { display: none; }
  .sr-foot-row .btn { flex: 1 1 0; }
  .sr-mx .sr-mx-perm { min-width: 150px; max-width: 180px; font-size: .8rem; }
  .sr-mx-role { min-width: 72px; }
  .sr-toast { bottom: calc(88px + env(safe-area-inset-bottom)); }
}

/* รอบ 103: หน้าต่างแก้ผู้ใช้ — พนักงานในระบบเงินเดือนที่ผูกกับผู้ใช้นี้ */
.usr-payroll { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 0; }
.usr-payroll strong { color: var(--ink); font-weight: 600; }
