/* Shared browser-local personalization styling: the favorite control, the
   homepage Favorites/Recently used lists, the sidebar utility entries and the
   Preferences page. Uses the existing palette variables so both themes stay
   consistent, and touches nothing inside a tool's own root element. */

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Favorite control ------------------------------------------------------- */

.favorite-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
}
.favorite-toggle[hidden] { display: none; }
.favorite-toggle:hover { background: var(--control-hover); color: var(--navy); }
.favorite-toggle:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }
.favorite-toggle svg { display: block; width: 18px; height: 18px; }
.favorite-toggle[aria-pressed="true"] { color: var(--deep-teal); border-color: var(--teal); }
.favorite-toggle[aria-pressed="true"] svg path { fill: currentColor; }

.favorite-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Catalog cards ---------------------------------------------------------- */

.card-shell {
  position: relative;
  display: flex;
  min-width: 0;
}
.card-shell > .tool-card {
  flex: 1 1 auto;
  padding-right: 44px;
}
/* Keep the star with its card when the catalog search hides the card. */
.card-shell:has(> .tool-card[hidden]) { display: none; }

.favorite-toggle-card {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 40px;
  min-height: 40px;
  border-color: transparent;
  background: transparent;
}
.favorite-toggle-card:hover { border-color: var(--control-border); }
.favorite-toggle-card:focus-visible { outline: 3px solid var(--teal); outline-offset: -3px; }

/* Homepage Favorites and Recently used ------------------------------- */
/* Each block is its own module box; the module styling itself belongs to
   the Home page head, so nothing here depends on a catalog card class. */

.personal { display: grid; gap: clamp(24px, 2.4vw, 32px); }
.personal[hidden] { display: none; }
.personal-block[hidden] { display: none; }
.personal h2:focus { outline: none; }
.personal-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.personal-list[hidden] { display: none; }
.personal-list .tool-card {
  width: 100%;
  max-width: none;
  height: 100%;
  margin-top: 0;
}
.personal-empty { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.personal-empty[hidden] { display: none; }

@media (max-width: 1439px) {
  .personal-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1179px) {
  .personal-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 519px) {
  .personal-list { grid-template-columns: minmax(0, 1fr); }
}

/* Sidebar utilities: Back to top, then Preferences -------------------- */
/* The sidebar is a flex column, so the utilities rest at the bottom of the
   viewport through margin-top:auto instead of fixed positioning or a
   hardcoded offset. A short window keeps everything reachable by scrolling. */
.sidebar-links { flex: 1 0 auto; }
@media (min-width: 761px) {
  .site-sidebar { display: flex; flex-direction: column; }
}
@media (max-width: 760px) {
  .site-sidebar[data-open] { display: flex; flex-direction: column; }
  html:not([data-navigation-ready]) .site-sidebar { display: flex; flex-direction: column; }
}
.sidebar-links .sidebar-divider {
  margin: auto 0 4px;
  border: 0;
  border-top: 1px solid var(--line);
}
/* An empty search status must not lift the utilities off the bottom edge. */
.sidebar-links + .search-status:empty { margin: 0; }
.sidebar-links a.sidebar-utility[data-sidebar-utility="top"] { margin-top: 10px; }
.sidebar-links a.sidebar-utility {
  --tab-accent: var(--teal);
  --tab-tint: var(--control-hover);
  font-weight: 600;
}

/* Inactive sidebar entries gain a restrained teal ring on hover. An inset
   box-shadow never shifts layout, and :not([aria-current]) keeps the active
   entry's accent and background exactly as they were. */
:root { --sidebar-hover-ring: rgb(8 127 135 / 0.34); }
:root[data-theme="dark"] { --sidebar-hover-ring: rgb(93 213 209 / 0.42); }
.sidebar-links a:not([aria-current]):hover {
  box-shadow: inset 0 0 0 1px var(--sidebar-hover-ring);
}

/* Preferences page ---------------------------------------------------- */

.preferences-count {
  margin: 0 0 16px;
  color: var(--navy);
  font-weight: 600;
}
.preferences-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}
.preferences-note[hidden] { display: none; }
.preferences-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.preferences-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  background: var(--paper);
  color: var(--navy);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.preferences-button:hover { background: var(--control-hover); }
.preferences-button:focus-within,
.preferences-button:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
.preferences-button-quiet { background: transparent; color: var(--muted); }
.preferences-file {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.preferences-status { margin: 16px 0 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.preferences-status:empty { margin: 0; }
.preferences-confirm {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  background: var(--control-hover);
}
.preferences-confirm[hidden] { display: none; }
.preferences-confirm p { margin: 0 0 14px; font-size: 15px; line-height: 1.6; }

@media (max-width: 760px) {
  .favorite-toggle { min-width: 40px; min-height: 40px; }
  .preferences-actions { flex-direction: column; align-items: stretch; }
  .preferences-button { width: 100%; }
}
