/* Patterns × Sizes matrix — Atelier Grid (compact)
   Scoped under .pm-page and .pm-modal */

.pm-page {
  --pm-bg: #faf3e3;
  --pm-surface: #fefcf7;
  --pm-vellum: #f4e9cc;
  --pm-paper: #fbf6e8;
  --pm-ink: #0c0906;
  --pm-muted: #5c5040;
  --pm-muted-2: #8c7c6a;
  --pm-line: #c8be9c;
  --pm-gold: #a67c08;
  --pm-gold-2: #c99a28;
  --pm-gold-pale: #ecdfa0;
  --pm-gold-hair: rgba(166,124,8,.28);
  --pm-gold-tint: rgba(166,124,8,.06);
  --pm-gold-deep: #7a5808;
  --pm-crimson: #861616;
  --pm-crimson-soft: rgba(134,22,22,.10);
  --pm-green: #1e6b3e;

  background: var(--pm-bg);
  color: var(--pm-ink);
  font-family: 'Assistant', system-ui, sans-serif;
  font-weight: 700;
  padding: 18px 22px 32px;
  min-height: 100%;
  overflow-y: auto;
}

/* head */
.pm-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 12px;
}
.pm-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--pm-ink);
  letter-spacing: 0;
}
.pm-head .pm-sub {
  font-style: italic;
  font-weight: 500;
  font-size: 13px;
  color: var(--pm-muted);
}
.pm-head .pm-stats {
  margin-right: auto;
  display: inline-flex;
  align-items: baseline;
  gap: 14px;
  font-size: 12.5px;
  color: var(--pm-muted);
}
.pm-stats b {
  color: var(--pm-ink);
  font-weight: 800;
}
.pm-stats .pm-warn-count {
  color: var(--pm-crimson);
}

/* toolbar */
.pm-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.pm-search {
  flex: 0 1 280px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1.5px solid var(--pm-gold-hair);
  border-radius: 8px;
  background: var(--pm-surface);
  font-size: 13px;
}
.pm-search svg { color: var(--pm-gold); flex: 0 0 auto; }
.pm-search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font: inherit;
  font-weight: 700;
  color: var(--pm-ink);
}
.pm-pill {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--pm-gold-hair);
  background: var(--pm-paper);
  font-weight: 700;
  font-size: 12px;
  color: var(--pm-ink);
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.pm-pill:hover {
  border-color: var(--pm-gold-2);
  color: var(--pm-gold-deep);
}
.pm-pill.is-active {
  background: var(--pm-gold);
  border-color: var(--pm-gold-deep);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,240,200,.4);
}
.pm-pill.is-warn {
  background: var(--pm-crimson-soft);
  border-color: rgba(134,22,22,.32);
  color: var(--pm-crimson);
}
.pm-pill.is-warn.is-active {
  background: var(--pm-crimson);
  color: #fff;
  border-color: var(--pm-crimson);
}

/* card containing the matrix */
.pm-card {
  background: var(--pm-surface);
  border: 1px solid var(--pm-gold-hair);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(122,88,8,.04);
}

.pm-table-wrap { max-height: calc(100vh - 230px); overflow: auto; }

.pm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: inherit;
  font-size: 12.5px;
}
.pm-table thead th {
  position: sticky; top: 0; z-index: 2;
  padding: 7px 6px;
  background: linear-gradient(180deg, var(--pm-vellum), var(--pm-paper));
  border-bottom: 1.5px solid var(--pm-gold-2);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--pm-gold-deep);
  text-align: center;
  white-space: nowrap;
}
.pm-table thead th:first-child {
  text-align: right;
  padding-right: 12px;
}
.pm-table thead th.pm-th-size {
  background: linear-gradient(180deg, var(--pm-gold-pale), var(--pm-vellum));
}
.pm-table thead th.pm-th-clickable {
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s;
}
.pm-table thead th.pm-th-clickable:hover {
  background: linear-gradient(180deg, #e3d28a, var(--pm-gold-pale));
  color: var(--pm-ink);
}
.pm-table thead th.pm-th-clickable.is-active {
  background: linear-gradient(180deg, var(--pm-gold), #b88a14);
  color: #fff;
  position: relative;
}
.pm-table thead th.pm-th-clickable.is-active::after {
  content: '';
  position: absolute;
  bottom: -1.5px; left: 12%; right: 12%;
  height: 2.5px;
  background: var(--pm-gold-deep);
}
.pm-table thead th.pm-th-clickable .pm-th-x {
  display: none;
  margin-right: 4px;
  opacity: .85;
}
.pm-table thead th.pm-th-clickable.is-active .pm-th-x {
  display: inline;
}

.pm-table tbody tr {
  transition: background .12s;
}
.pm-table tbody tr:nth-child(even) {
  background: rgba(166,124,8,.022);
}
.pm-table tbody tr:hover {
  background: var(--pm-gold-tint);
}
.pm-table tbody td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(166,124,8,.10);
  text-align: center;
  font-weight: 700;
  vertical-align: middle;
}
.pm-table tbody tr:last-child td { border-bottom: none; }

/* name cell */
.pm-name-cell {
  text-align: right !important;
  padding: 5px 12px 5px 6px !important;
}
.pm-name-inner {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.pm-chip {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 1px solid var(--pm-gold-deep);
  box-shadow:
    inset 0 1px 1.5px rgba(255,255,255,.35),
    inset 0 -1.5px 2px rgba(0,0,0,.15);
  flex: 0 0 auto;
}
.pm-name {
  font-weight: 800;
  font-size: 13px;
  color: var(--pm-ink);
  line-height: 1.1;
}

/* size dot */
.pm-dot {
  display: inline-flex;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--pm-gold);
  box-shadow: inset 0 1px 0 rgba(255,240,200,.45);
  vertical-align: middle;
}
.pm-dot-off {
  display: inline-block;
  width: 12px; height: 1.5px;
  background: var(--pm-line);
  vertical-align: middle;
}

/* assoc link */
.pm-link {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(166,124,8,.07);
  color: var(--pm-gold-deep);
  font-size: 11.5px;
  font-weight: 800;
  border: 1px solid transparent;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pm-link.is-empty {
  background: transparent;
  color: var(--pm-muted-2);
  font-style: italic;
  font-weight: 500;
}

/* fur */
.pm-fur-yes {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(30,107,62,.10);
  border: 1px solid rgba(30,107,62,.30);
  color: var(--pm-green);
  font-size: 11px;
  font-weight: 800;
}

/* warn row */
.pm-warn-row td:first-child {
  box-shadow: inset 3px 0 0 var(--pm-crimson);
}
.pm-warn-tag {
  display: inline-block;
  padding: 1.5px 7px;
  border-radius: 3px;
  background: var(--pm-crimson-soft);
  color: var(--pm-crimson);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 1px solid rgba(134,22,22,.32);
  margin-right: 6px;
}

/* edit btn */
.pm-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 5px;
  border: 1px solid var(--pm-gold-hair);
  background: var(--pm-paper);
  color: var(--pm-gold-deep);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
}
.pm-act:hover {
  background: var(--pm-gold);
  color: #fff;
  border-color: var(--pm-gold-deep);
}
.pm-act.is-locked {
  background: transparent;
  border-color: rgba(166,124,8,.10);
  color: var(--pm-line);
  cursor: not-allowed;
}

/* empty state */
.pm-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--pm-muted);
  font-style: italic;
  font-size: 13px;
}

/* ═════════ MODAL (lookup popup in order form) ═════════ */
.pm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40,33,26,.32);
  z-index: 9998;
  animation: pmFade .15s ease both;
}
@keyframes pmFade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pmRise { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

.pm-modal {
  position: fixed;
  top: 50%;
  right: 24px;          /* RTL → screen-right is visual-left in our layout */
  transform: translateY(-50%);
  width: 540px;
  max-width: calc(100vw - 48px);
  height: calc(100vh - 32px);
  max-height: calc(100vh - 32px);
  background: var(--pm-surface, #fefcf7);
  color: #0c0906;
  font-family: 'Assistant', system-ui, sans-serif;
  font-weight: 700;
  border: 1.5px solid #c99a28;
  border-radius: 12px;
  box-shadow: 0 30px 60px -18px rgba(60,40,5,.35), 0 0 0 1px #faf3e3 inset;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  animation: pmRise .22s ease both;
}
/* When form sits on the right (admin) put modal on visual-left (CSS left in RTL = visual right; we want OPPOSITE side of the design card) */
.pm-modal.is-left { right: auto; left: 24px; }

.pm-modal-head {
  padding: 12px 14px 10px;
  border-bottom: 1.5px solid rgba(166,124,8,.28);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(180deg, #faf3e3, transparent);
  border-radius: 12px 12px 0 0;
}
.pm-modal-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.pm-modal-eyebrow {
  font-style: italic;
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #7a5808;
  font-weight: 600;
}
.pm-modal-h {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  color: #0c0906;
}
.pm-modal-close {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(166,124,8,.28);
  background: #fbf6e8;
  color: #7a5808;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}
.pm-modal-close:hover { background: #861616; color: #fff; border-color: #861616; }

.pm-modal-ctx {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(166,124,8,.06);
  border-bottom: 1px dashed rgba(166,124,8,.28);
  font-size: 11.5px;
  color: #7a5808;
}
.pm-modal-ctx b {
  font-weight: 800;
  color: #0c0906;
  padding: 1.5px 7px;
  border-radius: 4px;
  background: #fefcf7;
  border: 1px solid rgba(166,124,8,.28);
}

.pm-modal .pm-search { margin: 8px 12px 4px; }
.pm-modal .pm-table-wrap { flex: 1; max-height: none; }
.pm-modal .pm-table tbody tr { cursor: pointer; }
.pm-modal .pm-table tbody tr.is-current {
  background: rgba(166,124,8,.14);
  box-shadow: inset 3px 0 0 #a67c08;
}
.pm-modal .pm-table thead th.pm-th-current {
  background: linear-gradient(180deg, #ecdfa0, #f4e9cc);
  position: relative;
}
.pm-modal .pm-table thead th.pm-th-current::after {
  content: '';
  position: absolute;
  bottom: -1.5px; left: 6%; right: 6%;
  height: 2px;
  background: #a67c08;
}
.pm-modal .pm-table tbody td.pm-td-current {
  background: rgba(166,124,8,.05);
}

.pm-modal-foot {
  padding: 9px 14px;
  border-top: 1px solid rgba(166,124,8,.28);
  background: #faf3e3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: #5c5040;
  font-style: italic;
  border-radius: 0 0 12px 12px;
}
.pm-modal-foot button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(166,124,8,.28);
  background: #fefcf7;
  color: #7a5808;
  font: inherit;
  font-weight: 800;
  font-style: normal;
  font-size: 12px;
  cursor: pointer;
}
.pm-modal-foot button:hover { background: rgba(166,124,8,.10); }

/* magnifier button next to pattern field */
.pm-mag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-right: 6px;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid rgba(166,124,8,.28);
  background: #fbf6e8;
  color: #7a5808;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  font-size: 11.5px;
  transition: all .15s;
}
.pm-mag-btn:hover {
  background: #a67c08;
  color: #fff;
  border-color: #7a5808;
}
.pm-mag-btn svg { flex: 0 0 auto; }
