/* DevCN chrome layer — global header / footer / back-to-top for ALL front pages.
 *
 * Hard rules learned the hard way (2026-10-02 regression):
 *  1. NO global resets here (no * {}, no img/h1/p/ul resets) — the legacy
 *     redesign.css still renders every unmigrated page and depends on them.
 *  2. NO generic class names that legacy CSS already owns (.btn, .badge,
 *     .empty-state, .alert, .card …) — those live in ui.css, scoped to
 *     migrated pages only.
 *  3. Selectors are prefixed with body.front-ui so this layer wins the
 *     cascade without fighting !important.
 * Loaded globally for every non-admin page, after tokens.css.
 */

body.front-ui {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- container (this layer MUST own it) ----------
 * .wrap used to be defined in ui.css, which only loads on migrated pages.
 * Result: on /articles, /circles, /topics … the header + nav + footer rendered
 * full-bleed (x=0) while the page body stayed pinned at --maxw → a 113px
 * misalignment at 1440px wide. Every front page loads this file, so the
 * container lives here.
 *
 * Alignment target: an unmigrated shell renders as max-width:var(--maxw);
 * margin-inline:auto; padding 0 → its edges sit at (100vw - --maxw)/2. Mirroring
 * that exact formula keeps header, channel bar, body and footer on one grid. */
body.front-ui .wrap {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
}
/* Narrower than the container there is nothing left to align against —
 * restore gutters so content never touches the viewport edge. */
@media (max-width: 1248px) {
  body.front-ui .wrap { padding-inline: var(--gutter); }
}
@media (max-width: 620px) {
  body.front-ui .wrap { padding-inline: 16px; }
}

body.front-ui .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- header ---------- */
body.front-ui .site-head {
  position: sticky; top: 0; z-index: 60;
  background: var(--head-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}
body.front-ui .head-in { display: flex; align-items: center; gap: 28px; min-height: var(--nav-h); padding-block: 13px; }
body.front-ui .brand-block { display: flex; align-items: center; min-width: 0; }
body.front-ui .brand-block a { display: flex; align-items: center; gap: 11px; min-width: 0; }
body.front-ui .brand-logo {
  width: 38px; height: 38px; flex: none; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: 17px; font-weight: 700; overflow: hidden;
}
body.front-ui .brand-logo img { width: 100%; height: 100%; object-fit: contain; }
/* grid, not inline: without this the site name and the slogan rendered side by
   side on one line ("DevCN让技术经验被看见…") instead of stacking. */
body.front-ui .brand-text { display: grid; min-width: 0; }
body.front-ui .brand-name {
  font-size: 18px; font-weight: 700; letter-spacing: -.02em; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.front-ui .brand-desc {
  font-size: 12px; color: var(--text-faint); line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.front-ui .head-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: none; }
body.front-ui .head-search {
  display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 15px;
  background: var(--bg-soft); border: 1px solid transparent;
  border-radius: var(--radius-pill); transition: border-color .18s, background .18s;
}
body.front-ui .head-search:focus-within { border-color: var(--primary); background: var(--bg); }
body.front-ui .head-search .s-icon { width: 16px; height: 16px; flex: none; color: var(--text-faint); }
body.front-ui .head-search input {
  border: 0; outline: 0; background: transparent; width: 168px; font-size: 13px; color: var(--text);
}
body.front-ui .head-search input::placeholder { color: var(--text-faint); }
body.front-ui .icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  color: var(--text-soft); border: 1px solid var(--border); background: transparent; transition: .18s;
}
body.front-ui .icon-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
body.front-ui .icon-btn svg { width: 18px; height: 18px; }
body.front-ui .pill-link {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px;
  border-radius: var(--radius-pill); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft); background: transparent; transition: .18s;
}
body.front-ui .pill-link:hover { color: var(--primary); border-color: var(--primary); }

/* account cluster */
body.front-ui .head-account { display: flex; align-items: center; gap: 4px; flex: none; }
body.front-ui .head-link {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 4px;
  font-size: 13px; color: var(--text-soft); white-space: nowrap;
  background: transparent; border: 0; transition: color .18s;
}
body.front-ui .head-link:hover { color: var(--primary); }
body.front-ui .head-link b {
  min-width: 17px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--danger); color: #fff; font-size: 11px; text-align: center; line-height: 17px;
}
body.front-ui .head-link.cta {
  min-height: 34px; padding: 0 15px; border-radius: var(--radius-pill);
  background: var(--primary); color: #fff; font-weight: 600;
}
body.front-ui .head-link.cta:hover { background: var(--primary-2); color: #fff; }

/* publish dropdown (legacy markup, restyled) */
body.front-ui .head-account .publish-menu { position: relative; }
body.front-ui .head-account .publish-menu > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--text-soft); cursor: pointer;
}
body.front-ui .head-account .publish-menu > summary::-webkit-details-marker { display: none; }
body.front-ui .head-account .publish-menu > summary:hover { color: var(--primary); }
body.front-ui .publish-trigger-plus,
body.front-ui .publish-trigger-chevron { width: 15px; height: 15px; }
body.front-ui .head-account .publish-menu > nav {
  position: absolute; right: 0; top: calc(100% + 12px); z-index: 90; width: 268px; padding: 10px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
body.front-ui .publish-menu-heading { margin: 4px 10px 8px; font-size: 12px; color: var(--text-faint); }
body.front-ui .publish-option {
  display: flex; align-items: center; gap: 11px; padding: 10px;
  border-radius: var(--radius-sm); transition: background .18s;
}
body.front-ui .publish-option:hover { background: var(--bg-soft); }
body.front-ui .publish-option-icon {
  width: 34px; height: 34px; flex: none; border-radius: var(--radius-xs);
  background: var(--primary-soft); color: var(--primary); display: grid; place-items: center;
}
body.front-ui .publish-option-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
body.front-ui .publish-option-copy { display: flex; flex-direction: column; min-width: 0; }
body.front-ui .publish-option-copy strong { font-size: 14px; font-weight: 600; }
body.front-ui .publish-option-copy small { font-size: 12px; color: var(--text-faint); line-height: 1.5; }
body.front-ui .publish-option-arrow { width: 16px; height: 16px; margin-left: auto; flex: none; color: var(--text-faint); fill: none; stroke: currentColor; stroke-width: 2; }

/* main navigation row (nav keeps class main-nav — tests assert it) */
body.front-ui .main-nav { border-top: 1px solid var(--border); background: var(--nav-bg); }
body.front-ui .nav-in { display: flex; gap: 26px; overflow-x: auto; scrollbar-width: none; }
body.front-ui .nav-in::-webkit-scrollbar { display: none; }
body.front-ui .nav-in a {
  position: relative; flex: none; padding: 12px 0; font-size: 14px; color: var(--text-soft);
  white-space: nowrap; transition: color .18s;
}
body.front-ui .nav-in a:hover { color: var(--primary); }
body.front-ui .nav-in a.on { color: var(--text); font-weight: 600; }
body.front-ui .nav-in a.on::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--primary); border-radius: 2px;
}

/* secondary channel bar (rendered by base.html below the header) —
 * articles categories / community channels. Same container grid as .wrap
 * so it lines up with the page body instead of bleeding full width. */
body.front-ui .channel-bar { background: var(--bg); border-bottom: 1px solid var(--border); }
body.front-ui .channel-bar > div {
  box-sizing: border-box; width: 100%; max-width: var(--maxw); margin-inline: auto;
  display: flex; align-items: center; gap: 22px; min-height: 46px;
  overflow-x: auto; scrollbar-width: none;
}
body.front-ui .channel-bar > div::-webkit-scrollbar { display: none; }
body.front-ui .channel-bar a {
  flex: none; font-size: 14px; color: var(--text-soft); white-space: nowrap;
  transition: color .18s;
}
body.front-ui .channel-bar a:hover { color: var(--primary); }
@media (max-width: 1248px) { body.front-ui .channel-bar > div { padding-inline: var(--gutter); } }
@media (max-width: 620px) { body.front-ui .channel-bar > div { padding-inline: 16px; gap: 16px; } }

/* ---------- footer ---------- */
body.front-ui .site-foot { margin-top: 56px; border-top: 1px solid var(--border); background: var(--bg-soft); }
body.front-ui .foot-grid {
  display: grid; gap: 32px; padding-block: 40px;
  grid-template-columns: minmax(220px, 1.6fr) repeat(auto-fit, minmax(130px, 1fr));
}
body.front-ui .foot-logo { display: block; height: 30px; width: auto; margin-bottom: 12px; }
body.front-ui .foot-brand { font-size: 16px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
body.front-ui .foot-desc { margin: 8px 0 0; font-size: 13px; line-height: 1.8; color: var(--text-soft); }
body.front-ui .foot-col h4 { font-size: 13px; margin: 0 0 12px; font-weight: 650; }
body.front-ui .foot-col a,
body.front-ui .foot-col span { display: block; padding: 4px 0; font-size: 13px; color: var(--text-soft); }
body.front-ui .foot-col a:hover { color: var(--primary); }
body.front-ui .foot-home { display: inline-block; margin-top: 12px; font-size: 13px; color: var(--primary); }
body.front-ui .foot-home:hover { text-decoration: underline; }
body.front-ui .foot-friends {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding-block: 14px; border-top: 1px solid var(--border);
}
body.front-ui .foot-friends > span { font-size: 13px; color: var(--text-faint); flex: none; }
body.front-ui .foot-friends nav { display: flex; gap: 14px; flex-wrap: wrap; }
body.front-ui .foot-friends a { font-size: 13px; color: var(--text-soft); }
body.front-ui .foot-friends a:hover { color: var(--primary); }
body.front-ui .foot-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-block: 16px;
  font-size: 13px; color: var(--text-faint);
}
body.front-ui .foot-bar nav { display: flex; gap: 18px; flex-wrap: wrap; }
body.front-ui .foot-bar a:hover { color: var(--primary); }

/* ---------- reading progress & back-to-top ---------- */
body.front-ui .read-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--primary); z-index: 120; transition: width .08s linear;
}
body.front-ui .to-top {
  position: fixed; right: 24px; bottom: 24px; width: 44px; height: 44px; z-index: 110;
  display: none; place-items: center; border-radius: 50%;
  background: var(--card-bg); border: 1px solid var(--border);
  box-shadow: var(--shadow); color: var(--text-soft);
}
body.front-ui .to-top.show { display: grid; }
body.front-ui .to-top:hover { color: var(--primary); border-color: var(--primary); }
body.front-ui .to-top svg { width: 19px; height: 19px; }

/* ---------- container alignment: one grid for every page ----------
 * Unmigrated shells each ship their own width (1200 / 1320 / 1400px) and their
 * own padding, so every page landed on a different grid than this header.
 * main-editorial.css pins several at 1400px!important on top of that.
 *
 * Enumerating class names cannot keep up — there are 67 front templates, and the
 * old list was already leaking (/following shipped a 1320px shell nobody had
 * listed). So constrain the page root and its top-level sections instead;
 * migrated pages already use .wrap, which resolves to exactly the same grid. */
 * V1 of this rule also capped <main> itself — do NOT bring that back: legacy CSS
 * gives main 24px of horizontal padding, so capping it to --maxw with
 * box-sizing:border-box squeezed every child to 1152px and pushed them 24px in.
 * Leaving main full width lets children centre on exactly the same grid. */
body.front-ui main > * {
  box-sizing: border-box;
  max-width: var(--maxw) !important;
  margin-inline: auto !important;
}
/* belts and braces: known shells that may sit deeper than a direct child */
body.front-ui :is(.home-feature-shell, .media-shell, .article-index-page, .topic-catalog-page,
.members-directory-page, .network-index-page, .web-directory-page, .circle-hub, .cf-directory,
.cf-forum-layout, .cf-forum-hero, .cf-breadcrumb, .article-layout, .post-detail-layout,
.creator-center, .creator-profile-page, .profile-page, .search-page, .publish-page,
.following-feed, .ov) {
  max-width: var(--maxw) !important;
  margin-inline: auto !important;
}

/* the mobile-only search pill duplicates the desktop search cluster */
body.front-ui .mobile-search-entry { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body.front-ui .head-in { flex-wrap: wrap; gap: 14px; min-height: 0; }
  body.front-ui .head-tools { width: 100%; margin-left: 0; }
  body.front-ui .head-search { flex: 1; }
  body.front-ui .head-search input { width: 100%; }
  body.front-ui .brand-desc { display: none; }
  body.front-ui .main-nav { display: none; }
  body.front-ui .head-account { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  body.front-ui .foot-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
}
@media (max-width: 620px) {
  body.front-ui .foot-grid { grid-template-columns: 1fr; }
  body.front-ui .to-top { right: 14px; bottom: 14px; }
}
