:root {
  color-scheme: light;
  --ground: #f4f5f2;
  --surface: #fff;
  --raised: #f8f9f7;
  --border: #e2e5df;
  --rule: #eceee9;
  --control: #cdd2c9;
  --text: #202823;
  --muted: #626a63;
  --primary: #23352c;
  --accent: #35634b;
  --soft-green: #e9f1e9;
  --negative: #8e302b;
  --soft-red: #faeeeb;
  --radius: 8px;
  --font: 'Microsoft YaHei UI', 'Microsoft YaHei', 'PingFang SC', system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background: var(--ground);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.4; font-weight: 650; }
h1 { font-size: 27px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
input, select, button { font: inherit; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button, summary { cursor: pointer; }
a { color: inherit; }
form, fieldset { min-width: 0; }
time { font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.sr-only,
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  z-index: 2;
  position: fixed;
  top: 12px;
  left: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 6px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
}

.brand-name, .brand-scope { display: block; }
.brand-name { font-weight: 750; font-size: 16px; line-height: 1.4; }
.brand-scope { color: var(--muted); font-size: 12px; line-height: 1.5; }
.brand-mark { position: relative; width: 23px; height: 24px; }
.brand-mark::before, .brand-mark::after {
  content: "";
  position: absolute;
  top: 3px;
  width: 9px;
  height: 18px;
  border-block: 2px solid var(--accent);
}
.brand-mark::before { left: 0; border-right: 2px solid var(--accent); }
.brand-mark::after { right: 0; border-left: 2px solid var(--accent); }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
}
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: #304a3c; }
.secondary { background: var(--surface); color: var(--text); border-color: var(--control); }
.secondary:hover, .text-button:hover { background: #e9eee7; }
.text-button { background: transparent; color: var(--text); padding-inline: 10px; }
.danger { color: var(--negative); }
.danger:hover { background: var(--soft-red); }
.stack { display: grid; gap: 14px; }
.stack.compact { gap: 10px; }
.field { display: grid; gap: 8px; min-width: 0; }
.field label { display: block; font-weight: 600; }
.field input, .field select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--control);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:hover, .field select:hover { border-color: #b8c0b4; }
.field input::placeholder { color: #9aa39c; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53, 99, 75, .12); outline: none; }
.hint, .field-hint, .muted { color: var(--muted); font-size: 12px; font-weight: 400; }
.hint { margin-inline-start: 4px; }

.message {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
}
.message.error { color: var(--negative); background: var(--soft-red); border-color: #ead6cf; }
.message.success { color: var(--primary); background: var(--soft-green); border-color: #d6e4d6; }

.auth-shell {
  width: min(440px, calc(100% - 32px));
  margin: clamp(32px, 10vh, 108px) auto 48px;
}
.auth-shell > .brand { margin-bottom: 20px; }
.auth-panel {
  display: grid;
  gap: 18px;
  padding: 30px 32px 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(32, 40, 35, .04), 0 18px 40px -28px rgba(32, 40, 35, .35);
}
.auth-form { display: grid; gap: 16px; }
.auth-heading p, .panel-heading p, .main-heading p { margin-top: 5px; color: var(--muted); }
.auth-heading p { overflow-wrap: anywhere; }
.auth-form > .button { margin-top: 2px; }
.auth-note {
  margin: 1px 0 0;
  padding-top: 13px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 13px;
}
.auth-note .text-button { margin-left: -10px; }
.auth-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; }
.auth-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 650;
  text-underline-offset: 3px;
}
.auth-panel > .button { justify-self: start; }

/* At 1200px, a 318px opening panel and an 862px record column share a 20px gutter. */
.admin-shell { width: min(1200px, calc(100% - 52px)); margin-inline: auto; }
.admin-bar { border-bottom: 1px solid var(--border); }
.bar-content { min-height: 65px; display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.account-menu { display: flex; align-items: center; gap: 7px; min-width: 0; }
.admin-username {
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 7px;
}
.account-menu .button { font-size: 13px; white-space: nowrap; }
.admin-main { padding-block: 28px 48px; }
.main-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 19px; }
.main-heading > .button { flex-shrink: 0; }
.admin-main > .message { margin-bottom: 16px; }
.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'roster' 'create' 'events';
  gap: 16px;
  align-items: start;
}
.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.create-panel { grid-area: create; background: #f4f7f2; padding: 0; scroll-margin-top: 18px; }
.create-panel > .create-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 19px; cursor: pointer; list-style: none; }
.create-panel > .create-head::-webkit-details-marker { display: none; }
.create-panel[open] > .create-head { border-bottom: 1px solid var(--border); }
.create-title { display: block; font-size: 15px; font-weight: 600; }
.create-note { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
.create-panel > .create-form { padding: 15px 19px 19px; }
.create-panel:target { outline: 2px solid var(--accent); outline-offset: 2px; }
.create-form { margin-top: 0; }
.create-form .primary { margin-top: 2px; }
.roster-panel { grid-area: roster; }
.events-panel { grid-area: events; }
.count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.section-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 17px 19px; }
.section-line p { margin: 0; font-size: 12px; }
.empty { margin: 0 19px 17px; padding: 16px; border: 1px dashed var(--control); border-radius: 6px; color: var(--muted); }

.company-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 81px 150px 70px;
  align-items: center;
  gap: 12px;
  padding-inline: 19px;
}
.column-heads {
  color: var(--muted);
  font-size: 12px;
  padding-bottom: 8px;
}
.column-heads :last-child, .row-action { justify-self: end; }
.company-row { border-top: 1px solid var(--rule); }
.company-row > summary {
  list-style: none;
  min-height: 58px;
  padding-block: 9px;
}
.company-row > summary::-webkit-details-marker { display: none; }
.company-row > summary:focus-visible { outline-offset: -3px; }
.company-row > summary:hover, .company-row[open] > summary { background: var(--raised); }
.company-identity { display: grid; gap: 1px; min-width: 0; overflow-wrap: anywhere; }
.company-username { color: var(--muted); font-size: 12px; }
.company-date { font-size: 13px; font-variant-numeric: tabular-nums; }
.state { display: inline-block; border-radius: 4px; padding: 1px 7px; font-size: 12px; white-space: nowrap; }
.state.active { color: var(--primary); background: var(--soft-green); }
.state.expired { color: var(--negative); background: var(--soft-red); }
.state.pending { color: #654a28; background: #f7f0e2; }
.state.disabled { color: var(--muted); background: #eceee9; }
.row-action { display: flex; align-items: center; gap: 8px; color: var(--primary); font-size: 13px; }
.chevron { width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); }
.company-row[open] .chevron { transform: translateY(1px) rotate(225deg); }
.company-controls {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 20px;
  padding: 14px 19px 19px;
  background: var(--raised);
}
.company-controls > form { align-content: start; }
.company-account-controls { align-content: start; }
.status-form { border-top: 1px solid var(--border); padding-top: 12px; }
.company-controls .button { justify-self: start; }

.table-scroll { overflow-x: auto; }
.table-scroll:focus-visible { outline-offset: -3px; }
table { border-collapse: collapse; width: 100%; text-align: left; font-size: 13px; }
th, td { padding: 9px 10px; vertical-align: top; }
th:first-child, td:first-child { padding-left: 19px; }
th:last-child, td:last-child { padding-right: 19px; }
th { padding-top: 0; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
td { border-top: 1px solid var(--rule); overflow-wrap: anywhere; }
td:last-child { min-width: 116px; max-width: 210px; }
.event-action { display: block; color: var(--muted); font-size: 12px; }
.record-label { display: none; }

@media (max-width: 960px) {
  .admin-shell { width: min(740px, calc(100% - 32px)); }
  .admin-layout { grid-template-columns: minmax(0,1fr); grid-template-areas: 'roster' 'create' 'events'; gap: 16px; }
  .has-companies { grid-template-areas: 'roster' 'create' 'events'; }
}

@media (max-width: 600px) {
  h1 { font-size: 23px; }
  .bar-content { min-height: 61px; gap: 8px; }
  .account-menu { gap: 1px; }
  .account-menu .button { padding-inline: 7px; }
  .admin-username { display: none; }
  .admin-main { padding-top: 21px; }
  .main-heading { align-items: start; }
  .main-heading p { font-size: 13px; max-width: 250px; }
  .auth-panel { padding: 21px; }
  .button { min-height: 44px; }
  .field input, .field select { font-size: 16px; }
  .section-line { padding: 13px 14px; }
  .company-grid {
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas: 'identity state' 'date action';
    gap: 4px 12px;
    padding-inline: 14px;
  }
  .column-heads { display: none; }
  .company-identity { grid-area: identity; }
  .company-state { grid-area: state; justify-self: end; align-self: start; }
  .company-date { grid-area: date; }
  .company-date:not(.no-expiry)::before { content: "到期 "; color: var(--muted); }
  .row-action { grid-area: action; }
  .company-controls { grid-template-columns: minmax(0,1fr); padding-inline: 14px; }
  .company-controls .button { min-height: 44px; }
  .empty { margin-inline: 14px; }
  .table-scroll { overflow: visible; }
  table, tbody { display: block; }
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  tbody tr {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas: 'identity identity' 'created days' 'expiry expiry' 'note note';
    gap: 5px 12px;
    padding: 12px 14px;
    border-top: 1px solid var(--rule);
  }
  tbody td, tbody td:first-child, tbody td:last-child {
    padding: 0;
    min-width: 0;
    max-width: none;
    border: 0;
  }
  .event-identity { grid-area: identity; }
  .event-action { display: inline; margin-inline-start: 8px; }
  .event-created { grid-area: created; color: var(--muted); }
  .event-days { grid-area: days; color: var(--muted); }
  .event-expiry { grid-area: expiry; }
  .event-note { grid-area: note; }
  .record-label { display: inline; color: var(--muted); }
}

/* 字段帮助：标签旁的小问号，鼠标移入或键盘聚焦即显示规则 */
.field-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 20px; width: 100%; }
.field-head label { margin: 0; line-height: 20px; }
.help { position: relative; display: inline-flex; align-items: center; }
.help-badge {
  box-sizing: border-box; cursor: help;
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; padding: 0; border-radius: 50%;
  border: 1px solid #c4ccc2; background: var(--surface); color: #6f7a71;
  font-size: 10.5px; font-weight: 700; line-height: 1; user-select: none;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}
.help-badge:hover, .help-badge:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.help-badge:focus-visible { box-shadow: 0 0 0 3px rgba(53, 99, 75, .15); }
.help-panel {
  display: none; position: absolute; z-index: 30; top: calc(100% + 8px); left: -10px; width: min(280px, 72vw);
  box-sizing: border-box; padding: 10px 12px 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; text-align: left;
  box-shadow: 0 16px 34px -14px rgba(32, 40, 35, .28);
}
.help:hover > .help-panel, .help:focus-within > .help-panel { display: block; }
.help:hover > .help-badge { border-color: var(--accent); color: var(--accent); background: var(--soft-green); }
.help-panel .help-title { display: block; margin: 0 0 6px; font-size: 12.5px; font-weight: 600; color: var(--text); letter-spacing: .01em; }
.help-panel ul {
  margin: 0; padding-inline-start: 14px; display: grid; gap: 4px;
  color: var(--muted); font-size: 12px; line-height: 1.55;
}
.help-panel li::marker { color: #a9b2a8; }

/* 密码框的小眼睛 */
.password-wrap { position: relative; display: block; }
.password-wrap > input { width: 100%; box-sizing: border-box; padding-right: 40px; }
.reveal {
  position: absolute; top: 50%; right: 5px; transform: translateY(-50%);
  display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 6px; background: none; color: #98a19a; cursor: pointer;
}
.reveal:hover { color: var(--accent); background: var(--soft-green); }
.reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.reveal .slash { display: none; }
.reveal[aria-pressed="true"] { color: var(--accent); }
.reveal[aria-pressed="true"] .slash { display: block; }
