:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #102033;
  --muted: #66768a;
  --border: #d9e2ec;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --dark: #17202a;
  --danger-bg: #fef2f2;
  --danger: #b91c1c;
  --success-bg: #ecfdf5;
  --success: #047857;
  --sidebar: #0f172a;
  --sidebar-muted: #9fb0c7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

a {
  color: var(--primary);
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.3;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
}

h3 {
  font-size: 15px;
  line-height: 1.35;
}

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

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

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(16, 32, 51, 0.08);
}

.stack-form {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  font: inherit;
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

input[type="file"] {
  min-width: 260px;
  padding: 7px 10px;
}

textarea {
  min-height: 112px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.5;
}

button,
.ghost-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

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

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.secondary-button {
  background: var(--dark);
  color: #ffffff;
}

.ghost-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
}

.mini-button {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.danger-button {
  color: var(--danger);
  border-color: #fecaca;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 22px;
  line-height: 1;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  background: var(--sidebar);
  color: #ffffff;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 900;
}

.sidebar-brand strong,
.sidebar-brand small {
  display: block;
}

.sidebar-brand small {
  margin-top: 2px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--sidebar-muted);
  text-decoration: none;
}

.sidebar-nav a.active {
  color: #ffffff;
  background: rgba(15, 118, 110, 0.28);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--sidebar-muted);
}

.sidebar-footer .ghost-button {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.admin-main {
  min-width: 0;
}

.content-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px 32px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.content-page {
  width: min(1280px, calc(100% - 48px));
  margin: 24px auto 48px;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stat {
  padding: 18px;
  display: grid;
  gap: 8px;
}

.stat span {
  color: var(--muted);
}

.stat strong {
  font-size: 28px;
  line-height: 1;
}

.panel {
  padding: 20px;
  margin-top: 16px;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  max-width: 260px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
}

td {
  color: #243447;
}

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

tr.selected td {
  background: #ecfeff;
}

.muted {
  color: var(--muted);
}

.data-grid {
  max-height: 560px;
  scrollbar-gutter: stable;
}

.data-grid table {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.data-grid th,
.data-grid td {
  min-width: 136px;
  width: 152px;
  max-width: 180px;
  padding: 9px 10px;
  border-right: 1px solid #eef3f8;
}

.data-grid th:last-child,
.data-grid td:last-child {
  border-right: 0;
}

.data-grid th {
  height: 58px;
  vertical-align: middle;
}

.data-grid .row-id-head,
.data-grid .row-id,
.data-grid .row-number-head,
.data-grid .row-number,
.data-grid .row-actions-head,
.data-grid .row-actions {
  position: sticky;
  background: #ffffff;
}

.data-grid .row-id-head,
.data-grid .row-id {
  left: 0;
  min-width: 82px;
  width: 82px;
  max-width: 82px;
}

.data-grid .row-number-head,
.data-grid .row-number {
  left: 82px;
  min-width: 72px;
  width: 72px;
  max-width: 72px;
}

.data-grid .row-actions-head,
.data-grid .row-actions {
  right: 0;
  min-width: 92px;
  width: 92px;
  max-width: 92px;
  text-align: center;
}

.data-grid .row-id-head,
.data-grid .row-number-head,
.data-grid .row-actions-head {
  z-index: 4;
  background: #f8fafc;
}

.data-grid .row-id,
.data-grid .row-number {
  z-index: 2;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.data-grid .row-actions {
  z-index: 3;
}

.data-grid tbody tr:hover td {
  background: #f8fbff;
}

.data-grid tbody tr:hover .row-id,
.data-grid tbody tr:hover .row-number {
  background: #f8fbff;
}

.data-grid tbody tr:hover .row-actions {
  background: #f8fbff;
}

.data-head-cell {
  color: #17314d;
}

.data-head-index {
  display: block;
  margin-bottom: 4px;
  color: #7a8ca3;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0;
  font-weight: 800;
}

.data-head-label {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: #17314d;
  font-size: 12px;
  line-height: 1.28;
  font-weight: 800;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.data-cell-value {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-height: 1.55;
  word-break: normal;
  overflow-wrap: break-word;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
}

.alert {
  padding: 12px 14px;
  margin-bottom: 16px;
  border-radius: 6px;
  font-weight: 600;
}

.alert.error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fecaca;
}

.alert.success {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid #bbf7d0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.modal.open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
}

.modal-dialog {
  position: relative;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100vh - 64px);
  margin: 64px auto;
  overflow: auto;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.26);
}

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

.modal-body {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.modal-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.modal-upload-form {
  display: grid;
  gap: 10px;
}

.row-edit-dialog {
  width: min(980px, calc(100% - 32px));
}

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

.edit-field textarea {
  min-height: 92px;
  max-height: 180px;
}

.modal-actions,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.binding-form,
.binding-edit-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: end;
}

.binding-list {
  display: grid;
  gap: 14px;
}

.binding-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.binding-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.binding-card-head strong {
  display: block;
  color: var(--text);
  font-size: 16px;
}

.status-pill {
  flex-shrink: 0;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.active {
  color: var(--success);
  background: var(--success-bg);
}

.status-pill.hidden {
  color: var(--muted);
  background: #e5e7eb;
}

.binding-row-summary {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

.binding-row-summary span,
.binding-row-summary strong {
  display: block;
}

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

.binding-row-summary strong {
  margin-top: 2px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px;
  }

  .sidebar-nav,
  .sidebar-footer {
    display: none;
  }

  .content-header {
    position: static;
    padding: 16px;
  }

  .content-page {
    width: min(100% - 24px, 1280px);
    margin-top: 14px;
  }

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

  .edit-field-grid,
  .binding-form,
  .binding-edit-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .content-header,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  button,
  .ghost-button,
  input[type="file"] {
    width: 100%;
  }

  .panel,
  .login-panel {
    padding: 16px;
  }
}
