:root {
  --page: #f6f6fb;
  --nav: #fff;
  --ink: #1d1d1f;
  --muted: #626269;
  --line: #e1e1ec;
  --blue: #0000cc;
  --blue-hover: #0000ac;
  --blue-soft: #eeeefe;
  --brand-red: #ed1b24;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

body { grid-template-columns: 208px minmax(0, 1fr); }
body > main, .panel, .content, .top-actions { min-width: 0; }
button, input, select, textarea { border-radius: 11px; border-color: var(--line); }
button:not(.primary):hover { background: #f0f3f7; }
.primary, .hero .primary, .account-card a.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.primary:hover, .hero .primary:hover, .account-card a.primary:hover { background: var(--blue-hover); }
:focus-visible { outline-color: var(--blue); }
.danger, .error { color: #ad1d29; }
.trial-status { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; vertical-align: middle; }
.incomplete-trial {
  display: inline-block; width: fit-content; max-width: 100%; padding: 3px 7px; border-radius: 7px;
  background: #fff0f1; color: #ad1d29; border: 1px solid #f0c5ca; font-size: 12px;
  font-weight: 700; line-height: 1.45; white-space: normal; overflow-wrap: anywhere;
}
.trial-board th:nth-last-child(2), .motor-board th:nth-last-child(2) { width: 12%; }

.sidebar { padding: 22px 14px 15px; gap: 24px; background: #fff; border-color: var(--line); color: var(--ink); }
.sidebar .brand { display: grid; gap: 10px; justify-items: start; padding: 0 12px; }
.brand div span { color: var(--muted); }
.company-logo { display: block; width: 104px; height: auto; flex: none; object-fit: contain; }
nav button { color: var(--muted); border-radius: 11px; }
nav button.active, nav button:hover { color: var(--blue); background: var(--blue-soft); box-shadow: none; }
nav button.active { box-shadow: inset 3px 0 var(--brand-red); }

.top { padding-block: 12px; min-height: 64px; font-size: 15px; }
.top button, .site-account, .data-menu summary { font-size: 14px; }
.top b { color: var(--muted); }
.site-account, .account-card a:not(.primary) { color: var(--blue); }
.sidebar-account {
  display: flex; align-items: center; gap: 9px; min-width: 0; min-height: 54px; margin-top: auto;
  padding: 7px; border: 1px solid transparent; border-radius: 14px; color: var(--ink);
}
.sidebar-account:hover { background: var(--blue-soft); border-color: #e0e0ff; }
.account-avatar {
  display: grid; flex: none; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  font-size: 15px; font-weight: 700; background: var(--blue); color: #fff;
}
.account-caption { display: grid; min-width: 0; line-height: 1.28; }
.account-caption strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.account-caption small { color: var(--muted); font-size: 12px; }
.data-menu { position: relative; }
.data-menu summary, .member-actions summary { cursor: pointer; color: var(--ink); }
.data-menu summary { padding: 8px 11px; border: 1px solid var(--line); border-radius: 11px; white-space: nowrap; }
.data-menu[open] summary { background: var(--page); }
.data-menu-items { position: absolute; z-index: 9; top: calc(100% + 6px); right: 0; display: grid; gap: 4px; padding: 6px; min-width: 138px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 8px 24px #17172217; }
.data-menu-items button { text-align: left; border: 0; }

.content { padding-top: 30px; }
.hero { min-height: 0; padding: 26px 28px; margin-bottom: 17px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 2px 8px #18182108; }
.hero::before { content: none; }
.hero h1 { font-size: clamp(26px, 4vw, 40px); line-height: 1.15; letter-spacing: -.035em; }
.hero p { color: var(--muted); margin-top: 8px; }
.export-button {
  display: inline-flex; min-height: 44px; align-items: center; padding: 7px 12px; border-radius: 11px;
  border: 1px solid #d8d8f5; background: #fff; color: var(--blue); text-decoration: none; font-weight: 600;
}
.export-button:hover { background: var(--blue-soft); }
.stat, .panel { border: 1px solid var(--line); border-radius: 19px; box-shadow: 0 2px 8px #18182108; }
.stat span, .sync-panel { font-size: 14px; }
.stat strong { line-height: 1.13; margin-top: 8px; }
.sync-panel { background: transparent; border: 0; padding: 0 2px; margin: 0 0 14px; }
th { color: var(--muted); background: #f8f8fa; }
.trial-board tbody tr[data-peek-row]:hover, .motor-board tbody tr[data-peek-row]:hover { background: #f6f9fd; }
dialog, .trial-peek { border-radius: 22px; }
dialog::backdrop { background: #1c213566; }
.form-nav { background: #f8f8fa; }
.form-nav button, .form-body h3 { color: var(--ink); }
#toast { background: #28282b; color: #fff; }

.account-page { grid-template-columns: minmax(0, 1fr); min-height: 100dvh; padding: 24px; }
.account-card { width: min(620px, 100%); padding: clamp(18px, 5vw, 36px); border-radius: 25px; box-shadow: 0 10px 28px #1818210e; }
.account-header { display: flex; gap: 13px; align-items: center; margin-bottom: 20px; }
.account-header .company-logo { width: 64px; }
.account-header p { margin: 0; font-size: 14px; }
.account-card h1 { font-size: clamp(25px, 6vw, 34px); }
.account-card .account-form { gap: 11px; }
.account-card :is(input, select, button, .primary) { min-height: 44px; }
.account-card .account-form :is(input, select) { width: 100%; min-width: 0; }
.account-card .account-form input { background: #fbfbfc; }
.account-card form[action="/account/login"] .primary { width: 100%; }
.account-card form[action="/account/users"] label { min-width: 0; }
.account-identity { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.account-identity p { font-size: 14px; }
.role-chip { display: inline-block; padding: 4px 10px; border-radius: 99px; background: #ececf1; color: #41414a; font-size: 14px; }
.role-chip[data-role="admin"] { background: var(--blue-soft); color: var(--blue); }
.role-chip[data-role="editor"] { background: #e3f5ed; color: #176343; }
.account-section { border-top: 1px solid var(--line); margin-top: 24px; }
.account-section > p { font-size: 14px; }
.role-guide { margin: 10px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: #fafafc; }
.role-guide > div { padding: 10px 12px; display: grid; grid-template-columns: 5em minmax(0, 1fr); align-items: start; gap: 8px; font-size: 14px; }
.role-guide > div + div { border-top: 1px solid var(--line); }
.role-guide dt { font-weight: 650; }
.role-guide dd { margin: 0; color: var(--muted); }
.account-user { padding: 14px; border-radius: 15px; }
.account-user > .account-form { grid-template-columns: minmax(0, 1fr) auto; align-items: end; margin-top: 12px; }
.member-actions { margin-top: 12px; padding-top: 9px; border-top: 1px solid var(--line); }
.member-actions summary { font-size: 14px; color: var(--muted); padding: 6px 0; }

@media screen {
  body {
    background-color: var(--page);
    background-image: radial-gradient(ellipse at 7% 13%, #e0e0ff 0, transparent 42%),
                      radial-gradient(ellipse at 100% 0, #ffe6e9 0, transparent 33%);
  }
  .top { position: sticky; top: 0; z-index: 6; }
  .sidebar nav { background: #fff; }
}

@supports ((-webkit-backdrop-filter: blur(12px)) or (backdrop-filter: blur(12px))) {
  @media screen {
    :is(.sidebar, .top, .data-menu-items, .account-card) {
      background-color: #ffffffe0;
      background-clip: padding-box;
      -webkit-backdrop-filter: saturate(145%) blur(18px);
      backdrop-filter: saturate(145%) blur(18px);
    }
    .sidebar nav { background: transparent; }
    .account-card { background-color: #ffffffe6; }
    dialog::backdrop {
      background: #1d20434b;
      -webkit-backdrop-filter: blur(7px);
      backdrop-filter: blur(7px);
    }
  }
}

@media screen and (min-width: 761px) and (max-width: 1040px) {
  body { grid-template-columns: 166px minmax(0, 1fr); }
  .trial-board tr, .motor-board tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media screen and (max-width: 760px) {
  body:not(.account-page) { display: block; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 14px 8px; border: 0; }
  .sidebar .brand { display: flex; gap: 8px; padding: 0; font-size: 14px; }
  .sidebar .company-logo { width: 48px; }
  .sidebar-account { min-height: 44px; margin-top: 0; gap: 6px; padding: 4px 5px; }
  .sidebar-account .account-avatar { width: 34px; height: 34px; }
  .sidebar-account .account-caption { max-width: 8ch; }
  .sidebar-account .account-caption small { display: none; }
  .sidebar nav {
    position: fixed; z-index: 7; bottom: 0; left: 0; right: 0; display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
    background: #fff;
  }
  nav button { display: grid; justify-items: center; padding: 4px; text-align: center; font-size: 14px; min-height: 53px; line-height: 1.15; }
  nav button span { width: auto; display: block; font-size: 20px; }
  nav button.active { box-shadow: inset 0 -2px var(--brand-red); }
  .top { min-height: 0; padding: 0 16px 10px; border-bottom: 1px solid var(--line); }
  .top > :first-child { display: none; }
  .top-actions { width: 100%; gap: 6px; }
  .top-actions :is(button, summary, a) { min-height: 44px; }
  .data-menu summary { display: list-item; align-content: center; }
  .content { padding: 15px 12px 18px; }
  .hero { padding: 17px; border-radius: 19px; gap: 12px; }
  .hero .actions button { min-height: 44px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { border-radius: 15px; padding: 12px; }
  .panel-head { padding: 14px; }
  #directory .panel-head .actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #directory #search { grid-column: 1 / -1; }
  :is(.content, .account-card, dialog) :is(input:not([type="checkbox"]), select, textarea) { min-width: 0; max-width: 100%; font-size: 16px; }
  .trial-board tbody, .motor-board tbody { display: grid; gap: 10px; padding: 0 10px 10px; }
  .trial-board tr, .motor-board tr { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: #fafafc; padding: 9px; border: 1px solid var(--line); border-radius: 15px; }
  .motor-board td, .trial-board td, .trial-board .inline-buttons button, .motor-board .inline-buttons button { font-size: 14px; }
  .trial-board td::before, .motor-board td::before { font-weight: 550; }
  .trial-board td:first-child, .motor-board td:first-child, .trial-board td:last-child, .motor-board td:last-child { grid-column: 1 / -1; }
  :is(.trial-board, .motor-board, .drive-board) td[data-label="填写状态"] { grid-column: 1 / -1; }
  .trial-board td:last-child::before, .motor-board td:last-child::before { display: none; }
  .trial-board td:nth-child(n+6):not(:nth-child(14)):not(:last-child):not([data-label="填写状态"]),
  .motor-board td:nth-child(n+4):not(:nth-last-child(3)):not(:last-child):not([data-label="填写状态"]) { display: none; }
  .trial-board td:first-child button, .motor-board td:first-child button { min-height: 36px; font-size: 16px; }
  .trial-board .inline-buttons button, .motor-board .inline-buttons button { min-height: 42px; padding-inline: 12px; }
  .drive-board thead { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  .drive-board tbody { display: grid; gap: 10px; padding: 0 10px 10px; }
  .drive-board tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: #fafafc; padding: 9px; border: 1px solid var(--line); border-radius: 15px; }
  .drive-board td { padding: 5px; border: 0; white-space: normal; overflow-wrap: anywhere; font-size: 14px; }
  .drive-board td:first-child, .drive-board td:last-child { grid-column: 1 / -1; }
  .drive-board td:not(:last-child)::before { content: attr(data-label); display: block; color: var(--muted); font-size: 12px; }
  .drive-board td:nth-child(n+6):not(:last-child):not([data-label="填写状态"]) { display: none; }
  .drive-board td button { min-height: 40px; }
  body[data-access="view"] .drive-board td:last-child { display: none; }
  dialog { width: 100%; max-width: 100%; max-height: 94dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  dialog form { max-height: 93dvh; }
  .dialog-head, .dialog-foot { flex-shrink: 0; padding: 11px 14px; }
  .dialog-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .dialog-head button, .dialog-foot button, .form-nav button { min-height: 44px; }
  .form-body { min-height: 0; padding-inline: 14px; overscroll-behavior: contain; }
  .form-body .fields { grid-template-columns: 1fr; }
  .form-body .fields label { grid-column: auto; }
  .report-content { max-height: none; }
  #toast { bottom: calc(74px + env(safe-area-inset-bottom)); }
  .account-page { padding: 14px; }
}

@supports ((-webkit-backdrop-filter: blur(12px)) or (backdrop-filter: blur(12px))) {
  @media screen and (max-width: 760px) {
    .sidebar {
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
    }
    .sidebar nav {
      background: #ffffffe0;
      -webkit-backdrop-filter: saturate(160%) blur(20px);
      backdrop-filter: saturate(160%) blur(20px);
    }
  }
}

@media (prefers-reduced-transparency: reduce) {
  :is(.sidebar, .sidebar nav, .top, .data-menu-items, .account-card) {
    background-color: #fff;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  dialog::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
