/* TimbreKit: the Plugins tab's rows and detail page, access-tier badges, the consent sheet, marketplace cards,
   the Activity table, the Install dialog, and the frames plugin pages show in. Written against css/tokens.css;
   switches, permission rows and state badges come from css/admin.css, the list/detail layout from css/queue.css. */

/* every built-in tab keeps the filter sidebar; a tab a plugin adds has the whole width */
body[data-tab="plugins"] #sidebar, body[data-tab="marketplace"] #sidebar, body[data-tab="activity"] #sidebar { display: block; }
body[data-tab="plugins"] #layout, body[data-tab="marketplace"] #layout, body[data-tab="activity"] #layout { grid-template-columns: var(--sidebar) 1fr; }
body[data-tab="plugins"] #layout.side-closed, body[data-tab="marketplace"] #layout.side-closed, body[data-tab="activity"] #layout.side-closed { grid-template-columns: 36px 1fr; }
/* #layout in these selectors outranks the folded sidebar's own rule (#layout.side-closed #sidebar, components.css):
   without it a folded sidebar came back on a plugin's tab, as a block above the page */
body[data-tab^="ext-"] #layout #sidebar { display: none; }
body[data-tab^="ext-"] #layout, body[data-tab^="ext-"] #layout.side-closed { grid-template-columns: 1fr; grid-template-rows: 1fr; }
#filter-list { padding: 4px 0 20px; }
#filter-list .opt .v { flex: 1; }
.tabs .ext-tab { display: inline-flex; align-items: center; gap: 6px; }
.tabs .ext-tab .pill { font-size: 10px; line-height: 16px; padding: 0 5px; }
.tabs .ext-tab::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); opacity: .6; }
#host-badge { margin: 0 4px; }

/* a plugin page's own tabs (Overview, Permissions). The page not shown keeps its width so frames in it still lay out */
.x-tabs { display: inline-flex; margin-top: 14px; }
.x-tabs button { display: inline-flex; align-items: center; gap: 6px; }
.x-tabs .pill { font-size: 10px; line-height: 16px; padding: 0 5px; }
.x-page.away { height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }
.x-page > .q-sec:first-child, .x-page > .x-os:first-child + .q-sec { margin-top: 12px; }

/* an access tier: the one word that says how much a plugin can do */
.tier { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px; font-size: 11px; white-space: nowrap; font-weight: 500;
  background: var(--raise); color: var(--text-2); }
.tier.medium { background: color-mix(in srgb, var(--warn) 16%, transparent); color: #ffd27a; }
.tier.high { background: color-mix(in srgb, #e0734c 20%, transparent); color: #f0a284; }
.tier.full { background: color-mix(in srgb, var(--error) 22%, transparent); color: #ff9c9c; }

/* a plugin's icon: its image, or its initial on a hue of its own */
.ext-icon { display: inline-grid; place-items: center; flex: none; border-radius: 7px; font-weight: 700; color: #fff; overflow: hidden;
  background: hsl(var(--h) 45% 38%); width: 28px; height: 28px; font-size: 13px; }
.ext-icon.sm { width: 22px; height: 22px; font-size: 11px; border-radius: 5px; }
.ext-icon.lg { width: 56px; height: 56px; font-size: 24px; border-radius: 12px; }
.ext-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* the list: a switch, the icon, name and meta, badges on the right */
.x-row { gap: 10px; }
.x-row.off .q-row-name, .x-row.off .ext-icon { opacity: .75; }
.x-row .q-row-name .pill { margin-left: 6px; }
.x-row .q-row-tags { gap: 6px; align-items: center; }
.switch.big { width: 40px; height: 22px; }
.switch.big i { border-radius: 11px; }
.switch.big i::after { width: 16px; height: 16px; }
.switch.big input:checked + i::after { transform: translateX(18px); }

/* the detail page */
.x-head { align-items: flex-start; }
.x-head .q-title h2 .tag { margin-left: 8px; font-size: 11px; vertical-align: 3px; }
.x-meta { gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.q-actions { align-items: center; }
.perm-list { padding: 2px 12px; }
.perm-list .perm-row { padding: 9px 2px; }
.perm-row .tier { margin-left: 6px; vertical-align: 1px; }
.perm-row .qual { margin-left: 5px; font-size: 11px; color: var(--text-2); background: var(--surface-2); padding: 0 5px; border-radius: 4px; }
.scope-id { font-size: 11px; color: var(--muted); white-space: nowrap; }
.table.act td { padding: 5px 10px 5px 0; }
.table.act.small td { font-size: 12px; }
.q-detail .kv { gap: 6px 18px; }
.q-detail .kv .mono { word-break: break-all; }

/* frames: a page a plugin shows. In a tab it fills the tab; on the detail page it sits in a box. */
.ext-frame { border: 0; width: 100%; display: block; background: transparent; color-scheme: dark; }
.ext-tab-host { position: absolute; inset: 0; }
.ext-tab-host .ext-frame { height: 100%; }
.frame-box { min-height: 40px; }
/* until the page reports its height (timbrekit/sdk.js), a frame keeps a modest one; then it is exactly its content */
.frame-box .ext-frame { height: 160px; }
.frame-box .ext-frame.sized { transition: height .12s ease-out; }
body.frame-borders .ext-frame { outline: 1px dashed var(--warn); outline-offset: -1px; }
#ext-background { position: absolute; width: 0; height: 0; overflow: hidden; }

/* the consent sheet */
dialog.consent { width: min(640px, calc(100vw - 32px)); }
.consent .modal-body { padding-top: 10px; }
.consent-desc { margin: 0 0 10px; color: var(--text-2); line-height: 1.5; }
.consent-tier { margin-top: 12px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.consent-tier h3 { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; font-size: 12px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.consent-tier.full { border-color: color-mix(in srgb, var(--error) 40%, transparent); }
.consent-tier.high { border-color: color-mix(in srgb, #e0734c 40%, transparent); }
.consent-row { padding: 9px 0; }
.consent-row:hover { background: none; }
.consent-label .tag { margin-left: 6px; }
.consent-why { line-height: 1.45; }
.consent-full { margin: 14px 2px 0; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--error) 40%, transparent); border-radius: 8px; color: var(--text); }
.consent-foot { gap: 8px; align-items: center; }

/* marketplace */
.mk-note { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.mk-body { flex: 1; min-height: 0; overflow-y: auto; }
.mk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding: 16px; }
.mk-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; color: inherit; }
.mk-card:hover, .mk-card:focus-visible { background: var(--surface-2); border-color: var(--line); outline: none; }
.mk-head { display: flex; align-items: center; gap: 10px; }
.mk-name { font-weight: 600; }
.mk-name .tag { margin-left: 6px; }
.mk-summary { margin: 0; color: var(--text-2); line-height: 1.45; flex: 1; }
.mk-foot { display: flex; align-items: center; gap: 8px; }
.mk-detail { display: grid; grid-template-columns: 1fr 260px; gap: 24px; align-items: start; }
.mk-h { margin: 16px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.mk-shots { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.mk-shots img { height: 180px; border-radius: 8px; border: 1px solid var(--border); }
.mk-side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 14px; }
.mk-actions { display: flex; gap: 8px; }
.mk-actions .btn { flex: 1; }

/* the Install dialog */
.install-ways { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.way { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; color: inherit; }
.way:hover { border-color: var(--line); background: var(--raise); }
.way.url { grid-column: 1 / -1; flex-direction: row; align-items: center; cursor: default; }
.way.url:hover { background: var(--surface-2); border-color: var(--border); }
.way.url input { flex: 1; }
.install-status { margin-top: 12px; }
.problems { margin: 6px 0 0; padding-left: 18px; color: var(--error); }
.problems li { margin: 2px 0; }

/* the Activity tab */
.act-wrap { flex: 1; min-height: 0; overflow: auto; padding: 0 16px 24px; }
.act-wrap .table th { position: sticky; top: 0; background: var(--page); }
.act-text .tag { margin-left: 6px; }
.act-wrap .q-more { display: block; margin: 12px auto; }

/* rendered Markdown (js/markdown.js) and toasts */
.markdown h2, .markdown h3, .markdown h4 { margin: 14px 0 6px; font-size: 14px; }
.markdown h2 { font-size: 16px; }
.markdown p, .markdown ul, .markdown ol { margin: 0 0 8px; color: var(--text-2); line-height: 1.55; }
.markdown code { background: var(--surface-2); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.markdown pre.raw { background: var(--surface-2); border-radius: 6px; padding: 8px 10px; font-size: 12px; overflow-x: auto; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 100; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: min(560px, calc(100vw - 32px)); transition: opacity .2s; }
.toast.err { color: var(--error); }
.toast.warn { color: var(--warn); }
.toast.out { opacity: 0; }

@media (max-width: 760px) {
  .mk-detail { grid-template-columns: 1fr; }
  .mk-side { position: static; }
  .install-ways { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  /* the template stacks the sidebar over the main area on a phone; keep that for every built-in tab */
  body[data-tab="plugins"] #layout, body[data-tab="marketplace"] #layout, body[data-tab="activity"] #layout { grid-template-columns: 1fr; }
  body[data-tab="plugins"] #layout.side-closed, body[data-tab="marketplace"] #layout.side-closed, body[data-tab="activity"] #layout.side-closed { grid-template-columns: 1fr; }
  #count, #host-badge { display: none; }
  .q-keys { display: none; }
  .x-head .q-actions { width: 100%; }
}

/* ---- the moderation page: an approved/active state, a warning line in a table --------------------------------- */
.state.ok { color: #199e70; background: color-mix(in srgb, #199e70 12%, transparent); }
.state.ok::before { background: #199e70; }
.warn-text { color: var(--warn); }
.admin-page .modal-body textarea { width: 100%; background: var(--page); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }

/* a macOS permission a plugin keeps running into (js/plugins.js osCard) */
.x-os:empty { display: none; }
.x-os { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.os-card { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 7%, var(--surface)); }
.os-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px;
  background: var(--warn); color: #1a1406; font-weight: 700; font-size: 13px; line-height: 1; }
.os-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.os-title { font-weight: 600; color: var(--text); }
.os-text { font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.os-text .mono { font-size: 11.5px; background: var(--raise); padding: 1px 5px; border-radius: 4px; }
.os-path b { font-weight: 600; color: var(--text); }
.os-path .sep { color: var(--muted); margin: 0 5px; }
.os-actions { flex: none; display: flex; gap: 6px; align-items: center; }
@media (max-width: 640px) { .os-card { flex-wrap: wrap; } .os-actions { width: 100%; justify-content: flex-end; } }
