/* kova/kraft-gallery.css — KRAFT designer gallery (split: 3D · filters)
   ------------------------------------------------------------------
   Additive styles for the gallery view only. Every value resolves to a
   token from tokens.css. Respects prefers-reduced-motion.
   ------------------------------------------------------------------ */

.krg-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.krg { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ============================================================
   TOOLBAR
   ============================================================ */
.krg-toolbar {
  display: flex; align-items: center; gap: var(--s-3);
  padding-bottom: var(--s-3); margin-bottom: var(--s-3);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.krg-toolbar-search {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 6px 10px; min-width: 240px;
  color: var(--mute);
}
.krg-toolbar-search input {
  border: 0; background: none; outline: none; font: inherit;
  font-size: var(--t-body-sm); color: var(--ink); width: 100%;
}
.krg-toolbar-search input::placeholder { color: var(--mute-2); }
.krg-toolbar-clearq { border: 0; background: none; cursor: pointer; color: var(--mute); font-size: 15px; line-height: 1; }
.krg-toolbar-clearq:hover { color: var(--ink); }

.krg-toolbar-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r-md); padding: 6px 11px; cursor: pointer;
  font: inherit; font-size: var(--t-body-sm); color: var(--ink-2);
  transition: border-color var(--m-1) var(--ease-out), background var(--m-1) var(--ease-out);
}
.krg-toolbar-toggle:hover { border-color: var(--line-strong); }
.krg-toolbar-toggle.is-on { border-color: var(--m-kraft); background: color-mix(in srgb, var(--m-kraft) 9%, var(--surface)); color: var(--m-kraft); }

.krg-select select {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r-md); padding: 7px 26px 7px 11px; cursor: pointer;
  font: inherit; font-size: var(--t-body-sm); color: var(--ink-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.krg-select select:hover { border-color: var(--line-strong); }

.krg-density { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.krg-density button {
  border: 0; background: var(--surface); cursor: pointer; padding: 6px 9px;
  font-size: 13px; color: var(--mute); line-height: 1;
}
.krg-density button + button { border-left: 1px solid var(--line); }
.krg-density button.is-on { background: var(--surface-3); color: var(--ink); }

/* ============================================================
   BODY · rail + main
   ============================================================ */
.krg-body { display: grid; grid-template-columns: 212px 1fr; gap: var(--s-4); flex: 1; min-height: 0; }
.krg-main { min-width: 0; overflow-y: auto; padding-bottom: var(--s-6); }

.krg-rail { overflow-y: auto; padding-right: var(--s-1); border-right: 1px solid var(--line-2); }
.krg-rail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-3); }
.krg-rail-clear { border: 0; background: none; cursor: pointer; color: var(--accent); font-size: var(--t-meta); font-weight: var(--w-semibold); }
.krg-rail-clear:hover { color: var(--accent-2); }

.krg-filtergroup { margin-bottom: var(--s-4); }
.krg-filtergroup-label {
  font-family: var(--font-mono); font-size: var(--t-eyebrow); letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase; color: var(--mute); margin-bottom: var(--s-2);
}
.krg-filtergroup-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.krg-chip-count { opacity: 0.6; font-variant-numeric: tabular-nums; margin-left: 3px; }

/* ============================================================
   SECTIONS (All view)
   ============================================================ */
.krg-section { margin-bottom: var(--s-6); }
.krg-section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--s-3); }
.krg-section-link { border: 0; background: none; cursor: pointer; color: var(--accent); font-size: var(--t-meta); font-weight: var(--w-semibold); }
.krg-section-link:hover { color: var(--accent-2); }

/* ============================================================
   GRID
   ============================================================ */
.krg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: var(--s-3); }
.krg-grid.is-compact { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
.krg-grid-3d { grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); }
/* 3D cards carry a rotate bar — keep them wide enough even in compact density.
   This must out-rank .krg-grid.is-compact (equal specificity → later wins). */
.krg-grid-3d.is-compact { grid-template-columns: repeat(auto-fill, minmax(204px, 1fr)); }

/* ============================================================
   GALLERY CARD
   ============================================================ */
.krg-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden; display: flex; flex-direction: column;
  transition: box-shadow var(--m-2) var(--ease-out), border-color var(--m-2) var(--ease-out), transform var(--m-2) var(--ease-out);
}
.krg-card:hover { box-shadow: var(--z-2); border-color: var(--line-strong); transform: translateY(-2px); }
.krg-card.is-selected { border-color: var(--m-kraft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--m-kraft) 26%, transparent); }

.krg-card-thumb { position: relative; aspect-ratio: 1; cursor: pointer; background: var(--surface-2); overflow: hidden; }
.krg-card-thumb:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.krg-card-thumb .kr-tile-canvas { width: 100%; height: 100%; display: block; }
.krg-card-toptags { position: absolute; top: 7px; left: 7px; display: flex; gap: 4px; }
.krg-card-select { position: absolute; top: 7px; right: 7px; }
.krg-card-star {
  position: absolute; bottom: 7px; right: 7px; border: 0; cursor: pointer;
  width: 24px; height: 24px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--surface) 78%, transparent); color: var(--mute-2);
  font-size: 14px; line-height: 1; display: grid; place-items: center;
  backdrop-filter: blur(3px); transition: color var(--m-1) var(--ease-out);
}
.krg-card-star:hover { color: var(--warn); }
.krg-card-star.is-on { color: var(--warn); }
.krg-card-id { position: absolute; bottom: 7px; left: 7px; font-size: 10px; color: var(--mute); background: color-mix(in srgb, var(--surface) 70%, transparent); padding: 1px 5px; border-radius: var(--r-xs); }

.krg-card-body { padding: var(--s-3); display: flex; flex-direction: column; gap: 6px; }
.krg-card-tag { font-size: var(--t-body-sm); color: var(--ink); font-weight: var(--w-medium); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.krg-card-meta { font-size: var(--t-meta); color: var(--mute); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.krg-dot { color: var(--mute-2); }
.krg-card-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.krg-card-act {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  width: 26px; height: 26px; border-radius: var(--r-sm); color: var(--ink-2);
  font-size: 13px; line-height: 1; display: grid; place-items: center;
  transition: border-color var(--m-1) var(--ease-out), background var(--m-1) var(--ease-out);
}
.krg-card-act:hover { border-color: var(--m-kraft); background: color-mix(in srgb, var(--m-kraft) 8%, var(--surface)); color: var(--m-kraft); }

/* ============================================================
   FAUX-3D STAGE
   ============================================================ */
.krg-3d { display: flex; flex-direction: column; }
.krg-3d-stage {
  position: relative; aspect-ratio: 4 / 3;
  background: radial-gradient(120% 90% at 50% 20%, var(--surface) 0%, var(--surface-2) 70%, var(--surface-3) 100%);
  perspective: 700px; cursor: grab; overflow: hidden;
  display: grid; place-items: center;
}
.krg-3d-stage:active { cursor: grabbing; }
.krg-3d-lg .krg-3d-stage { aspect-ratio: 16 / 11; }
.krg-3d-obj {
  position: relative; width: 56%; aspect-ratio: 1;
  transform-style: preserve-3d; will-change: transform;
}
.krg-3d-face {
  position: absolute; inset: 0; border-radius: var(--r-md); overflow: hidden;
  box-shadow: var(--z-2); backface-visibility: hidden;
}
.krg-3d-front { transform: translateZ(12px); }
.krg-3d-back  { transform: rotateY(180deg) translateZ(12px); filter: brightness(0.94); }
.krg-3d-face .kr-tile-canvas { width: 100%; height: 100%; }
.krg-3d-floor {
  position: absolute; left: 50%; bottom: 12%; width: 46%; height: 14px;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(50% 50%, rgba(11,13,16,0.18), transparent 70%);
}
.krg-3d-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line-2); flex-wrap: nowrap; }
.krg-3d-bar .k-chip { flex-shrink: 0; }
.krg-3d-hint { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.krg-3d-spinbtn {
  flex-shrink: 0; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  border-radius: var(--r-sm); padding: 4px 9px; font: inherit; font-size: var(--t-meta); color: var(--ink-2);
}
.krg-3d-spinbtn:hover { border-color: var(--line-strong); }
.krg-3d-spinbtn.is-on { border-color: var(--m-kraft); color: var(--m-kraft); background: color-mix(in srgb, var(--m-kraft) 9%, var(--surface)); }

/* ============================================================
   SELECTION BAR
   ============================================================ */
.krg-selbar {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: var(--s-2);
  background: var(--ink); color: #fff;
  border-radius: var(--r-md); padding: 8px 10px 8px 14px; margin-bottom: var(--s-3);
  box-shadow: var(--z-2);
}
.krg-selbar-count { font-size: var(--t-body-sm); font-weight: var(--w-semibold); }
.krg-selbar .k-btn { color: #fff; }

/* ============================================================
   INSPECT DRAWER BODY
   ============================================================ */
.krg-inspect-stage { margin-bottom: var(--s-4); }
.krg-inspect-flat {
  aspect-ratio: 4 / 3; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line); background: var(--surface-2);
}
.krg-inspect-flat .kr-tile-canvas { width: 100%; height: 100%; }
.krg-drawer-section { margin-bottom: var(--s-5); }
.krg-drawer-eyebrow { font-family: var(--font-mono); font-size: var(--t-eyebrow); letter-spacing: var(--tr-eyebrow); text-transform: uppercase; color: var(--mute); margin-bottom: var(--s-3); }
.krg-inspect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.krg-inspect-stat { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-md); padding: var(--s-3); }
.krg-inspect-stat-l { font-family: var(--font-mono); font-size: var(--t-eyebrow); letter-spacing: var(--tr-eyebrow); text-transform: uppercase; color: var(--mute); }
.krg-inspect-stat-v { font-size: var(--t-body); color: var(--ink); font-weight: var(--w-medium); margin-top: 3px; }
.krg-lineage { display: flex; align-items: center; gap: 8px; font-size: var(--t-body-sm); }
.krg-lineage-arrow { color: var(--mute-2); }
.krg-lineage-cur { color: var(--ink); }
.krg-lineage-v { color: var(--m-kraft); font-weight: var(--w-semibold); font-size: var(--t-meta); }

/* ============================================================
   VIEW TOGGLE (in KRAFT header) — small, reuses Seg look
   ============================================================ */
.kr-viewtoggle { margin-right: auto; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .krg-body { grid-template-columns: 1fr; }
  .krg-rail { border-right: 0; border-bottom: 1px solid var(--line-2); padding-bottom: var(--s-3); margin-bottom: var(--s-2);
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-3); }
  .krg-rail-head { grid-column: 1 / -1; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .krg-card:hover { transform: none; }
  .krg-3d-obj { transition: none; }
}
