:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #fbfbfc;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --accent: #111827;
  --accent-soft: #f3f4f6;
  --danger: #dc2626;
  --success: #047857;
  --warning: #b45309;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  display: block;
}

.app-shell.sidebar-open {
  padding-left: 244px;
}

.sidebar-toggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 30;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 8px 24px rgb(17 24 39 / 0.08);
}

.sidebar-toggle:hover {
  background: var(--accent-soft);
}

.app-shell.sidebar-open .sidebar-toggle {
  left: 258px;
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  width: 244px;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 25;
  overflow-y: auto;
}

.app-shell.sidebar-closed .sidebar {
  display: none;
}

.app-shell.sidebar-closed .content {
  padding-left: 72px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-weight: 650;
  font-size: 16px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #111827;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 750;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav button {
  height: 38px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  text-align: left;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav button.active,
.nav button:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.content {
  padding: 28px;
  min-width: 0;
}

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

.title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 720;
}

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

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

.panel-pad {
  padding: 18px;
}

.metric {
  display: grid;
  gap: 8px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  font-size: 28px;
  font-weight: 760;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title {
  font-weight: 680;
  font-size: 15px;
}

.form {
  display: grid;
  gap: 12px;
}

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

.toggle-line {
  min-height: 40px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--muted-strong);
  white-space: nowrap;
}

.toggle-line input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.compatibility-toggle {
  gap: 8px;
}

.info-dot {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--muted);
  border-radius: 999px;
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  flex: 0 0 auto;
}

.stack {
  display: grid;
  gap: 10px;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.input {
  height: 40px;
  padding: 0 11px;
}

select.input[multiple] {
  height: 96px;
  padding: 8px 11px;
}

.textarea {
  min-height: 110px;
  padding: 11px;
  resize: vertical;
  line-height: 1.45;
}

.input:focus,
.textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}

.button {
  height: 38px;
  border-radius: 7px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
}

.button.secondary.attention {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.button.ghost {
  background: transparent;
  color: var(--muted-strong);
}

.button.danger {
  color: #fff;
  background: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-weight: 560;
  font-size: 12px;
}

td.wrap {
  white-space: normal;
  word-break: break-all;
}

.badge {
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  display: inline-flex;
  align-items: center;
  background: var(--accent-soft);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
}

.badge.ok {
  background: #ecfdf5;
  color: var(--success);
}

.badge.off {
  background: #f3f4f6;
  color: var(--muted);
}

.badge.warn {
  background: #fffbeb;
  color: var(--warning);
}

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

.link-actions {
  display: grid;
  gap: 8px;
  min-width: 460px;
}

.import-panel {
  padding: 14px;
}

.compact-import-form {
  gap: 8px;
}

.import-grid-main,
.import-grid-filters {
  display: grid;
  gap: 10px;
  align-items: stretch;
}

.import-grid-main {
  grid-template-columns: minmax(170px, 0.7fr) minmax(150px, 0.55fr) minmax(280px, 1.5fr) auto;
}

.import-grid-filters {
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto minmax(180px, 0.7fr);
}

.import-panel .textarea {
  min-height: 72px;
  width: 100%;
  min-width: 220px;
  resize: both;
}

.import-panel .input,
.import-panel .textarea {
  min-height: 40px;
}

.group-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 360px) auto;
  gap: 10px;
  align-items: center;
}

.group-card {
  display: grid;
  gap: 12px;
}

.group-card-main {
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.group-source-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.source-mini-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-soft);
}

.source-mini-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.source-mini-main input {
  flex: 0 0 auto;
}

.group-move-controls,
.group-add-source,
.group-bulk-move {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.group-add-source {
  margin-top: 12px;
}

.group-bulk-move {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.group-move-select,
.source-group-filter {
  width: 180px;
}

.import-panel .toggle-line,
.import-panel .row {
  min-height: 40px;
}

.source-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  margin-bottom: 0;
}

.source-toolbar > .source-search {
  flex: 1 1 360px;
}

.source-toolbar-bottom {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.source-search {
  width: min(420px, 42vw);
}

.source-sort-button {
  flex: 0 0 auto;
}

.source-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.source-page-size {
  width: 120px;
}

.source-card-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.source-card {
  border: 1.5px solid #111827;
  border-radius: 7px;
  padding: 9px 10px;
  display: grid;
  gap: 8px;
  background: #fff;
}

.source-card:first-child {
  border-top: 1.5px solid #111827;
}

.source-card-head {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.source-leading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

.source-index {
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.source-check {
  height: 24px;
  display: grid;
  place-items: center;
}

.source-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.source-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-url {
  display: grid;
  gap: 6px;
  color: var(--muted-strong);
  line-height: 1.35;
}

.source-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 26px;
  gap: 8px;
  align-items: center;
}

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

.source-info-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.source-info-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  background: var(--panel-soft);
}

.source-info-grid p {
  margin: 4px 0 0;
  line-height: 1.35;
  word-break: break-word;
  max-height: 38px;
  overflow: auto;
  font-size: 13px;
}

.source-info-grid .field-line {
  align-items: flex-start;
}

.source-info-grid .field-line span:not(.badge) {
  max-height: 38px;
  overflow: auto;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  font-size: 13px;
}

.info-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.source-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.op-times {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.field-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.field-line span,
.field-line strong {
  min-width: 0;
}

.icon-button {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted-strong);
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.icon-button:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.op-time {
  color: var(--text);
  font-size: 13px;
  line-height: 26px;
  white-space: nowrap;
}

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

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

.login-card {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 18px 60px rgb(17 24 39 / 0.08);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: #111827;
  color: #fff;
  padding: 16px 18px;
  border-radius: 8px;
  box-shadow: 0 16px 50px rgb(17 24 39 / 0.18);
  font-size: 15px;
  line-height: 1.45;
  z-index: 20;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(17 24 39 / 0.38);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
  overflow: hidden;
}

.modal {
  width: min(720px, 100%);
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 18px;
}

.modal-wide {
  width: min(920px, 100%);
}

.modal-full {
  width: min(1560px, calc(100vw - 40px));
  height: min(900px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
  padding: 12px;
}

.fixed-modal {
  align-items: center;
}

.modal-create-panel {
  padding: 10px;
}

.modal-create-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1.1fr) minmax(210px, 0.9fr) minmax(210px, 0.9fr) minmax(170px, 0.75fr) auto auto;
  gap: 8px;
  align-items: center;
}

.modal-links-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.modal-table-wrap {
  min-height: 0;
  overflow: auto;
  max-width: 100%;
}

.modal-table-wrap table {
  min-width: 1280px;
  table-layout: fixed;
}

.modal-table-wrap th,
.modal-table-wrap td {
  padding: 10px 9px;
  vertical-align: top;
}

.modal-table-wrap th:nth-child(1),
.modal-table-wrap td:nth-child(1) {
  width: 42px;
}

.modal-table-wrap th:nth-child(2),
.modal-table-wrap td:nth-child(2) {
  width: 190px;
}

.modal-table-wrap th:nth-child(3),
.modal-table-wrap td:nth-child(3) {
  width: 125px;
}

.modal-table-wrap th:nth-child(4),
.modal-table-wrap td:nth-child(4) {
  width: 180px;
}

.modal-table-wrap th:nth-child(5),
.modal-table-wrap td:nth-child(5) {
  width: 80px;
}

.modal-table-wrap th:nth-child(6),
.modal-table-wrap td:nth-child(6) {
  width: 155px;
}

.modal-table-wrap th:nth-child(7),
.modal-table-wrap td:nth-child(7) {
  width: 260px;
}

.modal-table-wrap th:nth-child(8),
.modal-table-wrap td:nth-child(8) {
  width: 110px;
}

.modal-table-wrap th:nth-child(9),
.modal-table-wrap td:nth-child(9) {
  width: 380px;
}

.modal-table-wrap td.wrap {
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.45;
}

.modal-table-wrap .link-actions {
  min-width: 0;
}

.modal-table-wrap .link-actions > .actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, max-content));
  justify-content: start;
  gap: 7px;
}

.modal-table-wrap .link-actions .button {
  min-width: 82px;
}

.modal-table-wrap .op-times {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.modal-table-wrap .op-time {
  white-space: normal;
  line-height: 1.35;
  font-size: 12px;
}

.modal-table-wrap .field-line {
  align-items: flex-start;
}

.modal-filter-input {
  width: min(320px, 36vw);
}

.modal-filter-select {
  width: 150px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  border-top: 1px solid var(--line);
}

.link-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.link-label {
  color: var(--muted-strong);
  font-weight: 650;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

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

  .app-shell.sidebar-open {
    padding-left: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: min(280px, calc(100vw - 72px));
    min-height: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 20px 60px rgb(17 24 39 / 0.16);
  }

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

  .nav button {
    justify-content: flex-start;
    text-align: left;
  }

  .content {
    padding: 18px 18px 18px 66px;
  }

  .app-shell.sidebar-closed .content {
    padding-left: 66px;
  }

  .app-shell.sidebar-open .sidebar-toggle {
    left: min(292px, calc(100vw - 54px));
  }

  .topbar,
  .row {
    align-items: stretch;
    flex-direction: column;
  }

  .link-row {
    grid-template-columns: 1fr;
  }

  .source-title,
  .source-toolbar,
  .source-pager,
  .source-card-actions,
  .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .source-badges {
    justify-content: flex-start;
  }

  .source-info-grid,
  .import-grid-main,
  .import-grid-filters,
  .modal-create-grid,
  .group-create-form,
  .source-mini-card {
    grid-template-columns: 1fr;
  }

  .source-search,
  .source-sort-button,
  .source-page-size {
    width: 100%;
  }

  .source-group-filter,
  .group-move-select {
    width: 100%;
  }

  .modal-filter-input,
  .modal-filter-select {
    width: 100%;
  }

  .modal-full {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
