/* Shared UI toolkit: form controls, dialogs, popover menus. Used by the collections sidebar and the template editor. */
:root {
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --field: #1c120c;
  --field-line: #4c3828;
  --accent-soft: #efb64f22;
}
.grow { flex: 1; }
button.small, .button.small { min-height: 28px; padding: 4px 10px; font-size: 11px; }
button.link { all: unset; color: var(--gold); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 12px; }
button.link:hover { color: var(--cream); }
button.link:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 3px; }
.wide-btn { width: 100%; margin-top: 4px; border-style: dashed; color: var(--muted); }
.wide-btn:hover { color: var(--cream); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--gold); }
kbd { font: 600 10px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; background: #1c120c; color: var(--cream); }

/* ---------- form rows ---------- */
.f-row { display: block; margin: 0 0 12px; color: var(--muted); font-size: 11px; }
.f-label { display: block; font-size: 10px; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 5px; text-transform: none; }
.f-hint { display: block; margin-top: 5px; color: #9c8564; font-size: 10.5px; line-height: 1.5; }
.f-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 8px; }
.f-axis { display: block; position: relative; }
.f-axis-l { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); z-index: 1; font-size: 10px; font-weight: 700; color: var(--gold); pointer-events: none; }
.f-axis .f-num { padding-left: 22px; }
.f-hint-after { margin: -4px 0 12px; }
.f-grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.f-pair { display: flex; gap: 14px; align-items: center; min-height: 32px; }
.f-vgroup { display: block; }
.f-btnrow { display: flex; gap: 6px; align-items: center; margin: 0 0 12px; flex-wrap: wrap; }
.f-text, .f-select, .f-num, .f-hex {
  display: block; width: 100%; min-height: 32px; margin: 0; padding: 6px 9px; border-radius: 7px;
  border: 1px solid var(--field-line); background: var(--field); color: var(--cream); font-size: 12px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.f-text:hover, .f-select:hover, .f-num:hover, .f-hex:hover { border-color: #94683c; }
.f-text:focus, .f-select:focus, .f-num:focus, .f-hex:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px #efb64f26; }
textarea.f-text { resize: vertical; min-height: 60px; line-height: 1.5; }
.f-text.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
.f-select { padding-right: 24px; }
.f-unit { position: relative; display: block; }
.f-unit .f-num { padding-right: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.f-unit i { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 10px; color: #9c8564; pointer-events: none; }
.f-num::-webkit-outer-spin-button, .f-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.f-num { -moz-appearance: textfield; appearance: textfield; }

/* slider */
.f-slider { margin: 0 0 14px; }
.f-slider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.f-slider-head .f-label { margin: 0; }
.f-slider-end { display: flex; align-items: center; gap: 4px; }
.f-slider-end .f-unit { width: 84px; }
.f-slider-end .f-num { min-height: 26px; padding: 3px 28px 3px 6px; font-size: 11px; }
.f-reset { all: unset; cursor: pointer; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); font-size: 13px; transition: opacity 0.2s, background 0.2s, color 0.2s; }
.f-reset:hover { background: #644127; color: var(--cream); }
.f-reset.is-default { opacity: 0.25; pointer-events: none; }
.f-reset:focus-visible { outline: 2px solid var(--gold); }
.f-range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 18px; margin: 0; padding: 0; min-height: 0; background: transparent; cursor: pointer; border: 0; }
.f-range::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: linear-gradient(90deg, var(--gold) var(--pct, 0%), #3a2a1d var(--pct, 0%)); }
.f-range::-moz-range-track { height: 4px; border-radius: 3px; background: #3a2a1d; }
.f-range::-moz-range-progress { height: 4px; border-radius: 3px; background: var(--gold); }
.f-range::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--cream); border: 2px solid var(--gold); box-shadow: 0 1px 4px #0008; transition: transform 0.15s var(--ease); }
.f-range::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--cream); border: 2px solid var(--gold); }
.f-range:hover::-webkit-slider-thumb { transform: scale(1.18); }
.f-range:active::-webkit-slider-thumb { transform: scale(1.3); }
.f-range:focus-visible { outline: none; }
.f-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px #efb64f44; }

/* colour */
.f-colorwrap { display: flex; gap: 6px; align-items: center; }
.f-color { width: 34px !important; min-height: 32px !important; height: 32px; padding: 3px !important; margin: 0 !important; flex: none; border-radius: 7px !important; cursor: pointer; }
.f-hex { font-family: ui-monospace, monospace; text-transform: lowercase; min-width: 0; }

/* toggle */
.f-toggle { position: relative; display: inline-flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; color: var(--cream); font-size: 11.5px; user-select: none; }
.f-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; min-height: 0; }
.f-switch { position: relative; flex: none; width: 30px; height: 17px; border-radius: 9px; background: #3a2a1d; border: 1px solid var(--field-line); transition: background 0.2s var(--ease), border-color 0.2s; }
.f-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--muted); transition: transform 0.22s var(--ease), background 0.2s; }
.f-toggle input:checked + .f-switch { background: var(--gold); border-color: var(--gold); }
.f-toggle input:checked + .f-switch::after { transform: translateX(13px); background: #2a1608; }
.f-toggle input:focus-visible + .f-switch { outline: 2px solid var(--gold); outline-offset: 2px; }
.f-toggle:hover .f-switch { border-color: #94683c; }

/* segmented */
.f-seg { display: inline-flex; width: 100%; border: 1px solid var(--field-line); border-radius: 8px; background: var(--field); padding: 2px; gap: 2px; }
.f-seg button { flex: 1; min-height: 26px; padding: 3px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; box-shadow: none; transition: background 0.18s, color 0.18s; }
.f-seg button:hover { background: #3a2a1d; color: var(--cream); box-shadow: none; }
.f-seg button.on { background: var(--cream); color: #24160e; }

/* icon button */
.icon-btn { min-width: 30px; min-height: 30px; height: 30px; padding: 0 8px; border-radius: 8px; font-size: 14px; line-height: 1; background: transparent; border-color: transparent; color: var(--muted); }
.icon-btn:hover { background: #644127; color: var(--cream); border-color: transparent; }
.icon-btn.danger:hover { background: #7a2f1d; }

/* collapsible section */
.f-section { border-top: 1px solid #3a2a1d; margin: 0 -2px; }
.f-section:first-child { border-top: 0; }
.f-section > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 15px 2px 13px; cursor: pointer; user-select: none; color: var(--cream); font-size: 15px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; }
.f-section > summary::-webkit-details-marker { display: none; }
.f-section > summary:hover { color: var(--gold); }
.f-section > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; border-radius: 6px; }
.f-caret { display: inline-block; font-size: 11px; color: var(--muted); transition: transform 0.2s var(--ease); }
.f-section[open] > summary .f-caret { transform: rotate(90deg); }
.f-section-title { flex: 1; }
.f-section-actions { display: flex; }
.f-section-body { padding: 2px 2px 8px; animation: sectionIn 0.26s var(--ease); }
.f-section-body.flat { animation: none; padding: 0; }
@keyframes sectionIn { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- dialogs ---------- */
.dlg { padding: 0; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, #34261b, #261a12); color: var(--cream); box-shadow: 0 30px 90px #000b; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); animation: dlgIn 0.22s var(--ease); overflow: hidden; }
.dlg.dlg-wide { width: min(880px, calc(100vw - 32px)); }
.dlg::backdrop { background: #0a0604cc; backdrop-filter: blur(5px); animation: fadeIn 0.2s ease; }
.dlg.closing { animation: dlgOut 0.14s var(--ease-in) forwards; }
.dlg.closing::backdrop { animation: fadeOut 0.14s ease forwards; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes dlgOut { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
.dlg-body { padding: 24px 24px 20px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100dvh - 42px); }
.dlg-body h2 { margin: 0; font-size: 22px; }
.dlg-msg { color: var(--muted); font-size: 13px; line-height: 1.6; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dlg-actions.wrap { flex-wrap: wrap; }
.dlg button.danger { background: #7a2f1d; border-color: #b4472b; color: #ffe3d6; }
.dlg button.danger:hover { background: #a53b22; border-color: #e0623f; }
button.danger { color: #ffb59d; }

/* ---------- popover menu ---------- */
.popmenu { position: fixed; z-index: 60; min-width: 210px; max-width: 280px; max-height: min(70dvh, 520px); overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: #2d2018; box-shadow: 0 18px 50px #000a; animation: menuIn 0.16s var(--ease); transform-origin: top left; scrollbar-width: thin; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-5px) scale(0.97); } }
.popmenu button { width: 100%; justify-content: flex-start; gap: 8px; min-height: 32px; padding: 6px 9px; border: 0; border-radius: 7px; background: transparent; box-shadow: none; font-weight: 500; font-size: 12px; text-align: left; }
.popmenu button:hover:not(:disabled), .popmenu button:focus-visible { background: #644127; outline: none; box-shadow: none; }
.popmenu button.danger { color: #ffab94; }
.popmenu button.danger:hover:not(:disabled) { background: #7a2f1d; }
.pm-icon { width: 16px; text-align: center; color: var(--gold); flex: none; font-size: 12px; }
.pm-label { flex: 1; }
.pm-hint { color: #9c8564; font: 10px ui-monospace, monospace; }
.popmenu-sep { height: 1px; background: #4c3828; margin: 5px 4px; }
.popmenu-heading { padding: 8px 9px 4px; font-size: 9px; letter-spacing: 1.4px; color: var(--gold); font-weight: 700; text-transform: uppercase; }
.popmenu-swatches { display: flex; gap: 7px; padding: 4px 9px 8px; flex-wrap: wrap; }
.popmenu .swatch { width: 22px; min-height: 22px; height: 22px; padding: 0; border-radius: 50%; background: var(--sw); border: 2px solid transparent; flex: none; transition: transform 0.15s var(--ease); }
.popmenu .swatch:hover:not(:disabled) { background: var(--sw); transform: scale(1.18); }
.popmenu .swatch.on { border-color: var(--cream); box-shadow: 0 0 0 2px var(--sw); }

/* ---------- asset library ---------- */
.al { gap: 12px; padding: 22px; }
.al-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.al-head h2 { margin-right: auto; }
.al-head .f-text { width: 220px; }
.al-tabs { width: auto; }
.al-drop { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; border: 1.5px dashed #6b4d33; border-radius: 12px; color: var(--muted); font-size: 12px; transition: background 0.2s, border-color 0.2s; }
.al.over .al-drop { background: #efb64f1a; border-color: var(--gold); }
.al-uploads { display: grid; gap: 6px; empty-cells: hide; }
.al-uploads:empty { display: none; }
.al-up { display: grid; grid-template-columns: 1fr 160px; gap: 10px; align-items: center; font-size: 11px; color: var(--muted); }
.al-up.err { color: #ffab94; grid-template-columns: 1fr; }
.al-bar { height: 5px; border-radius: 3px; background: #3a2a1d; overflow: hidden; }
.al-bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.15s linear; }
.al-up.ok .al-bar i { background: #7ed6a4; width: 100% !important; }
.al-scroll { overflow: auto; min-height: 200px; max-height: 46dvh; scrollbar-width: thin; scrollbar-color: var(--line) transparent; padding: 2px; }
.al-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.al-card { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #231810; padding: 6px; cursor: pointer; transition: border-color 0.18s, transform 0.18s var(--ease), background 0.18s; }
.al-card:hover { border-color: #94683c; transform: translateY(-2px); }
.al-card:focus-visible { outline: 2px solid var(--gold); }
.al-card.on { border-color: var(--gold); background: #3a2815; box-shadow: 0 0 0 1px var(--gold); }
.al-thumb { position: relative; aspect-ratio: 4/3; border-radius: 6px; overflow: hidden; display: grid; place-items: center; background: repeating-conic-gradient(#2c2018 0 25%, #241912 0 50%) 0 0 / 14px 14px; }
.al-thumb img, .al-thumb video { width: 100%; height: 100%; object-fit: contain; }
.al-font { font-size: 34px; color: var(--cream); }
.al-badge { position: absolute; left: 5px; bottom: 5px; font-size: 8px; letter-spacing: 1px; padding: 2px 5px; border-radius: 4px; background: #000a; color: var(--cream); }
.al-meta { padding: 7px 2px 1px; min-width: 0; }
.al-name { display: block; font-size: 11px; color: var(--cream); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.al-card small { font-size: 10px; }
.al-del { position: absolute; top: 8px; right: 8px; min-width: 24px; width: 24px; height: 24px; min-height: 24px; padding: 0; background: #000a; opacity: 0; font-size: 11px; }
.al-card:hover .al-del, .al-card:focus-within .al-del { opacity: 1; }
.al-status { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 0; }
.al-status:empty { display: none; }
.al-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.al-url { display: flex; gap: 6px; flex: 1; min-width: 220px; max-width: 420px; }

@media (prefers-reduced-motion: reduce) {
  .dlg, .dlg::backdrop, .popmenu, .f-section-body { animation: none !important; }
}
