/* The two side panels: the item catalog drawer (catalog-ui.js) and the inspector (inspector.js).
   Built on style.css's tokens and its .group / .field / .switch / .stepper / .ghost classes. */

/* ---------- catalog drawer ---------- */
.cat-host {
	display: flex; flex-direction: column; min-height: 0; overflow: hidden;
	background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.cat-host[hidden] { display: none; }
/* it slides in from the left (a sheet rises on a phone); closing, it fades out in 140 ms (catalog-ui.js keeps it inert meanwhile) */
.cat-host:not([hidden]) { animation: cat-in var(--dur-2, 200ms) var(--ease, ease-out); }
.cat-host.cat-out { opacity: 0; transform: translateX(-10px); transition: opacity 140ms ease-in, transform 140ms ease-in; pointer-events: none; }
@keyframes cat-in { from { opacity: 0; transform: translateX(-14px); } }

.cat-top { flex: none; display: flex; flex-direction: column; gap: 10px; padding: 12px 12px 10px; border-bottom: 1px solid var(--line); }
.cat-search { display: flex; align-items: center; gap: 6px; }
.cat-q-wrap { position: relative; flex: 1; min-width: 0; display: flex; }
.cat-q-ic { position: absolute; left: 10px; top: 50%; width: 17px; height: 17px; margin-top: -8.5px; fill: var(--ink-3); pointer-events: none; }
.cat-q {
	flex: 1; min-width: 0; height: 36px; padding: 0 10px 0 34px; border: 1px solid var(--line-field); border-radius: var(--r-sm, 8px); background: var(--card);
	transition: border-color 120ms, box-shadow 120ms;
}
.cat-q::placeholder { color: var(--ink-3); }
/* one way to clear the search, inside the field (the browser's own blue × is hidden; the × beside the field closes the drawer) */
.cat-q::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.cat-q-wrap:has(.cat-clear:not([hidden])) .cat-q { padding-right: 34px; }
.cat-clear {
	position: absolute; right: 7px; top: 50%; width: 22px; height: 22px; margin-top: -11px; padding: 0; border: 0; border-radius: 50%;
	display: grid; place-items: center; background: color-mix(in srgb, var(--ink-3) 18%, transparent); color: var(--ink-2); cursor: pointer;
}
.cat-clear svg { width: 14px; height: 14px; fill: currentColor; }
.cat-clear:hover { background: color-mix(in srgb, var(--ink-3) 30%, transparent); color: var(--ink); }
.cat-q:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.cat-close { flex: none; width: 36px; height: 36px; padding: 0; border-color: transparent; background: transparent; }
.cat-close svg { width: 18px; height: 18px; fill: var(--ink-2); }
.cat-close:hover:not(:disabled) { background: var(--card); border-color: var(--line-2); }

/* the categories: one row that scrolls sideways (the wheel scrolls it too); its ends fade where more chips are */
.cat-chips {
	display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin: 0 -12px; padding: 1px 12px 2px;
	scroll-padding: 0 24px;
}
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chips.more-r { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); }
.cat-chips.more-l { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px); mask-image: linear-gradient(90deg, transparent, #000 36px); }
.cat-chips.more-l.more-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
.cat-chip {
	flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-pill, 999px); font-size: var(--fs-sm, 12px); font-weight: 550;
	border: 1px solid var(--line-2); background: var(--card); color: var(--ink-2); white-space: nowrap; transition: background 120ms, border-color 120ms, color 120ms;
}
.cat-chip b { font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: var(--fs-xs, 11px); }
.cat-chip:hover { border-color: var(--ink-3); color: var(--ink); }
.cat-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--card); }
.cat-chip[aria-pressed="true"] b { color: color-mix(in srgb, var(--card) 75%, var(--ink)); }
.cat-chip.empty { opacity: 0.45; }
.cat-chip:focus-visible, .cat-card:focus-visible, .insp-pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.cat-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 12px 14px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.cat-body h3 {
	margin: 14px 2px 8px; display: flex; align-items: baseline; gap: 6px; font-size: var(--fs-xs, 11px); font-weight: 700;
	text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3);
}
.cat-body h3 small { font-weight: 500; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; margin-top: 10px; }
.cat-body h3 + .cat-grid { margin-top: 0; }
.cat-empty { margin: 36px 8px; text-align: center; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cat-empty p { margin: 0; max-width: 30ch; }

.cat-card {
	display: flex; flex-direction: column; gap: 4px; padding: 6px 6px 8px; text-align: left; border-radius: var(--r-md, 10px);
	border: 1px solid var(--line); background: var(--card); user-select: none; touch-action: pan-y; cursor: grab;
	transition: border-color 120ms, box-shadow 120ms, transform 120ms;
}
.cat-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line-2)); box-shadow: var(--shadow); transform: translateY(-1px); }
.cat-card:active { cursor: grabbing; transform: none; }
.cat-card.dragging { opacity: 0.45; }
.cat-card > span { display: block; min-width: 0; padding: 0 2px; }
.cat-card > .cat-prev { padding: 0; }
.cat-prev { position: relative; display: grid; place-items: center; height: 78px; border-radius: var(--r-sm, 8px); background: var(--view-bg); overflow: hidden; }
.cat-prev canvas { display: block; transition: opacity 260ms ease, filter 260ms ease; }
/* a skeleton until the photo is ready: the flat stand-in, faded, under a slow sweep */
.cat-prev.wait canvas { opacity: 0.5; filter: saturate(0.6); }
.cat-prev.wait::after {
	content: ""; position: absolute; inset: 0; pointer-events: none;
	background: linear-gradient(100deg, transparent 20%, color-mix(in srgb, var(--card) 70%, transparent) 50%, transparent 80%) -150% 0 / 60% 100% no-repeat;
	animation: cat-sweep 1.4s ease-in-out infinite;
}
@keyframes cat-sweep { to { background-position: 250% 0; } }
/* a name gets two lines and its sizes three (they fit whole; the card's title has them too), and every card keeps two of each so the grid lines up */
.cat-card > .cat-name, .cat-card > .cat-facts {
	display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; white-space: normal; overflow-wrap: anywhere;
}
.cat-name { font-weight: 650; font-size: var(--fs-md, 13px); line-height: 1.25; min-height: 2.5em; }
.cat-card > .cat-facts { -webkit-line-clamp: 3; line-clamp: 3; }
.cat-facts { font-size: var(--fs-xs, 11px); line-height: 1.3; min-height: 2.6em; color: var(--ink-3); }

.cat-info { flex: none; min-height: 66px; padding: 9px 14px 11px; border-top: 1px solid var(--line); font-size: var(--fs-sm, 12px); line-height: 1.45; color: var(--ink-2); background: color-mix(in srgb, var(--card) 50%, var(--panel)); }
.cat-info b { display: block; margin-bottom: 1px; font-size: var(--fs-md, 13px); color: var(--ink); }
.cat-info.hint { color: var(--ink-3); }

.cat-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; will-change: transform; filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.3)); }
.cat-ghost canvas { display: block; border-radius: var(--r-sm, 8px); border: 1.5px solid var(--accent); background: color-mix(in srgb, var(--card) 85%, transparent); opacity: 0.94; transform: rotate(-2deg); }
body.cat-dragging, body.cat-dragging * { cursor: grabbing !important; user-select: none !important; }

/* ---------- inspector ---------- */
.insp-sel > .group:last-of-type { margin-bottom: 8px; }
.insp-sel > .group:first-child { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 8%, transparent); }
.insp-list { position: relative; list-style: none; margin: 0; padding: 0; max-height: 232px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; }
.insp-item { display: flex; align-items: center; border-radius: var(--r-sm, 8px); transition: background 120ms; }
.insp-item:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.insp-item.selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.insp-pick {
	flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 4px 6px; border: 0; background: transparent;
	text-align: left; border-radius: var(--r-sm, 8px);
}
.insp-icon { flex: none; width: 40px; height: 30px; border-radius: 5px; background: var(--view-bg); }
.insp-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-item.selected .insp-nm { font-weight: 650; }
.insp-item.see-through .insp-nm::after { content: " · invisible wall"; font-weight: 400; font-size: var(--fs-sm, 12px); color: var(--ink-3); }
.insp-x {
	flex: none; width: 28px; height: 28px; margin-right: 3px; padding: 0; border: 0; border-radius: var(--r-xs, 6px); background: transparent; color: var(--ink-3);
	font-size: 17px; line-height: 1; opacity: 0.7; transition: opacity 120ms, color 120ms, background 120ms;
}
.insp-item:hover .insp-x, .insp-item.selected .insp-x, .insp-x:focus-visible { opacity: 1; }
.insp-x:hover { color: var(--bad); background: var(--bad-soft); }
.insp-hint { margin: 8px 2px 0; font-size: var(--fs-sm, 12px); color: var(--ink-3); }

.field .insp-num { width: 84px; }   /* wide enough for 0.1025 beside the spin buttons */
.field .insp-text, .field .insp-select { flex: 0 1 62%; min-width: 0; width: auto; text-align: left; }
/* the material menu: drawn like the top bar's scenario menu (no native look), with the same chevron */
.field .insp-select, .field .insp-select:focus {
	cursor: pointer; height: 28px; padding: 0 26px 0 8px; appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
	background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 5px center / 18px;
}
.insp-xy { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.insp-xy label { display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-sm, 12px); color: var(--ink-2); }
.insp-xy .num { width: 100%; text-align: left; }

/* a value the builder capped: the box shows what was built, this line says what was asked */
.field .cap-note {
	display: flex; gap: 7px; align-items: flex-start; margin: 5px 0 1px; padding: 6px 9px; border-radius: var(--r-xs, 6px); font-size: var(--fs-sm, 12px); line-height: 1.4;
	color: var(--ink); background: color-mix(in srgb, var(--changed) 11%, var(--card)); border: 1px solid color-mix(in srgb, var(--changed) 32%, transparent);
	animation: cap-in 200ms ease;
}
.field .cap-note::before {
	content: "i"; flex: none; width: 15px; height: 15px; margin-top: 1px; border-radius: 50%; display: grid; place-items: center;
	font: 700 10px/1 Georgia, serif; font-style: italic; color: var(--card); background: var(--changed);
}
@keyframes cap-in { from { opacity: 0; transform: translateY(-3px); } }

.insp-about p { margin: 0 0 8px; font-size: var(--fs-md, 13px); line-height: 1.5; color: var(--ink-2); }
.insp-about p:last-child { margin-bottom: 0; }
.insp-about b { color: var(--ink); font-weight: 600; }
.insp-about .src { font-size: var(--fs-sm, 12px); color: var(--ink-3); }

.insp-actions { display: flex; gap: 8px; margin-top: 2px; }
.insp-actions .ghost { flex: 1; }
.ghost.danger { color: var(--bad); }
.ghost.danger:hover:not(:disabled) { border-color: var(--bad); background: var(--bad-soft); }

/* narrow screens: a card is a big touch target, the description strip gives the grid its room */
@media (max-width: 900px) {
	.cat-host:not([hidden]) { animation-name: cat-up; }
	.cat-host.cat-out { transform: translateY(16px); }
	.cat-info { display: none; }
	.cat-card { cursor: default; }
}
@keyframes cat-up { from { opacity: 0; transform: translateY(24px); } }
@media (prefers-reduced-motion: reduce) {
	.cat-prev.wait::after { animation: none; }
	.cat-card:hover { transform: none; }
}
