:root {
  --bg: #f4f6fb;
  --panel: rgba(255, 255, 255, 0.9);
  --line: #d7dfef;
  --text: #14213d;
  --muted: #667085;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --danger: #b42318;
  --yellow: #b58105;
  --green: #027a48;
  --blue: #175cd3;
  --shadow: 0 20px 45px rgba(20, 33, 61, 0.08);
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 26%),
    radial-gradient(circle at right, rgba(23, 92, 211, 0.08), transparent 28%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }

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

.sidebar {
  width: 260px;
  background: linear-gradient(180deg, #10233d 0%, #163452 100%);
  color: #fff;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: 100vh;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { font-size: 24px; font-weight: 700; }

.nav { display: flex; flex-direction: column; gap: 10px; }

.nav a {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  transition: 0.2s ease;
}

.nav a:hover { background: rgba(255, 255, 255, 0.12); }

.nav a.is-active {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.sidebar-foot { font-size: 14px; color: rgba(255, 255, 255, 0.85); }

.content { flex: 1; padding: 28px; }
.content.centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.content.centered .page-head {
  width: min(460px, 100%);
  text-align: center;
  margin-bottom: 18px;
}

.content.centered > .alert,
.content.centered .auth-card {
  width: min(460px, 100%);
}

.content.centered .auth-card .card {
  margin-bottom: 0;
}

.page-head { margin-bottom: 22px; }
h1, h2, p { margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 20px; margin-bottom: 4px; }
.muted { color: var(--muted); }
.eyebrow { color: var(--primary); font-weight: 700; margin-bottom: 8px; }

.card,
.stat-card,
.auth-card .card {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(215, 223, 239, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card { padding: 24px; margin-bottom: 22px; }
.auth-card { width: min(460px, 100%); }
.auth-card .card { padding: 32px; }

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

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

.stat-card { padding: 22px; }
.stat-card span { display: block; color: var(--muted); margin-bottom: 8px; }
.stat-card strong { font-size: 36px; }

.form,
.filters,
.mini-form { display: grid; gap: 16px; }

.filters {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
}

.batch-filter {
  display: grid;
  gap: 8px;
  min-width: 0;
  position: relative;
  z-index: 30;
}

.compact-filter {
  min-width: 0;
}

.filter-card {
  position: relative;
  z-index: 12;
  overflow: visible;
}

.filter-card .filters {
  grid-template-columns: minmax(280px, 1.9fr) minmax(140px, 0.95fr) minmax(140px, 0.95fr) minmax(110px, 0.75fr) minmax(110px, 0.75fr) minmax(110px, 0.75fr) auto;
}

.filter-card .batch-filter {
  grid-column: auto;
}

.batch-picker {
  position: relative;
}

.batch-picker-control {
  position: relative;
}

.batch-picker-control::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 15px;
  width: 10px;
  height: 10px;
  border: 2px solid #98a2b3;
  border-radius: 50%;
  pointer-events: none;
}

.batch-picker-control::after {
  content: "";
  position: absolute;
  left: 28px;
  top: 28px;
  width: 8px;
  height: 2px;
  border-radius: 999px;
  background: #98a2b3;
  transform: rotate(45deg);
  pointer-events: none;
}

.batch-picker-control input {
  padding-left: 44px;
  padding-right: 48px;
}

.batch-picker-toggle {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  transform: translateY(-50%);
}

.batch-picker-toggle::before {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  margin: 0 auto;
  border-right: 2px solid #667085;
  border-bottom: 2px solid #667085;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.batch-picker.is-open .batch-picker-toggle::before {
  transform: rotate(-135deg);
  margin-top: 4px;
}

.batch-picker-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 500;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.batch-picker-panel[hidden] {
  display: none;
}

.batch-picker-list {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.batch-option {
  width: 100%;
  display: flex;
  align-items: center;
  border: 1px solid #e2e8f0;
  background: #f8fbff;
  color: var(--text);
  border-radius: 10px;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
}

.batch-option[hidden] {
  display: none;
}

.batch-option:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.08);
}

.batch-option-text {
  display: block;
  width: 100%;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.batch-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 4px;
}

label span {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--muted);
}

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

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 12px 14px;
  color: var(--text);
}

textarea { resize: vertical; }

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

.checkbox-row span { margin: 0; }
.checkbox-row input { width: auto; }

.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #edf2fb; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: linear-gradient(135deg, #ef4444, #b42318); }
.btn-small { padding: 8px 12px; border-radius: 12px; font-size: 13px; }

.dropzone {
  border: 2px dashed rgba(15, 118, 110, 0.35);
  border-radius: 20px;
  padding: 40px 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(15, 118, 110, 0.06), rgba(255, 255, 255, 0.8));
  transition: 0.2s ease;
  position: relative;
  overflow: hidden;
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone.is-over {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.dropzone span { display: block; font-size: 18px; color: var(--text); margin-bottom: 6px; }
.dropzone small, .dropzone-meta { color: var(--muted); }

.upload-progress {
  display: none;
  gap: 8px;
}

.upload-progress.is-visible {
  display: grid;
}

.upload-progress-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #e8eef7;
}

.upload-progress-value {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #0ea5a1);
  transition: width 0.2s ease;
}

.list { margin: 0; padding-left: 18px; line-height: 1.8; }
.table-wrap { overflow: auto; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid #e9eef7;
  vertical-align: top;
}

thead th { background: #f8fbff; position: sticky; top: 0; }

.mono { font-family: Consolas, Monaco, monospace; }
.small { font-size: 12px; }

.alert {
  padding: 14px 18px;
  border-radius: 16px;
  margin-bottom: 18px;
}

.alert-success { background: rgba(2, 122, 72, 0.12); color: #05603a; }
.alert-error { background: rgba(180, 35, 24, 0.12); color: #912018; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}

.badge-green { color: var(--green); background: rgba(2, 122, 72, 0.12); }
.badge-yellow { color: var(--yellow); background: rgba(181, 129, 5, 0.14); }
.badge-red { color: var(--danger); background: rgba(180, 35, 24, 0.12); }
.badge-blue { color: var(--blue); background: rgba(23, 92, 211, 0.12); }
.badge-gray { color: #475467; background: #eef2f7; }

.filter-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.section-head .inline-actions {
  margin-top: 0;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.filters .filter-actions {
  grid-column: auto;
  margin-top: 0;
  align-self: end;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.action-row form {
  margin: 0;
}

.mini-form {
  grid-template-columns: 120px 1fr auto;
  align-items: center;
}

.user-edit-form {
  display: grid;
  gap: 10px;
  min-width: 240px;
}

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

.history-filter {
  display: flex;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.history-filter label {
  min-width: 240px;
}

.narrow-form {
  max-width: 480px;
}

.profile-card {
  max-width: 720px;
}

.profile-grid {
  align-items: start;
}

.wallet-stats {
  display: grid;
  gap: 14px;
}

.wallet-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  background: rgba(237, 242, 251, 0.65);
}

.wallet-item span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.wallet-item strong {
  font-size: 24px;
}

.dashboard-top {
  align-items: start;
}

.notice-box {
  margin-top: 16px;
  background: #fff7d6;
  border: 1px solid #f5dea2;
  border-radius: 16px;
  padding: 14px;
  white-space: pre-wrap;
}

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

.ai-channel-card {
  margin-bottom: 0;
}

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

.ai-channel-switch span {
  color: var(--text);
  font-weight: 700;
}

.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  flex-wrap: wrap;
}

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

.page-link {
  min-width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #edf2fb;
}

.page-link.active { background: var(--primary); color: #fff; }
.page-link.disabled {
  background: #eef2f7;
  color: #98a2b3;
  cursor: not-allowed;
}

.page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  color: var(--muted);
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.page-jump input {
  width: 92px;
}

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

.col-title {
  width: 18%;
  min-width: 220px;
}

.records-table .col-title {
  width: 220px;
}

.cannot-delete {
  display: inline-block;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.danger-note {
  color: var(--danger);
  font-size: 13px;
}

.app-modal {
  width: min(560px, calc(100% - 32px));
  border: none;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(20, 33, 61, 0.18);
}

.app-modal::backdrop {
  background: rgba(16, 35, 61, 0.48);
}

.modal-close-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.modal-close {
  border: none;
  background: #edf2fb;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}

.task-status-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(420px, calc(100vw - 32px));
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(215, 223, 239, 0.9);
  box-shadow: 0 24px 50px rgba(20, 33, 61, 0.16);
  z-index: 900;
}

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

.task-status-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-status-open {
  border: none;
  background: #edf2fb;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

.task-status-list {
  display: grid;
  gap: 10px;
}

.task-status-widget.is-collapsed {
  width: min(320px, calc(100vw - 32px));
}

.task-status-widget.is-collapsed .task-status-head {
  margin-bottom: 0;
}

.task-status-widget.is-collapsed .task-status-list {
  display: none;
}

.task-widget-card,
.task-view-card {
  border: 1px solid #dce5f2;
  border-radius: 16px;
  padding: 12px;
  background: #f8fbff;
}

.task-widget-top,
.task-view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.task-widget-meta,
.task-view-message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.task-widget-main {
  min-width: 0;
  flex: 1;
}

.task-widget-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.task-card-action {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: #fee4e2;
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transition: 0.2s ease;
}

.task-card-action:hover {
  background: #fecdc9;
}

.task-card-action:focus-visible {
  outline: 2px solid rgba(180, 35, 24, 0.3);
  outline-offset: 2px;
}

.task-view-list {
  display: grid;
  gap: 12px;
}

.task-view-log {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #d6deeb;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.small {
  font-size: 12px;
}

.task-detail-modal {
  width: min(520px, calc(100vw - 32px));
  max-height: min(72vh, 760px);
  position: fixed;
  inset: auto 24px 118px auto;
  margin: 0;
  border: 1px solid rgba(215, 223, 239, 0.9);
  border-radius: 22px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 28px 56px rgba(20, 33, 61, 0.22);
  overflow: auto;
  z-index: 980;
}

.task-detail-modal::backdrop {
  background: rgba(16, 35, 61, 0.16);
}

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

.task-detail-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.task-detail-text {
  color: var(--muted);
  line-height: 1.6;
}

.upload-agent-page {
  min-height: 100vh;
  padding: 24px;
}

.upload-agent-card {
  max-width: 760px;
  margin: 0 auto;
}

.upload-agent-status {
  margin-bottom: 16px;
}

.upload-agent-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.upload-agent-text {
  color: var(--muted);
  line-height: 1.7;
}

code { font-family: Consolas, Monaco, monospace; }

@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-card .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
  .ai-channel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; position: static; min-height: auto; }
  .content { padding: 18px; }
  .filters, .stats-grid { grid-template-columns: 1fr; }
  .filter-card .filters { grid-template-columns: 1fr; }
  .batch-filter,
  .filters .filter-actions { grid-column: auto; }
  .mini-form { grid-template-columns: 1fr; }
  .history-filter { align-items: stretch; }
  .pagination-wrap { align-items: stretch; }
  .page-jump { width: 100%; }
  .task-detail-modal {
    inset: auto 16px 102px 16px;
    width: auto;
  }
}
