/* MasterCraft Asset Center - geometric style on the Milieu brand kit (assets/palette.txt).
   Light product surface: Snow White body, Midnight Navy ink, electric Blue accent used
   only for primary actions and selection. Density is a feature; color carries state. */

/* Layering tokens are global: modal + toast live outside .ac-root, so :root. */
:root { --ac-z-rail: 10; --ac-z-drawer: 40; --ac-z-modal: 60; --ac-z-toast: 70; }

.ac-root {
  --ac-bg: #f8f9fa;          /* Snow White */
  --ac-surface: #ffffff;
  --ac-surface-2: #e9ecef;   /* Cloud Grey */
  --ac-ink: #0a1d37;         /* Midnight Navy */
  --ac-ink-muted: #4f5d75;   /* Steel Blue */
  --ac-line: #bcbec0;        /* Grey */
  --ac-accent: #0f69f0;      /* Blue */
  --ac-accent-ink: #ffffff;
  --ac-ok-bg: #e7fbdb; --ac-ok-ink: #0c3e26;
  --ac-warn-bg: #ffedd9; --ac-warn-ink: #8a3a00;
  --ac-err: #d90429;
  --ac-radius: 8px;
  --ac-gap: 12px;
  --ac-z-rail: 10; --ac-z-drawer: 40; --ac-z-modal: 60; --ac-z-toast: 70;

  display: flex; flex-direction: column;
  min-height: calc(100vh - 220px);
  background: var(--ac-bg);
  color: var(--ac-ink);
  font: 400 14.4px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- buttons: one vocabulary, every state ---------- */
.ac-root .btn {
  appearance: none; border: 1px solid var(--ac-accent); border-radius: var(--ac-radius);
  padding: 7px 14px; font: 600 13px/1.2 inherit; letter-spacing: 0; cursor: pointer;
  background: transparent; color: var(--ac-accent);
  transition: background-color 180ms cubic-bezier(0.25, 1, 0.5, 1), color 180ms cubic-bezier(0.25, 1, 0.5, 1), border-color 180ms ease;
}
.ac-root .btn:hover { background: rgba(15, 105, 240, 0.08); }
.ac-root .btn:active { background: rgba(15, 105, 240, 0.16); }
.ac-root .btn:disabled { border-color: var(--ac-line); color: var(--ac-ink-muted); background: var(--ac-surface-2); cursor: not-allowed; opacity: 0.7; }
.ac-root .btn-primary { background: var(--ac-accent); color: var(--ac-accent-ink); }
.ac-root .btn-primary:hover:not(:disabled) { background: #0b57c4; }
.ac-root .btn-primary:active:not(:disabled) { background: #0a4ba8; }
.ac-root .btn:focus-visible,
.ac-root .ac-mode-btn:focus-visible,
.ac-root .ac-chip:focus-visible,
.ac-root .ac-tile:focus-visible,
.ac-root .ac-search:focus-visible { outline: 2px solid var(--ac-accent); outline-offset: 2px; }
.ac-root .btn-ghost { border-color: transparent; color: var(--ac-ink-muted); }
.ac-root .btn-ghost:hover:not(:disabled) { background: var(--ac-surface-2); color: var(--ac-ink); }
.ac-root .btn-danger { border-color: var(--ac-err); color: var(--ac-err); }

/* ---------- toolbar ---------- */
.ac-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--ac-surface); border-bottom: 1px solid var(--ac-surface-2);
  position: sticky; top: 64px; z-index: var(--ac-z-rail);
}
.ac-mode { display: inline-flex; border: 1px solid var(--ac-line); border-radius: var(--ac-radius); overflow: hidden; }
.ac-mode-btn { appearance: none; border: 0; background: var(--ac-surface); color: var(--ac-ink-muted); padding: 7px 16px; font: 600 13px/1.2 inherit; cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.ac-mode-btn[aria-selected="true"] { background: var(--ac-ink); color: #ffffff; }
.ac-mode-btn:hover:not([aria-selected="true"]) { background: var(--ac-surface-2); color: var(--ac-ink); }
.ac-search {
  flex: 1 1 260px; min-width: 200px; max-width: 560px;
  border: 1px solid var(--ac-line); border-radius: var(--ac-radius);
  padding: 8px 12px; font: inherit; color: var(--ac-ink); background: var(--ac-surface);
  transition: border-color 160ms ease;
}
.ac-search::placeholder { color: var(--ac-ink-muted); opacity: 1; }
.ac-search:focus { border-color: var(--ac-accent); outline: none; }
.ac-source-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ac-chip {
  appearance: none; border: 1px solid var(--ac-line); border-radius: 999px;
  background: var(--ac-surface); color: var(--ac-ink-muted);
  font: 600 12px/1 inherit; padding: 6px 12px; cursor: pointer; white-space: nowrap;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}
.ac-chip:hover { border-color: var(--ac-ink-muted); color: var(--ac-ink); }
.ac-chip[aria-pressed="true"] { border-color: var(--ac-accent); color: var(--ac-accent); background: rgba(15, 105, 240, 0.06); }
/* Access class badge on source chips (brief §3): API / GitHub / Local / Import / Off. */
.ac-chip-access {
  display: inline-block; margin-left: 6px; padding: 2px 6px; border-radius: 4px;
  background: var(--ac-surface-2); color: var(--ac-ink-muted);
  font: 600 9px/1.2 inherit; letter-spacing: 0.02em; vertical-align: 1px;
}
.ac-chip-access-off { background: var(--ac-warn-bg); color: var(--ac-warn-ink); }
.ac-toolbar-end { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.ac-bridge-chip { font: 600 12px/1 inherit; padding: 6px 10px; border-radius: 999px; background: var(--ac-surface-2); color: var(--ac-ink-muted); white-space: nowrap; }
.ac-bridge-chip[data-state="live"] { background: var(--ac-ok-bg); color: var(--ac-ok-ink); }
.ac-bridge-chip[data-state="fallback"] { background: var(--ac-warn-bg); color: var(--ac-warn-ink); }
.ac-bridge-chip[data-state="error"] { background: #ffe5e9; color: var(--ac-err); }

/* ---------- body: rail + wall + drawer ---------- */
.ac-body { display: flex; flex: 1; min-height: 480px; align-items: stretch; }
.ac-rail {
  flex: 0 0 220px; background: var(--ac-surface-2); padding: 14px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.ac-rail-btn {
  appearance: none; border: 0; background: transparent; text-align: left; cursor: pointer;
  padding: 9px 12px; border-radius: var(--ac-radius); color: var(--ac-ink-muted);
  font: 600 13.5px/1.3 inherit; display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  transition: background-color 150ms ease, color 150ms ease;
}
.ac-rail-btn:hover { background: rgba(255, 255, 255, 0.7); color: var(--ac-ink); }
.ac-rail-btn[aria-current="true"] { background: var(--ac-surface); color: var(--ac-ink); box-shadow: inset 0 0 0 1px var(--ac-line); }
.ac-rail-count { font: 600 11px/1 inherit; color: var(--ac-ink-muted); }

.ac-wall { flex: 1; min-width: 0; padding: 16px; overflow-y: auto; }
.ac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.ac-tile {
  appearance: none; border: 1px solid var(--ac-line); border-radius: var(--ac-radius);
  background: var(--ac-surface); padding: 0; overflow: hidden; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; font: inherit; color: inherit;
  transition: border-color 150ms ease, transform 180ms cubic-bezier(0.25, 1, 0.5, 1);
}
.ac-tile:hover { border-color: var(--ac-ink-muted); }
.ac-tile:active { transform: scale(0.99); }
.ac-tile[aria-selected="true"] { border-color: var(--ac-accent); box-shadow: inset 0 0 0 1px var(--ac-accent); }
.ac-tile-thumb { aspect-ratio: 1 / 1; width: 100%; background: var(--ac-surface-2); display: block; object-fit: contain; }
/* Animated items carry JSON, not raster previews: labelled placeholder tile. */
.ac-tile-anim { display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--ac-ink-muted); }
.ac-tile-meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ac-tile-title { font: 600 12.5px/1.3 inherit; color: var(--ac-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-tile-sub { font: 500 11px/1.2 inherit; color: var(--ac-ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-tile-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.ac-tile-actions .btn { flex: 1; padding: 5px 8px; font-size: 12px; }
.ac-load-more { display: flex; justify-content: center; padding: 18px 0 6px; }

/* skeletons */
.ac-skel { border: 1px solid var(--ac-surface-2); border-radius: var(--ac-radius); overflow: hidden; background: var(--ac-surface); }
.ac-skel-thumb { aspect-ratio: 1 / 1; background: linear-gradient(100deg, var(--ac-surface-2) 40%, #f5f6f8 50%, var(--ac-surface-2) 60%); background-size: 200% 100%; animation: ac-shimmer 1.2s linear infinite; }
.ac-skel-line { height: 10px; margin: 9px 10px; border-radius: 4px; background: linear-gradient(100deg, var(--ac-surface-2) 40%, #f5f6f8 50%, var(--ac-surface-2) 60%); background-size: 200% 100%; animation: ac-shimmer 1.2s linear infinite; }
.ac-skel-line.w70 { width: 70%; }
.ac-skel-line.w45 { width: 45%; }
@keyframes ac-shimmer { to { background-position: -200% 0; } }

/* empty + error states teach the interface */
.ac-empty { text-align: center; padding: 72px 24px; color: var(--ac-ink-muted); max-width: 560px; margin: 0 auto; }
.ac-empty h3 { color: var(--ac-ink); font: 700 17.3px/1.3 inherit; margin: 0 0 8px; }
.ac-empty p { margin: 0 0 14px; }
.ac-banner-error { border: 1px solid var(--ac-err); background: #fff2f4; color: var(--ac-err); border-radius: var(--ac-radius); padding: 10px 14px; margin: 0 0 14px; font: 500 13px/1.4 inherit; }

/* ---------- drawer ---------- */
.ac-drawer {
  flex: 0 0 380px; border-left: 1px solid var(--ac-surface-2); background: var(--ac-surface);
  padding: 18px; overflow-y: auto; z-index: var(--ac-z-drawer);
  /* max-height leaves room for the toolbar band above the drawer's natural position,
     so it never pokes past the fold on 768-tall laptops before sticky pins it.
     Budget is 280px: with many source chips the chip row wraps, making the band
     ~190px tall (search row + two chip rows + action row) above a ~90px page header. */
  position: sticky; top: 150px; max-height: calc(100vh - 280px); align-self: flex-start;
}
.ac-drawer-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ac-drawer-title { font: 700 17.3px/1.3 inherit; margin: 0; word-break: break-word; }
.ac-drawer-close { appearance: none; border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ac-ink-muted); padding: 4px 8px; border-radius: var(--ac-radius); }
.ac-drawer-close:hover { background: var(--ac-surface-2); color: var(--ac-ink); }
.ac-preview {
  border: 1px solid var(--ac-surface-2); border-radius: var(--ac-radius); background:
    repeating-conic-gradient(#f1f3f5 0% 25%, #ffffff 0% 50%) 50% / 20px 20px;
  display: grid; place-items: center; min-height: 220px; padding: 12px; margin-bottom: 12px;
}
.ac-preview img, .ac-preview svg { max-width: 100%; max-height: 280px; }
.ac-preview video, .ac-preview audio { max-width: 100%; }
.ac-meta { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: 12.5px; }
.ac-meta dt { color: var(--ac-ink-muted); font-weight: 600; width: 96px; padding: 5px 0; vertical-align: top; }
.ac-meta dd { margin: 0; padding: 5px 0; word-break: break-word; }
.ac-meta, .ac-meta dt, .ac-meta dd { display: block; }
.ac-meta-row { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--ac-surface-2); }
.ac-meta-row:last-child { border-bottom: 0; }
.ac-meta-key { flex: 0 0 96px; color: var(--ac-ink-muted); font-weight: 600; }
.ac-meta-val { flex: 1; min-width: 0; }
.ac-drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.ac-drawer-actions .btn { flex: 1 1 auto; }

/* parametric controls (generators, media studio, typography) */
.ac-controls { border: 1px solid var(--ac-surface-2); border-radius: var(--ac-radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.ac-controls h4 { margin: 0; font: 700 13px/1.2 inherit; }
.ac-control { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; font-size: 12.5px; }
.ac-control label { color: var(--ac-ink-muted); font-weight: 600; }
.ac-control input[type="range"] { width: 100%; accent-color: var(--ac-accent); }
.ac-control input[type="color"] { width: 42px; height: 26px; padding: 0; border: 1px solid var(--ac-line); border-radius: 6px; background: none; }
.ac-control select, .ac-control input[type="number"], .ac-control input[type="text"] {
  border: 1px solid var(--ac-line); border-radius: 6px; padding: 5px 8px; font: inherit; color: var(--ac-ink); background: var(--ac-surface);
}
.ac-control-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- workspace ---------- */
.ac-workspace { flex: 1; display: flex; min-height: 640px; }
.ac-workspace[hidden] { display: none; }
.ac-vc-frame-wrap { flex: 1; position: relative; background: #262626; }
.ac-vc-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.ac-root[data-mode="browse"] .ac-workspace { display: none; }
.ac-root[data-mode="workspace"] { flex-direction: row; flex-wrap: wrap; }
.ac-root[data-mode="workspace"] .ac-toolbar { order: -1; flex: 0 0 100%; } /* own row; stays sticky like browse */
.ac-root[data-mode="workspace"] .ac-body { order: 1; flex: 0 0 400px; border-right: 1px solid var(--ac-surface-2); min-height: calc(100vh - 200px); }
.ac-root[data-mode="workspace"] .ac-workspace { order: 2; flex: 1 1 0; align-self: flex-start; position: sticky; top: 140px; height: calc(100vh - 160px); }
.ac-root[data-mode="workspace"] .ac-rail { flex-basis: 150px; }
.ac-root[data-mode="workspace"] .ac-drawer {
  position: fixed; right: 12px; bottom: 12px; top: auto; width: 380px;
  max-height: calc(100vh - 280px); overflow-y: auto; /* bottom-anchored under the toolbar band */
  border: 1px solid var(--ac-surface-2); border-radius: var(--ac-radius);
  box-shadow: 0 8px 24px rgba(10, 29, 55, 0.18); z-index: 50;
}
@media (max-width: 1023px) {
  .ac-root[data-mode="workspace"] .ac-body { flex-basis: 300px; }
  .ac-root[data-mode="workspace"] .ac-drawer { width: 320px; }
}
@media (max-width: 767px) {
  .ac-root[data-mode="workspace"] .ac-body { order: 2; flex-basis: 100%; border-right: 0; min-height: 320px; }
  .ac-root[data-mode="workspace"] .ac-workspace { order: 1; flex: 0 0 100%; width: 100%; min-height: 320px; height: 44vh; }
  .ac-root[data-mode="workspace"] .ac-drawer { position: fixed; left: 0; right: 0; top: auto; width: auto; max-height: 66vh; border-radius: 14px 14px 0 0; }
}

/* ---------- modal + toast ---------- */
.ac-modal { position: fixed; inset: 0; background: rgba(10, 29, 55, 0.42); display: grid; place-items: center; z-index: var(--ac-z-modal); padding: 20px; }
.ac-modal[hidden] { display: none; }
.ac-modal-card { background: var(--ac-surface); border-radius: var(--ac-radius); padding: 22px; width: min(680px, 100%); max-height: 82vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(10, 29, 55, 0.18); }
.ac-modal-card h3 { margin: 0 0 12px; font: 700 17.3px/1.3 inherit; }
.ac-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ac-ink); color: #ffffff; padding: 10px 18px; border-radius: var(--ac-radius);
  font: 600 13px/1.3 inherit; z-index: var(--ac-z-toast); box-shadow: 0 8px 24px rgba(10, 29, 55, 0.3);
  max-width: min(560px, 90vw);
}
.ac-toast[data-kind="error"] { background: var(--ac-err); }
.ac-toast[data-kind="ok"] { background: #0c5c2e; }
.ac-toast[hidden] { display: none; }

/* packs list */
.ac-pack-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--ac-surface-2); }
.ac-pack-row:last-child { border-bottom: 0; }
.ac-pack-name { font: 600 14px/1.2 inherit; }
.ac-pack-sub { font: 500 12px/1.2 inherit; color: var(--ac-ink-muted); }
.ac-pack-info { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ac-modal-sub { margin: 0 0 12px; color: var(--ac-ink-muted); font-size: 13px; line-height: 1.45; }
.ac-pack-list { display: flex; flex-direction: column; }

/* ---------- responsive: structural, not fluid ---------- */
@media (max-width: 1365px) {
  .ac-rail { flex-basis: 190px; }
  .ac-drawer { flex-basis: 340px; }
}
@media (max-width: 1023px) {
  .ac-rail { flex-basis: 150px; padding: 10px 6px; }
  .ac-rail-btn { font-size: 12.5px; padding: 8px 10px; }
}
@media (max-width: 767px) {
  .ac-root[data-mode="workspace"] { flex-direction: column; flex-wrap: nowrap; }
  .ac-toolbar { position: static; }
  .ac-toolbar-end { margin-left: 0; width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .ac-body { flex-direction: column; }
  .ac-rail { flex: 0 1 auto; min-width: 0; max-width: 100%; flex-direction: row; overflow-x: auto; padding: 8px 12px; gap: 6px; }
  .ac-rail-btn { white-space: nowrap; flex: 0 0 auto; border: 1px solid var(--ac-line); background: var(--ac-surface); }
  .ac-rail-count { display: none; }
  .ac-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .ac-drawer {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; max-height: 72vh;
    border-left: 0; border-top: 1px solid var(--ac-surface-2); border-radius: 14px 14px 0 0;
    z-index: calc(var(--ac-z-drawer) + 10);
  }
  .ac-workspace { min-height: 0; height: calc(100vh - 190px); }
}
@media (max-width: 390px) {
  .ac-root { font-size: 14px; }
  .ac-grid { grid-template-columns: repeat(2, 1fr); }
  .ac-mode-btn { padding: 7px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .ac-root *, .ac-root *::before, .ac-root *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
