:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f9fbfb;
  --line: #dfe6e4;
  --text: #17211e;
  --muted: #66736f;
  --green: #16745a;
  --green-soft: #e6f4ef;
  --amber: #b7791f;
  --amber-soft: #fff4d8;
  --red: #b33b3b;
  --red-soft: #fae8e8;
  --shadow: 0 16px 36px rgba(26, 42, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body.selection-active {
  padding-bottom: 84px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #b9c7c3;
  background: #f7faf9;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  width: min(1440px, calc(100vw - 48px));
  margin: 24px auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 20px;
}

.ghost-btn {
  min-width: 98px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 5px;
  font-size: 25px;
}

.workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  align-items: start;
}

.filters,
.table-area {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filters {
  padding: 16px;
  position: sticky;
  top: 16px;
}

.filters label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

select,
input[type="search"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

select:focus,
input:focus {
  border-color: #8eb8aa;
  box-shadow: 0 0 0 3px rgba(22, 116, 90, 0.12);
}

.bulk-panel {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 8px;
}

.bulk-count {
  color: var(--muted);
  font-size: 13px;
}

.bulk-panel button {
  width: 100%;
  text-align: center;
}

.table-area {
  overflow: hidden;
}

.table-toolbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.table-toolbar strong {
  margin-right: 10px;
}

.table-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.select-all {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-height: calc(100vh - 245px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4f2;
  color: #41514c;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
}

tbody tr:hover {
  background: #fbfdfc;
}

.check-col {
  width: 42px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 88px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 92px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 96px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 260px;
}

.code {
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 15px;
  letter-spacing: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-width: 58px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.pill.normal {
  background: var(--green-soft);
  color: var(--green);
}

.pill.used {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.hidden {
  background: var(--red-soft);
  color: var(--red);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.row-actions button {
  padding: 6px 9px;
  font-size: 13px;
}

.danger {
  color: var(--red);
}

.primary-danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.primary-danger:hover {
  background: #9e3232;
  border-color: #9e3232;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 44px 12px;
}

dialog {
  border: none;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.18);
}

dialog::backdrop {
  background: rgba(19, 28, 26, 0.42);
}

.password-card {
  width: 360px;
  display: grid;
  gap: 14px;
  padding: 12px;
}

.password-card h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #17211e;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  font-size: 14px;
}

body.selection-active .toast {
  bottom: 94px;
}

.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 20;
  width: min(720px, calc(100vw - 32px));
  min-height: 56px;
  display: grid;
  grid-template-columns: auto repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
  transform: translateX(-50%);
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 50px rgba(21, 35, 31, 0.18);
  padding: 10px;
  backdrop-filter: blur(12px);
}

.selection-bar[hidden] {
  display: none !important;
}

.selection-bar strong {
  white-space: nowrap;
  font-size: 14px;
}

.selection-bar button {
  min-height: 38px;
}

@media (max-width: 980px) {
  .shell {
    width: min(100% - 28px, 760px);
    margin: 16px auto;
  }

  .topbar {
    align-items: flex-start;
    gap: 14px;
  }

  h1 {
    font-size: 24px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .filters {
    position: static;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .filters label {
    margin-bottom: 0;
  }

  .bulk-panel {
    grid-column: 1 / -1;
    grid-template-columns: auto repeat(4, minmax(0, 1fr));
    align-items: center;
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }

  .bulk-panel button {
    min-height: 40px;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .shell {
    width: calc(100% - 18px);
    margin: 10px auto 18px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .ghost-btn {
    flex: 1;
  }

  h1 {
    font-size: 22px;
  }

  p {
    font-size: 13px;
    line-height: 1.45;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 11px 12px;
  }

  .stat-card strong {
    font-size: 22px;
  }

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

  .bulk-panel {
    grid-template-columns: 1fr;
  }

  .table-toolbar {
    height: auto;
    min-height: 58px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 10px;
  }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    overflow: hidden;
  }

  tbody tr:hover {
    background: var(--panel);
  }

  tbody td {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    min-height: 42px;
  }

  tbody td:last-child {
    border-bottom: 0;
  }

  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .check-col,
  th:nth-child(2),
  td:nth-child(2),
  th:nth-child(3),
  td:nth-child(3),
  th:nth-child(5),
  td:nth-child(5),
  th:nth-child(6),
  td:nth-child(6) {
    width: auto;
  }

  .code {
    font-size: 14px;
    word-break: break-all;
  }

  .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .row-actions button {
    min-height: 36px;
  }

  body.selection-active {
    padding-bottom: 150px;
  }

  .selection-bar {
    left: 9px;
    right: 9px;
    bottom: 8px;
    width: auto;
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    transform: none;
  }

  .selection-bar strong {
    grid-column: 1 / -1;
  }

  .selection-bar button {
    min-height: 40px;
  }

  body.selection-active .toast {
    bottom: 150px;
  }

  .empty {
    display: block;
  }

  .empty::before {
    content: "";
  }

  .password-card {
    width: min(360px, calc(100vw - 48px));
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
  }
}
