/* =================================================================
 * www/styles/chrome.css
 *
 * Page-chrome utilities that sit AROUND a form view. Load AFTER
 * tokens.css + base.css. Form-is-type itself doesn't own page
 * chrome — but every demo page in www/ wants the same shell, so
 * these patterns live here as opt-in utility classes.
 *
 * Adapted visually from:
 *   vendor/.../jds-form-header
 *   vendor/.../jds-page-header
 *   vendor/.../jds-sidebar-layout
 *   vendor/.../jds-list-group
 *
 * Classes:
 *   .topbar                   48-px sticky top bar — logo + crumb + nav + actions
 *   .topbar__nav              horizontal nav; [aria-current="page"] highlights
 *   .save-state               dot + label — green "saved", warn "dirty"
 *   .form-header              burgundy hero banner with subtitle + title
 *   .page-header              neutral header strip with h1/p/breadcrumbs
 *   .sidebar-layout           2-col: sticky sidebar + main content
 *   .sidebar-layout__sidebar  left rail (sticky on wide viewports)
 *   .sidebar-layout__content  main column
 *   .list-group               vertical nav list inside a card
 *   .list-group__item         single link; [aria-current="page"] highlights
 *   select.fit-select         styled <select> — native dropdown, SVG chevron
 * ================================================================= */

/* -----------------------------------------------------------------
 * topbar — shared 48-px bar rendered server-side by
 *   internal/web/templates/partials/header.html
 * ----------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 var(--space-md);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-light);
  height: 48px;
  min-height: 48px;
  gap: var(--space-md);
  position: relative;
  z-index: 10;
  font-family: var(--font-family-primary);
  flex-wrap: nowrap;
  overflow: hidden;
}
.topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
  flex-shrink: 0;
}
.topbar__logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font: var(--font-small-bold);
  color: var(--color-heading);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.topbar__logo:hover { text-decoration: none; }
.topbar__logo-mark {
  width: 22px;
  height: 22px;
  background: var(--color-primary-light);
  color: var(--color-white);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font: 700 11px/1 var(--font-family-mono);
}
.topbar__crumb {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-grey-darkest);
  font: var(--font-small);
}
.topbar__crumb strong {
  color: var(--color-heading);
  font-weight: 600;
}
.topbar__crumb .sep { color: var(--color-grey-dark); }

.topbar__nav {
  display: flex;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  min-width: 0;
  margin-left: auto;           /* pin nav (+ right slot) to the right edge */
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;    /* IE/Edge legacy */
}
.topbar__nav::-webkit-scrollbar { height: 0; display: none; }
.topbar__nav a {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--color-grey-darkest);
  text-decoration: none;
  font: var(--font-small);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.topbar__nav a:hover {
  background: var(--color-grey-lighter);
  color: var(--color-heading);
  text-decoration: none;
}
.topbar__nav a[aria-current="page"],
.topbar__nav a.active {
  color: var(--color-heading);
  background: var(--color-grey-lighter);
}

.topbar__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  min-width: 140px;            /* reserve room for save-state so nav lines up
                                  whether or not this page has one */
}

/* Narrow viewports: drop non-essential chrome so the nav fits on one row.
   The nav itself becomes horizontally scrollable when it overflows. */
@media (max-width: 1080px) {
  .topbar__crumb { display: none; }
}
@media (max-width: 900px) {
  .topbar__right { min-width: 0; } /* nav reclaims the reserved right slot */
}
@media (max-width: 640px) {
  .topbar__logo span:last-child { display: none; } /* keep just the N mark */
}

/* connection-status — green/red dot in topbar showing WS state */
.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font: var(--font-xs);
  color: var(--color-grey-darkest);
  padding: 0 4px;
}
.conn-status__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-status-completed-bg, #34c759);
  flex-shrink: 0;
}
.conn-status--off .conn-status__dot {
  background: var(--color-status-pending-bg, #ff9500);
}
.conn-status--off .conn-status__label {
  color: var(--color-status-pending-bg, #ff9500);
}
/* Busy: page is mid-resync (e.g. re-fetching list after reconnect).
   Stays semantically "still connected" — we just pulse the dot to flag
   that something async is happening, instead of recoloring it. */
.conn-status--busy .conn-status__dot {
  animation: conn-status-busy-pulse 1s ease-in-out infinite;
}
@keyframes conn-status-busy-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* Yellow-fade highlight for items that appeared during a post-reconnect
   refresh. Yellow-fade technique (Luke Wroblewski, 2003): brief amber
   highlight that fades back to the row's background — draws the eye
   without claiming success/error semantics. Uses the design system's
   pending-bg token to keep the palette coherent. */
@keyframes resync-flash-in {
  from { background-color: var(--color-status-pending-bg, #FFD975); }
  to   { background-color: transparent; }
}
.dt-item--just-added,
.view-item--just-added {
  animation: resync-flash-in 1.4s ease-out;
}

.save-state {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-grey-darkest);
  font: var(--font-xs);
}
.save-state__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-status-completed-bg);
}
.save-state--dirty {
  color: var(--color-primary-light);
}
.save-state--dirty .save-state__dot {
  background: var(--color-status-pending-bg);
}

/* loading state for buttons/links/items during async operations */
button.loading, a.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button.loading::after, a.loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--color-grey-dark, #666);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin-loading 0.5s linear infinite;
}
/* sidebar / list items: spinner at the right edge, text stays visible */
div.loading, .dt-item.loading, .view-item.loading {
  position: relative;
  opacity: 0.6;
  pointer-events: none;
}
div.loading::after, .dt-item.loading::after, .view-item.loading::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid var(--color-grey-dark, #666);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin-loading 0.5s linear infinite;
}
@keyframes spin-loading {
  to { transform: rotate(360deg); }
}

/* -----------------------------------------------------------------
 * Sidebar list skeleton placeholders shown during initial WS getList.
 * Used by datatype-builder + view-builder while waiting for data.
 * ----------------------------------------------------------------- */
.dt-item--skeleton, .view-item--skeleton {
  pointer-events: none;
}
.dt-item--skeleton .dt-item__main,
.view-item--skeleton .name {
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--color-grey-lighter, #ececec) 0%,
    var(--color-grey-light, #f5f5f5) 50%,
    var(--color-grey-lighter, #ececec) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}
.dt-item--skeleton .dt-item__main { width: 70%; }
.view-item--skeleton .name { width: 60%; margin-bottom: 6px; }
.view-item--skeleton .meta {
  height: 8px;
  width: 30%;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--color-grey-lighter, #ececec) 0%,
    var(--color-grey-light, #f5f5f5) 50%,
    var(--color-grey-lighter, #ececec) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}
.dt-item--skeleton .dt-item__version {
  display: none;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* -----------------------------------------------------------------
 * Unsaved-changes confirmation modal (see /js/nav-guard.js).
 * ----------------------------------------------------------------- */
.unsaved-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 24, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.unsaved-dialog {
  background: var(--color-bg-surface, #fff);
  border: 1px solid var(--color-border-light, #d8dde5);
  border-radius: 8px;
  max-width: 440px;
  width: calc(100% - 2rem);
  padding: 1.2rem 1.3rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
.unsaved-dialog h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.05rem;
  color: var(--color-heading, #2a2f3c);
}
.unsaved-dialog .lead {
  color: var(--color-grey-dark, #666);
  font-size: 0.9rem;
  margin: 0 0 1rem 0;
  line-height: 1.45;
}
.unsaved-dialog .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}
.unsaved-dialog .actions button {
  font: inherit;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--color-border-light, #d8dde5);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}
.unsaved-dialog .actions button.primary {
  background: var(--color-primary, #2c6cd6);
  color: white;
  border-color: var(--color-primary, #2c6cd6);
}
.unsaved-dialog .actions button.danger {
  color: var(--color-status-error, #b53333);
  border-color: var(--color-status-error, #b53333);
}

/* Pre-import confirmation plan (what an import will create / re-revise /
   skip). See datatype-builder-page.js confirmImportPlan. */
.unsaved-dialog .import-plan {
  font-size: 0.88rem;
  margin: 0 0 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.unsaved-dialog .import-plan__row {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  line-height: 1.4;
}
.unsaved-dialog .import-plan__key {
  flex: 0 0 9.5rem;
  color: var(--color-grey-dark, #666);
  font-variant-numeric: tabular-nums;
}
.unsaved-dialog .import-plan__val {
  color: var(--color-heading, #2a2f3c);
  word-break: break-word;
}
.unsaved-dialog .import-plan__row.is-skip { opacity: 0.6; }

/* -----------------------------------------------------------------
 * fit-select — styled native <select>. Drop class="fit-select" on
 * any <select> to get the SVG-chevron look used across builder pages.
 * ----------------------------------------------------------------- */
select.fit-select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 0 28px 0 10px;
  border: 1px solid var(--color-border-light);
  background-color: var(--color-bg-surface);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='none' stroke='%23939599' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 3 4 6 7 3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border-radius: var(--radius-sm);
  font: var(--font-small);
  font-weight: 500;
  color: var(--color-heading);
  line-height: 1;
  height: 32px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
select.fit-select:hover {
  border-color: var(--color-grey-dark);
}
select.fit-select:focus {
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow-focus);
}
select.fit-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background-image: none;
}

/* -----------------------------------------------------------------
 * form-header — burgundy hero banner (intake.html reference)
 * ----------------------------------------------------------------- */
.form-header {
  background: var(--color-primary-light);
  color: var(--color-white);
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
}
.form-header .subtitle {
  font: var(--font-paragraph);
  opacity: 0.9;
  margin-bottom: 4px;
}
.form-header .title {
  font: var(--font-h2);
}

/* -----------------------------------------------------------------
 * page-header — neutral strip above a list/inspector page
 * ----------------------------------------------------------------- */
.page-header {
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-grey-dark);
  padding: var(--space-lg);
}
.page-header h1 {
  font: var(--font-h2);
  color: var(--color-black);
  margin: 0;
}
.page-header p {
  font: var(--font-small);
  color: var(--color-grey-darkest);
  margin: var(--space-sm) 0 0 0;
}
.page-header .breadcrumbs {
  font: var(--font-breadcrumb);
  color: var(--color-grey-darkest);
  margin-bottom: var(--space-sm);
}
.page-header .breadcrumbs a {
  color: var(--color-grey-darkest);
}

/* -----------------------------------------------------------------
 * sidebar-layout — 2-col with sticky left rail
 * ----------------------------------------------------------------- */
.sidebar-layout {
  display: flex;
  padding: var(--space-lg);
  max-width: 1200px;
  margin: 0 auto;
}
.sidebar-layout__sidebar {
  width: 260px;
  flex-shrink: 0;
  margin-right: var(--space-lg);
}
.sidebar-layout__sidebar .sticky {
  position: sticky;
  top: var(--space-lg);
}
.sidebar-layout__content {
  flex: 1;
  min-width: 0;
}
@media (max-width: 800px) {
  .sidebar-layout {
    flex-direction: column;
    padding: var(--space-md);
  }
  .sidebar-layout__sidebar {
    width: 100%;
    margin: 0 0 var(--space-md) 0;
  }
  .sidebar-layout__sidebar .sticky {
    position: static;
  }
}

/* -----------------------------------------------------------------
 * list-group — vertical link list (section nav / in-page nav)
 * ----------------------------------------------------------------- */
.list-group {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  background: var(--color-bg-surface);
  overflow: hidden;
  padding: 0;
  margin: 0 0 var(--space-md) 0;
  list-style: none;
}
.list-group__item {
  display: block;
  padding: 10px var(--space-md);
  font: var(--font-small);
  color: var(--color-grey-darkest);
  text-decoration: none;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-light);
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.list-group__item:last-child { border-bottom: none; }
.list-group__item:hover {
  background: var(--color-grey-lighter);
  text-decoration: none;
}
.list-group__item[aria-current="page"],
.list-group__item.active {
  color: var(--color-primary-light);
  font-weight: 700;
  border-left-color: var(--color-primary-light);
  background: var(--color-bg-surface);
}
.list-group__heading {
  font: var(--font-small-bold);
  color: var(--color-heading);
  margin: var(--space-md) 0 var(--space-xs) 0;
  padding: 0 var(--space-xs);
}

/* -----------------------------------------------------------------
 * site-footer — shared "build <id>" stamp rendered server-side by
 *   internal/web/templates/partials/footer.html
 * Surfaces the BuildID passed via web.WithBuildID at server start.
 * ----------------------------------------------------------------- */
.site-footer {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-surface);
  color: var(--color-grey-dark);
  font: var(--font-small);
  text-align: right;
}
.site-footer__build {
  font-family: var(--font-family-mono);
  letter-spacing: -0.01em;
}
