/* Pieces the kit does not have, for the registration (S-206/207) and slip (S-208) screens.
   Built only on the kit's tokens and classes (.panel, .ld-*, .m-*, .tag, .notice), the same
   way the kit adds a stylesheet per screen (leads.css). Load after rethink-backoffice.css. */

/* ---- Prototype badge (not part of the real back office) ---- */
.proto-badge {
  position: fixed;
  bottom: 16px;
  left: 260px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 276px);
  padding: 5px 6px 5px 12px;
  border: 1px solid #c3ae80;
  border-radius: 999px;
  background: #fff2d5;
  color: #684912;
  font-size: 0.75rem;
  box-shadow: var(--shadow);
}
.proto-label {
  font-weight: 600;
  white-space: nowrap;
}
.proto-badge select {
  min-height: 36px;
  max-width: 128px;
  padding: 4px 6px;
  border: 1px solid #c3ae80;
  border-radius: 6px;
  background: #fffaf0;
  color: #684912;
  font: inherit;
}
.proto-reset {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #c3ae80;
  border-radius: 50%;
  background: #fffaf0;
  color: #684912;
}
.proto-badge select:focus-visible,
.proto-reset:focus-visible {
  outline: 2px solid #684912;
  outline-offset: 2px;
}
@media (max-width: 1100px) {
  .proto-badge {
    left: 232px;
    max-width: calc(100vw - 248px);
  }
}
#modal-title:focus {
  outline: none;
}
/* Desktop: the last content can always scroll clear of the floating badge. */
@media (min-width: 1024px) {
  #main::after {
    content: "";
    display: block;
    height: 56px;
  }
}
/* Phones and tablets: a strip above the top bar (admin.js puts it before the app) that scrolls
   away with the page, so the bottom of the screen is the kit's own: tab bar, sticky buttons and
   toasts in their kit places. --proto-h stays for the rules that used to make room for it. */
@media (max-width: 1023px) {
  :root {
    --proto-h: 0px;
  }
  .proto-badge {
    position: static;
    justify-content: flex-start;
    max-width: none;
    min-height: 52px;
    padding: 4px 12px;
    border-width: 0 0 1px;
    border-radius: 0;
    box-shadow: none;
  }
  .proto-label {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .proto-badge select {
    flex: 1 1 0;
    min-width: 0;
    max-width: 160px;
    min-height: 44px;
  }
  .proto-reset {
    width: 44px;
    height: 44px;
    margin-left: auto;
  }
}
@media (max-width: 520px) {
  .proto-more {
    display: none;
  }
}

/* ---- Loading placeholders ---- */
.sk {
  display: block;
  height: 12px;
  margin: 6px 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 0%, var(--bg) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: sk-shine 1.3s ease-in-out infinite;
}
.sk-sm {
  height: 10px;
}
.sk-20 { width: 20%; }
.sk-30 { width: 30%; }
.sk-40 { width: 40%; }
.sk-50 { width: 50%; }
.sk-60 { width: 60%; }
.sk-70 { width: 70%; }
.sk-80 { width: 80%; }
.sk-90 { width: 90%; }
.sk-full { width: 100%; }
.sk-block {
  height: clamp(320px, 50vh, 520px);
  border-radius: 12px;
}
.sk-round {
  background: var(--line);
}
.m-end .sk {
  width: 56px;
}
@keyframes sk-shine {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sk {
    animation: none;
  }
}

/* ---- Registration list (S-206) ---- */
.rg-table th.num,
.rg-table td.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rg-table tbody tr[data-row] {
  cursor: pointer;
}
.rg-table tbody tr[data-row]:hover td {
  background: var(--bg);
}
.rg-code {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rg-org {
  min-width: 200px;
}
.rg-total {
  margin: 0;
  padding: 0 24px 12px;
}
.rg-filter-note {
  margin: 0 24px 16px;
}
.rg-soon,
.m-sub.rg-soon {
  color: #775112;
}
html[data-theme="dark"] .rg-soon,
html[data-theme="dark"] .m-sub.rg-soon {
  color: var(--gold);
}
.rg-num {
  font-variant-numeric: tabular-nums;
}
@media (max-width: 1023px) {
  .rg-total {
    padding: 0 2px 10px;
  }
  .rg-filter-note {
    margin: 0 0 10px;
  }
}

/* ---- Registration detail (S-207), inside the kit's lead dialog layout ---- */
#modal.rg-dialog {
  max-width: 760px;
}
.ld .notice {
  margin: 0;
}
.rg-h-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.rg-h-row .ld-h {
  margin: 0;
}
.rg-money dd {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rg-money .rg-total-row {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-weight: 600;
}
.rg-people,
.rg-pays,
.rg-notes {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.rg-people li {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 6px 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.rg-person {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.rg-contact {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
}
.rg-contact span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow-wrap: anywhere;
}
.rg-masked {
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.rg-reveal,
.rg-note-form {
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.rg-reveal[hidden],
.rg-note-form[hidden] {
  display: none;
}
.rg-reveal .actions,
.rg-note-form .actions {
  margin-top: 0;
}
.rg-note-form .field textarea {
  min-height: 96px;
}
.rg-logged {
  margin-bottom: 12px;
}
.rg-logged:focus {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.rg-pay {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.rg-pay-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.rg-pay > div {
  margin-top: 6px;
}
.rg-notes li {
  padding: 10px 14px;
  border-left: 3px solid var(--green);
  border-radius: 0 8px 8px 0;
  background: var(--bg);
}
.rg-notes p {
  margin: 0 0 2px;
}
.rg-steps {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 1.4em;
}
.tablewrap .rg-tiers {
  min-width: 0;
}
.rg-tiers th,
.rg-tiers td {
  padding: 10px 14px;
}
.rg-tiers th[scope="row"] {
  font-weight: 500;
  color: var(--ink);
  background: none;
}
.rg-tiers th[scope="row"] .sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}
.rg-tiers .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
dialog .actions .rg-left {
  margin-right: auto;
}
.rg-export .ld-states,
.sl-reasons {
  margin-bottom: 4px;
}
.ld-states .field-err {
  width: 100%;
}
@media (max-width: 560px) {
  .rg-people li {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 1023px) {
  dialog .actions .rg-left {
    margin-right: 0;
  }
}

/* ---- Slip review (S-208) ---- */
.sl-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.sl-layout.sl-empty {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
}
.sl-side {
  display: grid;
  gap: 22px;
  min-width: 0;
}
.sl-side .panel,
.sl-layout > .panel,
.sl-layout > div > .panel {
  margin-bottom: 0;
}
.sl-count {
  display: inline-block;
  min-width: 1.8em;
  margin-left: 4px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--green);
  font-size: 0.8rem;
  text-align: center;
  vertical-align: middle;
}
.sl-list,
.sl-done-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.sl-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 14px 20px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 3px 0 0 transparent;
}
.sl-list li:last-child .sl-item,
.sl-list .sl-item:last-child {
  border-bottom: 0;
}
.sl-item:hover {
  background: var(--bg);
}
.sl-item[aria-current="true"] {
  background: var(--soft);
  box-shadow: inset 3px 0 0 var(--green);
}
.sl-item:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: -3px;
}
.sl-sk {
  cursor: default;
}
.sl-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sl-code {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sl-org {
  display: block;
  overflow: hidden;
  font-size: 0.86rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sl-meta {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}
.sl-amounts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.sl-amounts > span {
  display: grid;
  min-width: 0;
}
.sl-amounts small {
  color: var(--muted);
  font-size: 0.78rem;
}
.sl-amounts b {
  font-size: 0.84rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sl-diff.bad b {
  color: var(--danger);
}
.sl-done-note {
  margin: 0;
  padding: 12px 24px 0;
}
.sl-done-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
.sl-done-row:last-child {
  border-bottom: 0;
}
.sl-done-row > div {
  display: grid;
  min-width: 0;
}

/* Viewer */
.panel.sl-viewer {
  overflow: visible;
}
.sl-viewer .panel-head p {
  margin-top: 2px;
}
.sl-viewer .panel-head h2:focus {
  outline: none;
}
.sl-viewer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
}
@media (min-width: 1360px) {
  .sl-viewer-grid {
    grid-template-columns: minmax(0, 1.05fr) minmax(300px, 1fr);
  }
}
.sl-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.sl-zoom {
  min-width: 52px;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.sl-stage {
  display: grid;
  place-items: safe center;
  height: clamp(420px, 64vh, 640px);
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.sl-stage:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}
.sl-canvas {
  position: relative;
  width: var(--bw, 320px);
  height: var(--bh, 560px);
}
.sl-slip {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--sw, 320px);
  height: var(--sh, 560px);
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  transition: transform 0.2s ease;
}
.sl-slip svg {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  box-shadow: 0 6px 24px #0f3a3d24;
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
}
.sl-slip.blurry svg {
  filter: blur(1.3px);
}
.sl-file {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.sl-info {
  display: grid;
  align-content: start;
  gap: 22px;
  min-width: 0;
}
.sl-hint {
  margin: 12px 0 0;
}
.sl-breakdown {
  margin-top: 8px;
  font-size: 0.88rem;
}
.sl-breakdown summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--blue);
  cursor: pointer;
}
.sl-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  background: var(--paper);
}
@media (max-width: 1023px) {
  .sl-layout,
  .sl-layout.sl-empty {
    grid-template-columns: minmax(0, 1fr);
  }
  .sl-viewer .panel-head {
    flex-wrap: wrap;
  }
  .sl-stage {
    height: min(70vh, 560px);
  }
  .sl-actions {
    bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--proto-h, 0px));
    padding: 10px 16px;
    border-radius: 0;
  }
  .sl-actions .btn {
    flex: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sl-slip {
    transition: none;
  }
}

/* ---- App shell on phones and tablets (kit app-shell.css, tabbar.mjs, me-sheet.mjs) ---- */
/* The kit writes the tab count in a style attribute; this CSP allows none, so the count is a
   class here (admin.js also sets --tabs from script). */
.tabbar.tabs-3 {
  --tabs: 3;
}
.tabbar.tabs-4 {
  --tabs: 4;
}
.tabbar.tabs-5 {
  --tabs: 5;
}
@media (max-width: 1023px) {
  /* The raised centre button's count sits on its circle (ตรวจสลิป for การเงิน). */
  .tab.main .tab-dot {
    top: -17px;
    left: calc(50% + 10px);
    box-shadow: 0 0 0 2px var(--paper);
  }
  .tab.main[aria-current="page"] .tab-label {
    color: var(--ink);
    font-weight: 700;
  }
  /* A sticky save bar sits on the tab bar, never under it. Writing screens (.app.task) have no
     tab bar and keep the kit's own bottom bar. */
  .app:not(.task) .savebar {
    bottom: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: 10px;
  }
  /* Long words and links wrap instead of widening the page. */
  .page {
    overflow-wrap: break-word;
  }
  /* Whatever a page scrolls to (a heading, the slip viewer, #no-next) stays clear of the top bar. */
  #main [id],
  #main h2 {
    scroll-margin-top: 72px;
  }
  /* Dialogs open as the kit's bottom sheets; a long one (registration, lead, run) keeps its
     buttons on screen at the bottom instead of after all the content. */
  dialog:not(.sheet) > .actions:last-child {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 20px -16px calc(-20px - var(--safe-b));
    padding: 12px 16px calc(12px + var(--safe-b));
    border-top: 1px solid var(--line);
    background: var(--paper);
  }
}

/* Content kinds under the เนื้อหา tab (RA.contentSegment): the kit's segment, but five kinds
   do not fit a phone, so it scrolls sideways when it must and fills the row when it can. */
.m-segment.ra-kinds {
  grid-auto-columns: minmax(max-content, 1fr);
  overflow-x: auto;
  scrollbar-width: none;
}
.m-segment.ra-kinds::-webkit-scrollbar {
  display: none;
}
.ra-kinds a {
  padding: 8px 14px;
  white-space: nowrap;
}

/* "บัญชีของฉัน" card and the account tile are buttons on the เมนู page (they open the sheet). */
button.me-card {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
button.me-card:hover,
button.tile:hover {
  border-color: var(--green);
}
.me-card > svg {
  flex: none;
  color: var(--muted);
}
.me-who {
  display: grid;
  flex: 1;
  min-width: 0;
}
.me-who .me-name,
.me-who .me-sub {
  display: block;
}
button.tile {
  width: 100%;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.more .tile[aria-current="page"] {
  border-color: var(--green);
}
.me-set {
  margin-bottom: 8px;
}
.me-set .set-row {
  min-height: 60px;
}

/* Sheets follow the finger when dragged down (admin.js swipeToClose) and spring back. */
dialog.sheet {
  transition: transform 0.2s ease;
}
dialog.sheet.is-dragging {
  transition: none;
}
.create-list .sheet-title {
  overflow-wrap: anywhere;
}
@media (prefers-reduced-motion: reduce) {
  dialog.sheet {
    transition: none;
  }
}
