/* ════════════════════════════════════════════════════════════════════════
   study-page-spaces.css: named Spaces and the All view on the Space home
   (public/js/study/study-page-spaces.js and study-page-files.js, drawn by
   study-pages.js). Loaded after study-pages.css, so it borrows that file's
   rows (.sp-row, .sp-ico) and tabs and only adds what is new: the shelf of
   Spaces, one Space's screen, the Source column and the file rows.
   Tokens and the tactile .k-btn come from /css/shared/khio-ui.css, so light
   and dark follow html[data-theme] with nothing to redo here.
   ════════════════════════════════════════════════════════════════════════ */

/* ── Which screen: the library, one Space, or the first visit ─────────────── */
.sp-home.is-first .sps-shelf,
.sp-home.in-space .sps-shelf, .sp-home.in-space .sp-tpls, .sp-home.in-space .sp-first, .sp-home.in-space .sp-tabs, .sp-home.in-space .sp-head-copy { display: none !important; }
.sp-home:not(.in-space) .sps-head { display: none !important; }
.sp-home.in-space .sp-search { margin-left: auto; }
.sp-home.in-space .sp-home-head { align-items: center; }

/* ── The shelf: your Spaces as cards over the tabs ───────────────────────── */
.sps-shelf { margin-bottom: 34px; }
.sps-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.sps-top .sp-eyebrow { margin: 0; }
.sps-top .sp-link svg { width: 15px; height: 15px; }
.sps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 12px; }
.sps-card { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 12px 16px 12px 12px; text-align: left; border-radius: 16px; border: 1px solid var(--k-line); background: var(--k-surface); color: var(--k-ink); cursor: pointer; outline: 0;
    transition: transform .3s var(--k-ease), box-shadow .3s var(--k-ease), border-color .2s ease; }
.sps-card:hover, .sps-card:focus-visible { transform: translateY(-2px); box-shadow: var(--k-shadow); border-color: color-mix(in srgb, var(--k-ink) 18%, var(--k-line)); }
.sps-card:focus-visible { box-shadow: 0 0 0 3px rgba(10, 132, 255, .25), var(--k-shadow); }
.sps-ico { flex: none; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--k-hover); color: var(--k-ink-2); font-size: 22px; line-height: 1; }
.sps-ico svg { width: 20px; height: 20px; }
.sps-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sps-text b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sps-text small { font-size: 12.5px; color: var(--k-ink-3); }

/* No Spaces yet: one slim card that says what they are and makes the first. */
.sps-banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px 14px 14px; border-radius: 16px; border: 1px dashed color-mix(in srgb, var(--k-ink) 22%, transparent); }
.sps-banner-ico { flex: none; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--k-hover); color: var(--k-ink-2); }
.sps-banner-ico svg { width: 20px; height: 20px; }
.sps-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sps-banner-text b { font-size: 15px; font-weight: 600; }
.sps-banner-text small { font-size: 13.5px; color: var(--k-ink-3); }

/* While the Spaces are on their way, and when they could not be loaded. */
.sps-skeleton { height: 68px; border-radius: 16px; background: linear-gradient(90deg, var(--k-hover), color-mix(in srgb, var(--k-ink) 7%, transparent), var(--k-hover)); background-size: 200% 100%; animation: sps-shimmer 1.4s ease-in-out infinite; }
@keyframes sps-shimmer { to { background-position: -200% 0; } }
.sps-line { margin: 0; padding: 18px 0; font-size: 14.5px; color: var(--k-ink-3); }

/* ── One Space: its name, its emoji and its count over its pages ─────────── */
.sps-head { flex: 1; min-width: 0; }
.sps-back { margin: 0 0 16px -2px; font-size: 14.5px; color: var(--k-ink-2); }
.sps-back svg { width: 16px; height: 16px; }
.sps-title-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.sps-emoji { flex: none; width: 60px; height: 60px; display: grid; place-items: center; border: 0; border-radius: 18px; background: var(--k-hover); color: var(--k-ink-2); font-size: 34px; line-height: 1; transition: background .15s ease, transform .2s var(--k-ease); }
button.sps-emoji { cursor: pointer; }
button.sps-emoji:hover { background: color-mix(in srgb, var(--k-ink) 9%, transparent); transform: scale(1.04); }
.sps-emoji svg { width: 28px; height: 28px; }
/* The name is a field as wide as its words: the wrapper holds a copy of them (data-value),
   which gives the field its width, so the menu beside it stays next to the name. The global
   field rules need an id to lose to. */
.sps-name-wrap { position: relative; flex: 0 1 auto; display: block; min-width: 0; margin-left: -8px; }
.sps-name-wrap::after { content: attr(data-value) ' '; display: block; visibility: hidden; white-space: pre; overflow: hidden; padding: 4px 8px; font-family: var(--k-display); font-weight: 500; font-size: clamp(34px, 3.4vw, 46px); line-height: 1.1; letter-spacing: -.025em; }
#view-deeptutor .sps-name, #view-deeptutor .sps-name:hover, #view-deeptutor .sps-name:focus { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; margin: 0; padding: 4px 8px; border: 0 !important; border-radius: 12px !important; background: none !important; box-shadow: none !important; outline: 0 !important;
    color: var(--k-ink) !important; font-family: var(--k-display) !important; font-weight: 500 !important; font-size: clamp(34px, 3.4vw, 46px) !important; line-height: 1.1; letter-spacing: -.025em; text-overflow: ellipsis; }
#view-deeptutor .sps-name:hover { background: var(--k-hover) !important; }
#view-deeptutor .sps-name:focus { background: var(--k-hover) !important; box-shadow: 0 0 0 3px rgba(10, 132, 255, .18) !important; }
.sps-title { margin: 0; font-family: var(--k-display); font-weight: 500; font-size: clamp(34px, 3.4vw, 46px); line-height: 1.1; letter-spacing: -.025em; }
.sps-count { margin: 8px 0 0 72px; font-size: 14.5px; color: var(--k-ink-3); }
.sps-more { flex: none; }

/* ── The list: a Source column, a Space beside a name, and the file rows ─── */
.sp-listhead { gap: 14px; }
.sp-lh-name { flex: 1; }
.sp-lh-src { flex: none; width: 128px; }
.sp-lh-when { flex: none; width: 110px; text-align: right; }
.sp-row-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sp-row-line .sp-row-title { flex: 0 1 auto; min-width: 0; }
.sp-row-src { flex: none; width: 128px; font-size: 13.5px; color: var(--k-ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sps-chip { flex: 0 1 auto; display: inline-flex; align-items: center; gap: 5px; min-width: 0; max-width: 190px; height: 22px; padding: 0 9px 0 7px; border-radius: 999px; background: var(--k-hover); color: var(--k-ink-2); font-size: 12.5px; font-weight: 500; line-height: 1; }
.sps-chip-ico { flex: none; display: grid; place-items: center; font-size: 12px; line-height: 1; }
.sps-chip-ico svg { width: 12px; height: 12px; }
.sps-chip-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-row:hover .sps-chip { background: color-mix(in srgb, var(--k-ink) 8%, transparent); }
/* Something Khio made that is not a page: no star, no menu, so a blank keeps the columns in line. */
.sp-ico.is-file { background: color-mix(in srgb, var(--k-blue) 12%, transparent); color: var(--k-blue); }
.sp-row:hover .sp-ico.is-file { background: color-mix(in srgb, var(--k-blue) 18%, transparent); }
.sp-row-gap { flex: none; width: 68px; }

/* ── New space: a name, and an emoji from a few that fit ─────────────────── */
#spLayer .sps-create { width: 300px; padding: 14px; border-radius: 14px; background: var(--k-surface); border: 1px solid var(--k-line); box-shadow: var(--k-shadow); animation: k-rise .2s var(--k-ease) both; }
#spLayer .sps-create-label { margin: 0 0 10px; font-size: 14.5px; font-weight: 600; }
#spLayer .sps-create-name { display: block; width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--k-line) !important; border-radius: 11px !important; background: var(--k-paper) !important; box-shadow: none !important; outline: 0 !important; color: var(--k-ink) !important; font: 15px var(--k-sans) !important; }
#spLayer .sps-create-name:focus { border-color: var(--k-blue) !important; box-shadow: 0 0 0 3px rgba(10, 132, 255, .14) !important; }
#spLayer .sps-create-icons { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; margin: 10px 0 12px; }
#spLayer .sps-create-ico { aspect-ratio: 1; display: grid; place-items: center; border: 0; border-radius: 9px; background: none; font-size: 19px; line-height: 1; cursor: pointer; transition: background .12s ease, transform .12s ease; }
#spLayer .sps-create-ico:hover, #spLayer .sps-create-ico:focus-visible { background: var(--k-hover); transform: scale(1.1); outline: 0; }
#spLayer .sps-create-ico.is-on { background: color-mix(in srgb, var(--k-blue) 14%, transparent); box-shadow: inset 0 0 0 1.5px var(--k-blue); }
#spLayer .sps-create-foot { display: flex; justify-content: flex-end; }

/* Keyboard focus: one blue ring on every control here. */
.sps-back:focus-visible, .sps-line .sp-link:focus-visible, .sps-top .sp-link:focus-visible, button.sps-emoji:focus-visible, .sps-more:focus-visible, #spLayer .sps-create-ico:focus-visible { outline: 2px solid var(--k-blue); outline-offset: 2px; }

@media (max-width: 1100px) {
    /* Wide enough for "From your texts", which is about 100px at this size. */
    .sp-row-src, .sp-lh-src { width: 108px; }
}
@media (max-width: 720px) {
    .sp-row-src, .sp-lh-src { display: none; }
    .sps-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .sps-banner { flex-wrap: wrap; }
    .sps-count { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .sps-skeleton, #spLayer .sps-create { animation: none; }
}
