:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #111827;
  --muted: #667085;
  --line: #d8dee7;
  --line-strong: #c2ccd8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #e6fffb;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #a15c07;
  --warning-soft: #fff7e6;
  --ok: #027a48;
  --ok-soft: #ecfdf3;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(420px, 100%);
  border-radius: 8px;
  padding: 28px;
  display: grid;
  gap: 18px;
}

.login-panel h1,
.topbar h1,
.modal-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: 28px;
  line-height: 1.2;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar h1 {
  font-size: 28px;
}

.topbar-actions,
.toolbar-actions,
.pager,
.field-heading,
.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(460px, 1.5fr) auto;
  gap: 12px;
  align-items: end;
}

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-box input {
  padding-left: 34px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
}

label > span,
.field-heading span:first-child {
  font-size: 12px;
  font-weight: 700;
  color: #344054;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

textarea {
  min-height: 170px;
  resize: vertical;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.tiny-btn,
.icon-btn {
  border-radius: 6px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  padding: 0 13px;
  white-space: nowrap;
}

.primary-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn,
.ghost-btn {
  background: #fff;
  border-color: var(--line-strong);
  color: #1f2937;
}

.danger-btn {
  background: #fff;
  border-color: #fecdca;
  color: var(--danger);
  font-weight: 700;
}

.danger-btn:hover:not(:disabled) {
  background: var(--danger-soft);
}

.ghost-btn {
  background: transparent;
}

.tiny-btn {
  min-height: 30px;
  padding: 0 9px;
  background: var(--panel-2);
  border-color: var(--line);
  color: #344054;
  font-size: 12px;
}

.icon-btn {
  width: 38px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  font-size: 22px;
  line-height: 1;
}

.full {
  width: 100%;
}

.icon {
  font-size: 16px;
  line-height: 1;
}

.spin {
  display: inline-block;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.14);
  padding: 6px;
}

.menu button {
  width: 100%;
  border: 0;
  background: transparent;
  min-height: 38px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--text);
  text-align: left;
}

.menu button:hover {
  background: var(--panel-2);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.summary-strip > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  display: grid;
  gap: 2px;
}

.summary-strip strong {
  font-size: 22px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
}

.table-shell {
  position: relative;
  min-height: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 940px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f3f5f7;
  color: #475467;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tbody tr:hover {
  background: #fbfcfd;
}

.account-title {
  display: grid;
  gap: 3px;
}

.account-title strong {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.muted,
.account-note {
  color: var(--muted);
}

.account-note {
  font-size: 12px;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: #344054;
}

.badge.ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: #abefc6;
}

.badge.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #fecdca;
}

.badge.warn {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: #fedf89;
}

.mobile-list {
  display: none;
}

.mobile-card {
  border-bottom: 1px solid var(--line);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.mobile-card .meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mobile-card .meta-grid strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  margin-top: 2px;
}

.empty-state,
.loading-state {
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.pager {
  justify-content: flex-end;
}

.pager select {
  width: auto;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(960px, calc(100vw - 24px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.44);
}

.modal-panel {
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 16px;
  max-height: min(88vh, 900px);
  overflow: auto;
}

.modal-panel.wide {
  width: min(960px, calc(100vw - 24px));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.modal-header h2 {
  font-size: 22px;
}

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

.span-2 {
  grid-column: span 2;
}

.field-block {
  display: grid;
  gap: 10px;
}

.field-heading {
  justify-content: space-between;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: var(--panel-2);
  min-height: 44px;
}

.choice input {
  width: 16px;
  min-height: 16px;
}

.choice span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: 16px;
  min-height: 16px;
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.import-preview,
.import-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
  color: #344054;
  font-size: 13px;
  white-space: pre-wrap;
}

.imported-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fff;
}

.imported-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.imported-list {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
}

.batch-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
}

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

.batch-stats > div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 2px;
}

.batch-stats strong {
  font-size: 20px;
}

.batch-stats span {
  color: var(--muted);
  font-size: 12px;
}

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e7ec;
}

.progress > div {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 160ms ease;
}

.batch-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
}

.batch-list {
  max-height: min(52vh, 520px);
}

.imported-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: var(--panel-2);
}

.imported-item-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.imported-item-title {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.imported-item-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imported-test-error {
  color: var(--danger);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.batch-select {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.batch-select input {
  width: 16px;
  min-width: 16px;
  min-height: 16px;
  margin-top: 3px;
}

.batch-select span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.batch-select strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-select em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.batch-pager {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.import-result.error {
  border-color: #fecdca;
  background: var(--danger-soft);
  color: var(--danger);
}

.import-result.success {
  border-color: #abefc6;
  background: var(--ok-soft);
  color: var(--ok);
}

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 100;
}

.toast {
  width: min(380px, calc(100vw - 32px));
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: #263238;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--ok);
}

.form-error {
  color: var(--danger);
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1080px) {
  .toolbar {
    grid-template-columns: 1fr;
  }

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

  .toolbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar-actions,
  .toolbar-actions,
  .pager {
    width: 100%;
  }

  .topbar-actions > *,
  .toolbar-actions > *,
  .pager > * {
    flex: 1;
  }

  .filters,
  .summary-strip,
  .batch-stats,
  .batch-controls,
  .form-grid,
  .json-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .table-scroll {
    display: none;
  }

  .mobile-list {
    display: block;
  }

  .modal {
    width: calc(100vw - 16px);
  }

  .modal-panel,
  .modal-panel.wide {
    width: 100%;
    max-height: 92vh;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer > * {
    width: 100%;
  }

  .imported-actions > * {
    width: 100%;
  }

  .login-panel {
    padding: 22px;
  }
}
