/* Core brand tokens, typography, masthead, and guest authentication portal for CHEN-Lab. */
:root {
  --claret: #a31d36;
  --claret-dark: #7d152a;
  --claret-soft: #faf0f2;
  --claret-ring: rgba(163, 29, 54, 0.16);
  --gold: #dfac47;
  --ink: #1e1e24;
  --muted: #5d5963;
  --subtle: #7e7984;
  --line: #e4dfdc;
  --line-strong: #cfc8c5;
  --paper: #ffffff;
  --canvas: #f7f5f2;
  --wash: #fbfaf8;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(24, 18, 22, 0.05);
  --shadow-md: 0 8px 28px rgba(24, 18, 22, 0.07), 0 1px 3px rgba(24, 18, 22, 0.04);
  --shadow-lg: 0 22px 60px rgba(18, 13, 18, 0.24);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Noto Sans CJK SC", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
a { color: var(--claret); text-decoration: none; }
button { cursor: pointer; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
h1, h2, h3, strong { font-weight: 650; }
:focus-visible { outline: 2px solid var(--claret); outline-offset: 2px; }

.icon { flex: none; vertical-align: -0.18em; display: inline-block; }
.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip-link:focus {
  position: fixed; top: 10px; left: 10px; z-index: 99;
  background: var(--paper); color: var(--ink); padding: 8px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--claret);
}

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink);
  font-size: 0.92rem; font-weight: 600; line-height: 1.3; white-space: nowrap;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.1s ease, box-shadow 0.14s ease;
}
.btn:hover { background: #f4f0ee; border-color: #b7afb2; }
.btn:active { transform: translateY(0.5px); }
.btn.primary {
  background: var(--claret); border-color: var(--claret); color: #fff;
  box-shadow: 0 1px 2px rgba(125, 21, 42, 0.24);
}
.btn.primary:hover { background: var(--claret-dark); border-color: var(--claret-dark); }
.btn.primary:disabled { opacity: 0.65; cursor: not-allowed; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 0.86rem; }
.btn.is-danger-outline { color: #b42339; border-color: #e3b8c0; background: #fff; }
.btn.is-danger-outline:hover { background: #fdf1f3; border-color: #c86475; }

label { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 0.89rem; font-weight: 600; color: #312e36; }
label small { color: var(--muted); font-size: 0.81rem; font-weight: 400; line-height: 1.5; }
input:not([type="hidden"]):not([type="file"]):not([type="checkbox"]), select, textarea {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); font-size: 0.95rem; font-weight: 400;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
input:not([type="hidden"]):not([type="file"]):not([type="checkbox"]):focus, select:focus, textarea:focus {
  outline: none; border-color: var(--claret); box-shadow: 0 0 0 3px var(--claret-ring);
}
input::placeholder, textarea::placeholder { color: #8c8691; opacity: 1; }
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: var(--paper);
  background-image: url("chevron.svg");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px 14px;
  padding-right: 32px;
}
select::-ms-expand { display: none; }
select::picker-icon { display: none; }

/* Flash Alerts */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 0 0 18px; padding: 12px 15px; border-radius: var(--radius-md);
  font-size: 0.92rem; line-height: 1.5; border: 1px solid transparent;
  overflow-wrap: anywhere;
}
.alert .icon { margin-top: 2px; flex: none; }
.alert.is-ok { background: #eef7f1; border-color: #cce5d4; color: #1f5c37; }
.alert.is-error { background: #fdf1f2; border-color: #f0c9cf; color: #8f1d32; }

/* Masthead */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.masthead::before {
  content: ""; display: block; height: 3.5px;
  background: linear-gradient(90deg, var(--claret) 0%, var(--claret) 84%, var(--gold) 84%, var(--gold) 100%);
}
.mast-inner, .portal-spread, .portal-footer, .page {
  width: min(100% - 2 * clamp(18px, 4.4vw, 68px), 1340px);
  margin-inline: auto;
}
.mast-inner { display: flex; align-items: center; gap: 20px; min-height: 68px; }
.lab-signature {
  color: #201e26; display: inline-flex; align-items: center; gap: 10px; white-space: nowrap;
}
.lab-signature img { display: block; width: 38px; height: 38px; }
.wordmark { font: 700 1.95rem/1 Georgia, "Times New Roman", serif; letter-spacing: -0.055em; }
.brand-divider { width: 1px; height: 22px; background: var(--line-strong); }
.mast-service { font-size: 0.96rem; font-weight: 560; letter-spacing: 0.04em; color: var(--muted); }
.university-link {
  margin-left: auto; display: inline-flex; gap: 6px; align-items: center;
  font-size: 0.88rem; color: var(--muted);
}
.university-link span { color: var(--claret); }
.university-link:hover, .portal-footer a:hover { color: var(--claret); text-decoration: underline; }

/* Authenticated Nav & Account Menu */
.lab-nav {
  align-self: stretch; display: flex; gap: clamp(14px, 2.2vw, 32px);
  margin-left: clamp(10px, 2.6vw, 40px);
}
.lab-nav .nav-link {
  position: relative; display: flex; align-items: center; gap: 7px;
  padding: 0 4px; color: var(--muted); font-size: 0.94rem; font-weight: 550; white-space: nowrap;
  transition: color 0.14s ease;
}
.lab-nav .nav-link:hover { color: var(--claret); }
.lab-nav .nav-link.active { color: var(--claret); font-weight: 650; }
.lab-nav .nav-link.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: var(--claret); border-radius: 3px 3px 0 0;
}

.account-menu { position: relative; margin-left: auto; min-width: 0; }
.account-menu summary {
  display: flex; align-items: center; gap: 9px; list-style: none; cursor: pointer;
  padding: 5px 10px 5px 6px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--wash); transition: border-color 0.14s ease, background-color 0.14s ease;
}
.account-menu summary:hover { border-color: var(--line-strong); background: var(--paper); }
.account-menu summary::-webkit-details-marker { display: none; }
.account-initial {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--claret-soft); color: var(--claret); border-radius: 50%;
  font-weight: 700; font-size: 0.88rem; flex: none;
}
.account-meta { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.account-name { max-width: 8em; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-size: 0.88rem; font-weight: 620; }
.account-role { font-size: 0.72rem; color: var(--muted); }
.caret {
  width: 6px; height: 6px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg); margin: -2px 2px 0 1px;
}
.account-sheet {
  position: absolute; z-index: 30; right: 0; top: calc(100% + 10px); width: 228px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); padding: 12px;
}
.account-sheet-head { padding: 2px 4px 11px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.account-sheet-head strong { display: block; font-size: 0.96rem; overflow-wrap: anywhere; }
.account-sheet-head small { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 2px; overflow-wrap: anywhere; }
.role-pill {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 600;
  background: #f1efee; color: #544f59;
}
.role-pill.is-admin { background: #fdf2e3; color: #8c5a12; border: 1px solid #f0d7a7; }
.account-sheet a, .account-sheet button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  min-height: 36px; padding: 6px 8px; border-radius: var(--radius-sm);
  color: var(--ink); font-size: 0.9rem; background: none; border: 0; text-align: left;
}
.account-sheet a:hover, .account-sheet button:hover { background: var(--claret-soft); color: var(--claret); }

/* Guest Portal Spread */
.signed-out { min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; background: var(--canvas); }
.portal-spread {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.38fr) minmax(350px, 0.95fr);
  align-items: center; gap: clamp(28px, 5vw, 76px); padding-block: clamp(24px, 4.5vh, 56px);
}
.portal-cover {
  overflow: hidden; min-width: 0; position: relative; border-radius: var(--radius-lg);
  background: var(--claret-dark); box-shadow: var(--shadow-md);
}
.campus-frame { margin: 0; position: relative; background: #2d3247; isolation: isolate; }
.campus-image { display: block; width: 100%; height: clamp(265px, 39vh, 435px); object-fit: cover; object-position: 53% 55%; }
.campus-frame::after {
  content: ""; position: absolute; inset: 55% 0 0;
  background: linear-gradient(transparent, rgba(20, 15, 26, 0.5)); pointer-events: none;
}
.campus-frame figcaption {
  display: flex; align-items: center; gap: 8px; position: absolute; right: 20px; bottom: 13px;
  font-size: 0.8rem; color: rgba(255, 255, 255, 0.92); z-index: 1;
}
.photo-rule { height: 1px; width: 18px; background: #f2dfbf; }
.cover-band {
  padding: clamp(24px, 3.2vh, 38px) clamp(24px, 3vw, 44px) clamp(26px, 3.5vh, 42px);
  position: relative; overflow: hidden; isolation: isolate; color: #fff;
  background: linear-gradient(112deg, #77152a 0%, #a31d36 78%, #b2243e 100%);
}
.cover-band::after {
  content: ""; position: absolute; z-index: -1; right: -60px; top: -80px; width: 220px; height: 420px;
  transform: rotate(28deg);
  background: repeating-linear-gradient(90deg, transparent 0 26px, rgba(255, 255, 255, 0.075) 26px 27px, transparent 27px 48px);
}
.cover-head { display: flex; align-items: center; gap: 11px; font: italic 1.08rem/1.3 Georgia, serif; color: #f8e9d5; }
.gold-dash { height: 3px; width: 30px; background: #eabc59; border-radius: 2px; }
.cover-band h2 {
  margin: 10px 0 10px;
  font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  font-size: clamp(2rem, 3.1vw, 3.15rem); font-weight: 700; line-height: 1.18; letter-spacing: 0.02em;
}
.cover-band p { color: rgba(255, 241, 244, 0.9); line-height: 1.65; font-size: 0.96rem; letter-spacing: 0.06em; }
.cover-highlights {
  list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-wrap: wrap; gap: 8px 10px;
}
.cover-highlights li {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 0.81rem; color: #fff6f7;
  background: rgba(255, 255, 255, 0.13); border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Auth Form Card */
.portal-form { width: 100%; max-width: 446px; justify-self: center; min-width: 0; }
.portal-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: clamp(24px, 3vw, 34px); box-shadow: var(--shadow-md);
}
.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 22px;
  background: #f2efed; border-radius: var(--radius-md);
}
.auth-tabs a {
  display: grid; place-items: center; min-height: 38px; border-radius: 7px;
  font-size: 0.91rem; font-weight: 600; color: var(--muted); transition: all 0.15s ease;
}
.auth-tabs a:hover { color: var(--ink); }
.auth-tabs [aria-current="page"] {
  background: var(--paper); color: var(--claret); box-shadow: 0 1px 4px rgba(24, 18, 22, 0.09);
}
.portal-tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; margin-bottom: 14px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 650;
  background: #fdf4e4; color: #8c5a12; border: 1px solid #efd6a7;
}
.entry-intro { margin-bottom: 22px; }
.entry-intro h1 { font-size: clamp(1.5rem, 2vw, 1.85rem); letter-spacing: -0.03em; line-height: 1.25; color: var(--ink); }
.entry-intro p { margin-top: 7px; color: var(--muted); font-size: 0.91rem; line-height: 1.6; }

.entry-fields { display: grid; gap: 15px; }
.entry-fields input:not([type="hidden"]) { min-height: 44px; font-size: 0.96rem; }
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 44px; }
.password-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--subtle); border-radius: var(--radius-sm);
}
.password-toggle:hover { color: var(--ink); background: #f4f1f0; }
.entry-submit { margin-top: 6px; width: 100%; min-height: 45px; font-size: 0.97rem; letter-spacing: 0.02em; }

.portal-notice {
  margin-top: 16px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: #f8f6f4; border: 1px solid var(--line); color: var(--muted); font-size: 0.83rem; line-height: 1.5;
}
.entry-footer-links {
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 0.87rem; color: var(--muted);
}
.entry-footer-links a { font-weight: 600; }
.entry-footer-links a:hover, .entry-switch a:hover { text-decoration: underline; }
.subtle-switch { color: var(--muted); }
.subtle-switch:hover { color: var(--claret); }
.entry-switch { margin-top: 16px; text-align: center; font-size: 0.9rem; font-weight: 600; }

.portal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 12px 0; border-top: 1px solid var(--line);
  color: var(--subtle); font-size: 0.82rem;
}
.portal-footer span { display: inline-flex; align-items: center; gap: 9px; }
.portal-footer i { width: 1px; height: 11px; background: var(--line-strong); }
.portal-footer a { color: inherit; }

/* Error block */
.error-block {
  max-width: 520px; margin: 30px auto; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 34px 28px; text-align: center; box-shadow: var(--shadow-sm);
}
.error-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
  display: grid; place-items: center; background: var(--claret-soft); color: var(--claret);
}
.error-block h1 { font-size: 1.45rem; }
.error-block p { margin: 10px 0 22px; color: var(--muted); font-size: 0.94rem; }

.mast-inner.is-app { width: 100%; max-width: none; padding-inline: 22px; min-height: 54px; gap: 14px; }
.mast-inner.is-app .lab-signature img { width: 28px; height: 28px; }
.mast-inner.is-app .wordmark { font-size: 1.38rem; }
.mast-service.is-compact { font-size: 0.85rem; color: var(--subtle); letter-spacing: 0.02em; }
.mast-inner.is-app .lab-nav { margin-left: 18px; gap: 22px; }
.mast-inner.is-app .nav-link { font-size: 0.88rem; }
.mast-inner.is-app .account-menu summary { padding: 3px 9px 3px 4px; background: #fff; border-color: #e4e5ea; }
.mast-inner.is-app .account-initial { width: 26px; height: 26px; font-size: 0.78rem; }
.mast-inner.is-app .account-name { font-size: 0.84rem; }
.page-narrow { max-width: 1120px; margin: 0 auto; padding: 28px clamp(18px, 4vw, 40px) 72px; }

@media (max-width: 980px) {
  .portal-spread { grid-template-columns: minmax(0, 1.05fr) minmax(320px, 1fr); gap: 28px; }
  .campus-image { height: 240px; }
  .cover-band h2 { font-size: 2.15rem; }
}
@media (max-width: 760px) {
  .mast-inner, .portal-spread, .portal-footer, .page { width: calc(100% - 28px); }
  .mast-inner { min-height: 60px; gap: 10px; }
  .lab-signature img { width: 32px; height: 32px; }
  .wordmark { font-size: 1.6rem; }
  .mast-service, .brand-divider { display: none; }
  .university-link { font-size: 0.8rem; }
  .portal-spread { display: flex; flex-direction: column; align-items: stretch; gap: 18px; padding: 16px 0 28px; }
  .campus-image { height: 165px; }
  .cover-band { padding: 20px 20px 22px; }
  .cover-band h2 { font-size: 1.65rem; }
  .cover-band p { font-size: 0.88rem; }
  .cover-highlights { display: none; }
  .portal-form { max-width: 100%; }
  .portal-card { padding: 22px 18px; }
  .portal-footer { flex-wrap: wrap; font-size: 0.77rem; }
  .signed-in .mast-inner { flex-wrap: wrap; padding-block: 8px 0; gap: 4px 10px; }
  .signed-in .lab-nav { order: 3; width: 100%; margin: 2px 0 0; min-height: 42px; }
  .account-meta { display: none; }
  .account-menu summary { padding: 4px 7px 4px 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
