.employee-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 24px 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.employee-profile-main {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.employee-avatar {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  color: var(--teal);
  background: #eaf4f2;
  font-size: 22px;
}

.employee-profile-main h1,
.employee-profile-main h2.panel-heading {
  margin: 3px 0 4px;
  color: var(--navy);
  font-size: 25px;
  font-weight: 650;
  letter-spacing: 0;
}

.employee-profile-main p {
  margin: 0;
  color: #42575b;
  font-size: 12px;
}

.employee-profile-main small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.employee-profile-actions {
  flex: 0 0 auto;
}

.ledger-summary {
  margin-bottom: 18px;
}

.ledger-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.ledger-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.ledger-toolbar h2 {
  margin: 3px 0 5px;
  color: var(--navy);
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

.ledger-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.ledger-toolbar .search-control {
  width: min(300px, 100%);
}

.device-ledger {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
  padding: 20px;
  background: var(--surface-soft);
}

.employee-device-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(20, 54, 59, 0.035);
}

.employee-device-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.device-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: var(--teal);
  background: #eaf4f2;
}

.device-mark svg {
  width: 18px;
  height: 18px;
}

.employee-device-copy {
  min-width: 0;
  flex: 1;
}

.employee-device-copy strong,
.employee-device-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-device-copy strong {
  color: var(--navy);
  font-size: 14px;
  font-weight: 650;
}

.employee-device-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.device-add-button {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #506267;
  background: #fff;
  font-size: 11px;
  font-weight: 600;
}

.device-add-button:hover {
  color: var(--teal);
  border-color: rgba(15, 118, 110, 0.35);
}

.device-add-button svg {
  width: 13px;
  height: 13px;
}

.employee-account-list {
  display: grid;
}

.employee-device-empty {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  color: var(--muted);
  background: #fff;
  font-size: 11px;
}

.employee-device-empty svg {
  width: 16px;
  height: 16px;
}

.ledger-account-row {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 14px 15px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: inherit;
  background: transparent;
  text-align: left;
}

.ledger-account-row:hover {
  background: #f7fbfa;
}

.ledger-account-copy {
  min-width: 0;
}

.ledger-account-copy strong,
.ledger-account-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-account-copy strong {
  color: #26383d;
  font-size: 12px;
  font-weight: 650;
}

.ledger-account-copy small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.ledger-chevron {
  width: 15px;
  height: 15px;
  color: #9aacae;
}

.employee-device-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 15px;
  color: var(--muted);
  background: #fbfcfc;
  font-size: 11px;
}

.risk-count {
  color: var(--red);
  font-weight: 600;
}

.ledger-empty {
  grid-column: 1 / -1;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px dashed #cbd8d6;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

.ledger-empty > svg {
  width: 32px;
  height: 32px;
  color: #97ada9;
}

.ledger-empty strong {
  color: var(--navy);
  font-size: 14px;
}

.ledger-empty span {
  font-size: 11px;
}

.ledger-empty .quiet-button {
  margin-top: 6px;
}

.quiet-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #526468;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
}

.quiet-button:hover {
  color: var(--navy);
  background: #f7faf9;
}

.ledger-dialog {
  width: min(820px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(13, 37, 41, 0.24);
}

.ledger-dialog::backdrop {
  background: rgba(16, 32, 35, 0.43);
  backdrop-filter: blur(2px);
}

/* 关闭态靠 UA 的 dialog:not([open]) 隐藏，作者样式会无条件压过 UA，
   所以 display 只在 [open] 时接管，否则关掉的弹窗会被显示出来 */
.ledger-dialog[open] {
  display: flex;
  flex-direction: column;
}

.ledger-dialog form {
  display: flex;
  flex-direction: column;
  /* 视口高度预算只写在 .ledger-dialog 一处，form 用 flex 吃满；
     原先两处各算一遍，差出 dialog 那 1px 上边框，被 overflow 裁掉 */
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.dialog-header {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 4px 0 0;
  color: var(--navy);
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

.dialog-body {
  display: grid;
  gap: 22px;
  padding: 20px 22px;
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.dialog-section,
.form-grid,
.field {
  min-width: 0;
}

.field input,
.field select,
.field textarea {
  min-width: 0;
  max-width: 100%;
}

.dialog-section {
  display: grid;
  gap: 12px;
}

.dialog-section + .dialog-section {
  padding-top: 19px;
  border-top: 1px solid var(--line);
}

.dialog-actions {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 9px;
  padding: 15px 22px;
  border-top: 1px solid var(--line);
  background: #fbfcfc;
}

.dialog-actions .primary-button {
  min-width: 110px;
}

body:has(.ledger-dialog[open]) {
  overflow: hidden;
}

@media (max-width: 760px) {
  .employee-profile {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 14px;
  }

  .employee-profile-actions .primary-button {
    width: auto;
    min-height: 40px;
    padding: 0 13px;
    white-space: nowrap;
    box-shadow: none;
  }

  .employee-profile-main {
    min-width: 0;
    gap: 10px;
  }

  .employee-avatar {
    width: 44px;
    height: 44px;
    font-size: 17px;
  }

  .employee-profile-main h1,
  .employee-profile-main h2.panel-heading {
    margin: 2px 0 3px;
    font-size: 20px;
  }

  .employee-profile-main .eyebrow {
    margin-bottom: 4px;
    font-size: 11px;
  }

  .employee-profile-main small {
    display: none;
  }

  .ledger-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 12px 0 14px;
  }

  .ledger-summary .summary-item {
    min-width: 0;
    min-height: 78px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    padding: 11px 12px;
  }

  .ledger-summary .summary-icon {
    width: 28px;
    height: 28px;
  }

  .ledger-summary .summary-icon svg {
    width: 14px;
    height: 14px;
  }

  .ledger-summary .summary-item > div {
    display: block;
  }

  .ledger-summary .summary-item span {
    display: block;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ledger-summary .summary-item strong {
    display: block;
    margin-top: 1px;
    font-size: 21px;
  }

  .ledger-toolbar {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

  .ledger-toolbar .search-control {
    width: 100%;
  }

  .device-ledger {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .employee-device-head {
    flex-wrap: wrap;
  }

  .device-add-button {
    margin-left: 49px;
  }

  .ledger-dialog {
    inset: auto 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -18px 50px rgba(13, 37, 41, 0.24);
  }

  .dialog-header,
  .dialog-body,
  .dialog-actions {
    padding-left: 16px;
    padding-right: 16px;
  }

  .dialog-actions .quiet-button,
  .dialog-actions .primary-button {
    flex: 1;
  }

  .dialog-actions {
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }
}
