/* /templates: "My templates" and "Ready-made presets" (templates.js) */
.templates-page { box-sizing: border-box; width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px 0 48px; }
.tplp-heading h1 { margin: 0 0 6px; font-size: clamp(28px, 4vw, 38px); letter-spacing: -.8px; }
.tplp-heading p { margin: 0 0 22px; color: var(--text-secondary); font-size: 15px; }

.tplp-tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 18px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-subtle); }
.tplp-tab { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 16px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-secondary); font-size: 14px; font-weight: 500; box-shadow: none; }
.tplp-tab:hover:not(.is-active) { color: var(--text-primary); }
.tplp-tab.is-active { background: var(--bg-muted); color: var(--text-primary); box-shadow: var(--shadow-card), inset 0 0 0 1px var(--border-default); }
.tplp-count { min-width: 20px; padding: 1px 6px; border-radius: var(--radius-sm); background: var(--bg-muted); color: var(--text-secondary); font-family: var(--font-mono); font-size: 11.5px; text-align: center; }
.tplp-tab.is-active .tplp-count { background: var(--bg-surface); color: var(--text-primary); }
.tplp-tab:focus-visible, .tplp-chip:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; box-shadow: none; }

.tplp-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.tplp-search { flex: 1 1 260px; max-width: 420px; min-height: 40px; }
.tplp-toolbar > .secondary { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; }
.tplp-chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; }
.tplp-chip { min-height: 34px; padding: 6px 14px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-secondary); font-size: 13px; font-weight: 500; box-shadow: none; }
.tplp-chip:hover { color: var(--text-primary); border-color: var(--border-strong); }
.tplp-chip[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand-tint-border, var(--brand-accent)); color: var(--brand-tint-fg); }
[hidden].tplp-search, [hidden].tplp-chips, .tplp-toolbar > [hidden] { display: none; }

.tplp-list { display: grid; gap: 14px; }
.tplp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.tplp-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 18px 20px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); box-shadow: var(--shadow-card); }
.tplp-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.tplp-card-head h3 { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.tplp-id { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 3px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-page); color: var(--text-primary); box-shadow: none; }
.tplp-id code { font-family: var(--font-mono); font-size: 12.5px; }
.tplp-id:hover { border-color: var(--brand-accent); color: var(--brand-tint-fg); }
.tplp-tag, .tplp-live { padding: 2px 8px; border-radius: var(--radius-sm); background: var(--bg-muted); color: var(--text-secondary); font-size: 11.5px; font-weight: 500; }
.tplp-live { background: var(--brand-tint); color: var(--brand-tint-fg); }
.tplp-hint { margin: -4px 0 0; color: var(--text-secondary); font-size: 13.5px; line-height: 1.5; }

.tplp-menu { position: relative; }
.tplp-menu > summary { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer; list-style: none; }
.tplp-menu > summary::-webkit-details-marker { display: none; }
.tplp-menu > summary:hover, .tplp-menu[open] > summary { background: var(--bg-muted); color: var(--text-primary); }
.tplp-menu-list { position: absolute; z-index: 5; top: 36px; right: 0; display: grid; min-width: 170px; padding: 6px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); box-shadow: var(--shadow-card); }
.tplp-menu-list button { justify-content: flex-start; min-height: 34px; padding: 6px 10px; border: 0; background: transparent; color: var(--text-primary); font-size: 13.5px; text-align: left; box-shadow: none; }
.tplp-menu-list button:hover { background: var(--bg-muted); }
.tplp-menu-list .is-danger { color: var(--danger); }

/* [input] → 01 step → 02 step → [output]; long chains wrap onto the next line instead of scrolling */
.tplp-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 0; margin: 0; padding: 2px 0 4px; list-style: none; }
.tplp-flow li { display: flex; align-items: center; min-width: 0; max-width: 100%; }
.tplp-flow li + li::before { content: ""; width: 22px; height: 1px; margin: 0 2px; background: var(--border-strong); }
.tplp-node { display: inline-flex; align-items: baseline; gap: 2px; padding: 5px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-page); color: var(--text-primary); font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.tplp-node small { color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; }
.tplp-node em { color: var(--text-secondary); font-style: normal; font-size: 12px; }
.is-io .tplp-node { border-color: var(--brand-tint-border, var(--brand-accent)); background: var(--brand-tint); color: var(--brand-tint-fg); font-family: var(--font-mono); font-size: 12px; font-weight: 600; }

.tplp-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; color: var(--text-secondary); font-size: 13px; }
.tplp-dot { color: var(--text-muted); }
.tplp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.tplp-actions button { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 7px 14px; font-size: 13.5px; }
.tplp-empty { padding: 40px 24px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); text-align: center; }
.tplp-empty p { max-width: 460px; margin: 0 auto 16px; color: var(--text-secondary); }
.tplp-empty .tplp-actions { justify-content: center; }
.tplp-loading, .tplp-note { color: var(--text-secondary); font-size: 13px; }
.tplp-note { margin: 16px 0 0; }

/* API / n8n sheet */
.tplp-sheet { width: min(640px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text-primary); }
.tplp-sheet::backdrop { background: rgb(0 0 0 / .45); }
.tplp-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tplp-sheet-head h2 { margin: 0; font-size: 20px; }
.tplp-sheet h3 { margin: 18px 0 8px; font-size: 14px; }
.tplp-sheet-lead { color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.tplp-sheet-id { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tplp-sheet-id code { padding: 6px 10px; border-radius: var(--radius-md); background: var(--bg-page); font-family: var(--font-mono); font-size: 14px; }
.tplp-sheet button { display: inline-flex; align-items: center; gap: 7px; }
.tplp-code { max-height: 240px; margin: 0 0 10px; padding: 12px; overflow: auto; border-radius: var(--radius-md); background: var(--bg-page); font-family: var(--font-mono); font-size: 12px; line-height: 1.55; white-space: pre; }
.tplp-n8n { margin: 0; padding-left: 20px; color: var(--text-secondary); font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
.tplp-sheet-link { display: inline-block; margin-top: 16px; font-size: 13.5px; }

/* Studio: editing a template that the API already calls */
.live-template-dialog { width: min(480px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text-primary); }
.live-template-dialog::backdrop { background: rgb(0 0 0 / .45); }
.live-template-dialog h2 { margin: 0 0 8px; font-size: 19px; }
.live-template-dialog p { margin: 0 0 18px; color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.live-template-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.live-template-actions button { min-height: 42px; padding: 8px 16px; font-size: 14px; }
.live-template-actions .text-button { min-height: 0; }

@media (max-width: 700px) {
  .templates-page { padding-top: 20px; }
  .tplp-grid { grid-template-columns: minmax(0, 1fr); }
  .tplp-card { padding: 16px; }
  .tplp-actions button { flex: 1 1 auto; justify-content: center; }
  .tplp-toolbar > .secondary { margin-left: 0; }
}

/* Preset cards: category eyebrow above the title, one calm action row pinned to the bottom. */
.tplp-eyebrow { margin: 0 0 -6px; color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.tplp-preset .tplp-hint { margin: 0; }
.tplp-card .tplp-actions { display: flex; flex-wrap: nowrap; gap: 8px; margin-top: auto; }
.tplp-card .tplp-actions button { flex: 0 0 auto; width: auto; min-width: 0; justify-content: center; margin: 0; padding: 7px 10px; gap: 6px; font-size: 13px; white-space: nowrap; }
.tplp-card .tplp-actions button > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tplp-card .tplp-actions button > svg { flex: none; }
/* Only the narrow preset cards share the row between their two buttons; wide "My templates" cards keep natural widths. */
.tplp-preset .tplp-actions button { flex: 1 1 auto; }
/* A mouse click leaves no ring on the tabs and chips; the keyboard ring is the :focus-visible rule above. */
.tplp-tab:focus:not(:focus-visible), .tplp-chip:focus:not(:focus-visible) { outline: none; }
.tplp-tab:not(.is-active):focus:not(:focus-visible), .tplp-chip:focus:not(:focus-visible) { box-shadow: none; }
body .tplp-card .tplp-open { background: var(--brand-tint); border-color: var(--brand-tint-border); color: var(--brand-tint-fg); }
body .tplp-card .tplp-open:hover:not(:disabled) { border-color: var(--brand-accent); background: var(--brand-tint); color: var(--brand-tint-fg); }

/* There are no files on /templates: the storage note belongs to Studio and History only. */
body main.shell:has(> #templates-view:not([hidden])) > .storage-policy,
#templates-view:not([hidden]) ~ .storage-policy { display: none !important; }

/* Confirmation window (window.pipeidConfirm in app.js): a destructive action is red, not the teal main action. */
body .pipeid-confirm .primary.is-danger { background: var(--danger); border-color: var(--danger); color: var(--fg-inverse); }
body .pipeid-confirm .primary.is-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 88%, var(--fg-inverse)); border-color: var(--danger); color: var(--fg-inverse); }
