:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --text: #16181d;
  --muted: #69707d;
  --border: #dce0e6;
  --border-strong: #c6cbd3;
  --primary: #1769e0;
  --primary-hover: #0e55bd;
  --green: #18794e;
  --green-bg: #e9f7ef;
  --amber: #946200;
  --amber-bg: #fff5d6;
  --red: #c52b35;
  --red-bg: #fff0f1;
  --blue-bg: #eaf2ff;
  --shadow: 0 12px 36px rgba(22, 24, 29, 0.14);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  font-size: 14px;
}

button, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px 16px;
  background: #202329;
  color: #f7f8fa;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #30343c;
}

.brand {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 18px;
  border-bottom: 1px solid #383c44;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #f4c95d;
  color: #1c1d20;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { color: #9fa6b2; font-size: 12px; margin-top: 3px; }

.nav-tabs {
  display: grid;
  gap: 4px;
  padding-top: 18px;
}

.nav-tab {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #b7bdc8;
  text-align: left;
}

.nav-tab:hover { background: #2b2f36; color: #ffffff; }
.nav-tab.active { background: #343942; color: #ffffff; }
.nav-tab svg { width: 18px; height: 18px; }

.connection-state {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9fa6b2;
  font-size: 12px;
  padding: 10px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ecf8e; }
.status-dot.offline { background: #e45b64; }

.main-content {
  width: 100%;
  min-width: 0;
  padding: 26px 32px 48px;
}

.page-header {
  min-height: 62px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }

.header-actions, .modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.worker-control {
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}
.worker-control svg { width: 15px; height: 15px; }
.worker-control input {
  width: 38px;
  min-height: 25px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--text);
  text-align: center;
}
.worker-control input:focus { outline: 2px solid rgba(24, 111, 214, 0.18); border-color: #94b9e8; }
.worker-interval { color: var(--muted); font-size: 12px; white-space: nowrap; }

.button, .icon-button {
  border-radius: 6px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 650;
  white-space: nowrap;
}

.button { height: 36px; padding: 0 13px; }
.button.compact { height: 34px; padding: 0 11px; }
.button svg { width: 16px; height: 16px; }
.button.primary { color: #ffffff; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button.secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.button.secondary:hover { background: var(--surface-muted); }
.button.danger { color: var(--red); background: var(--surface); border-color: #e6b7bb; }
.button.danger:hover { background: var(--red-bg); border-color: #dc949a; }
.button:disabled { opacity: 0.48; cursor: not-allowed; }

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border-color: var(--border);
}

.icon-button:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-muted); }
.icon-button.danger:hover { color: var(--red); border-color: #efb9bd; background: var(--red-bg); }
.icon-button svg { width: 16px; height: 16px; }
.icon-button.danger { width: 40px; height: 40px; }

.metrics {
  margin: 18px 0 30px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.metric {
  min-height: 78px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--border);
}

.metric:first-child { padding-left: 0; }
.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { margin-top: 4px; font-size: 25px; line-height: 1; }

.view { display: none; }
.view.active { display: block; }

.section-toolbar {
  min-height: 44px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-count { display: flex; align-items: baseline; gap: 7px; color: var(--muted); }
.section-count strong { color: var(--text); font-size: 18px; }
.resource-summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.selection-count { color: var(--muted); font-size: 12px; }
.resource-filter { margin-left: 4px; }
.resource-search {
  width: 210px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.resource-search:focus-within { border-color: #94b9e8; box-shadow: 0 0 0 2px rgba(24, 111, 214, 0.1); }
.resource-search svg { width: 15px; height: 15px; color: var(--muted); flex: 0 0 auto; }
.resource-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.resource-search input::placeholder { color: var(--muted); }
.resource-filter-select {
  min-height: 36px;
  margin-left: 4px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.resource-filter-select svg { width: 15px; height: 15px; color: var(--muted); }
.resource-filter-select select {
  min-width: 104px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.bulk-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.segmented.full { width: 100%; grid-template-columns: repeat(3, 1fr); margin: 18px 0; }
.segmented button {
  min-height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(22, 24, 29, 0.1); }
.segmented svg { width: 15px; height: 15px; }

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

table { width: 100%; border-collapse: collapse; min-width: 760px; }
.resource-table { min-width: 1050px; table-layout: fixed; }
.emails-table { min-width: 1260px; }
.tasks-table { min-width: 1220px; }
.proxies-table { min-width: 760px; }
.resource-table td { overflow: hidden; }
.tasks-table th:nth-child(2) { width: 125px; }
.tasks-table th:nth-child(3) { width: 230px; }
.tasks-table th:nth-child(4) { width: 150px; }
.tasks-table th:nth-child(5) { width: 110px; }
.tasks-table th:nth-child(6) { width: auto; }
.tasks-table th:nth-child(7) { width: 150px; }
.tasks-table th:nth-child(8) { width: 190px; }
.emails-table th:nth-child(2) { width: 230px; }
.emails-table th:nth-child(3) { width: 180px; }
.emails-table th:nth-child(4) { width: 72px; }
.emails-table th:nth-child(5) { width: 110px; }
.emails-table th:nth-child(6) { width: 90px; }
.emails-table th:nth-child(7) { width: 120px; }
.emails-table th:nth-child(8) { width: auto; }
.emails-table th:nth-child(9) { width: 300px; }
.phones-table th:nth-child(2) { width: 200px; }
.phones-table th:nth-child(3) { width: 180px; }
.phones-table th:nth-child(4) { width: 76px; }
.phones-table th:nth-child(5) { width: 140px; }
.phones-table th:nth-child(6) { width: auto; }
.phones-table th:nth-child(7) { width: 116px; }
.proxies-table th:nth-child(1) { width: 44px; }
.proxies-table th:nth-child(2) { width: 80px; }
.proxies-table th:nth-child(3) { width: auto; }
.proxies-table th:nth-child(4), .proxies-table th:nth-child(5) { width: 120px; }
.proxies-table th:nth-child(6) { width: 104px; }
th, td { height: 50px; padding: 0 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { height: 40px; background: #fafbfc; color: var(--muted); font-size: 12px; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
tbody tr.selected { background: #f1f6fd; }
td { color: #30343b; }
.select-column { width: 44px; padding-right: 0; text-align: center; }
.select-column input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); vertical-align: middle; }
.actions-column { width: 150px; text-align: right; }
.table-actions { display: flex; justify-content: flex-end; gap: 6px; }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.cell-primary { display: block; color: var(--text); font-weight: 650; }
.cell-secondary { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.resource-identity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resource-reason { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tasks-table td { height: 50px; white-space: nowrap; }
.task-failure-reason { display: block; max-width: 100%; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }

.badge {
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.neutral { color: #616874; background: #eef0f3; }
.badge.info { color: #155cb9; background: var(--blue-bg); }
.badge.success { color: var(--green); background: var(--green-bg); }
.badge.warning { color: var(--amber); background: var(--amber-bg); }
.badge.danger { color: var(--red); background: var(--red-bg); }

.empty-state {
  min-height: 220px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--muted);
}

.empty-state.visible { display: flex; }
.empty-state svg { width: 26px; height: 26px; }

.resource-pagination {
  min-height: 42px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.resource-pagination[hidden] { display: none; }
.resource-pagination .icon-button { width: 34px; height: 34px; }

.modal {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal::backdrop { background: rgba(20, 22, 27, 0.52); }
.modal-shell { padding: 22px; background: var(--surface); overflow: auto; max-height: calc(100vh - 40px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.field-label { display: block; margin-bottom: 7px; color: #3b4049; font-weight: 650; }
.import-file-picker { min-height: 36px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.import-file-picker[hidden] { display: none; }
.import-file-name { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
textarea {
  width: 100%;
  min-height: 196px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  background: #fbfcfd;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

textarea:focus { outline: 2px solid rgba(23, 105, 224, 0.18); border-color: var(--primary); }
.modal-actions { justify-content: flex-end; margin-top: 20px; }
.preview-summary { margin-top: 12px; padding: 10px 12px; background: var(--surface-muted); border-radius: 6px; }
.preview-list { max-height: 180px; margin-top: 8px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.preview-row { min-height: 38px; padding: 8px 10px; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); }
.preview-row:last-child { border-bottom: 0; }
.preview-row.invalid { color: var(--red); background: var(--red-bg); }

.task-summary { margin: 18px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.task-summary > div { min-height: 64px; padding: 10px; background: var(--surface); }
.task-summary span, .task-summary strong { display: block; }
.task-summary span { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.task-summary strong { overflow-wrap: anywhere; }

.timeline { border-top: 1px solid var(--border); }
.timeline-item { min-height: 54px; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline-item.error .timeline-dot { background: var(--red); }
.timeline-item.warning .timeline-dot { background: #d28a00; }
.timeline-time { color: var(--muted); font-size: 12px; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 380px; padding: 11px 13px; color: #ffffff; background: #25282e; border-radius: 6px; box-shadow: var(--shadow); }
.toast.error { background: #a9252e; }

@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 10px 12px; }
  .brand { min-height: 42px; padding: 0 2px 10px; }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .nav-tabs { padding-top: 10px; grid-template-columns: repeat(4, minmax(76px, 1fr)); overflow-x: auto; }
  .nav-tab { justify-content: center; padding: 0 9px; }
  .connection-state { display: none; }
  .main-content { padding: 20px 16px 36px; }
  .page-header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--border); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(3), .metric:nth-child(4) { border-bottom: 0; }
  .metric:nth-child(3) { padding-left: 0; }
  .task-summary { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .brand span { display: none; }
  .nav-tabs { grid-template-columns: repeat(5, minmax(58px, 1fr)); }
  .nav-tab { flex-direction: column; gap: 2px; height: 44px; font-size: 11px; }
  .nav-tab svg { width: 16px; height: 16px; }
  .page-header { display: block; }
  .header-actions { margin-top: 14px; justify-content: flex-start; }
  .header-actions .button { flex: 1; }
  .worker-control { flex: 1; justify-content: center; }
  .worker-interval { width: 100%; order: 3; }
  .section-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .resource-summary { width: 100%; justify-content: space-between; }
  .resource-search { width: 100%; order: 3; }
  .resource-filter { width: 100%; margin-left: 0; order: 4; }
  .resource-filter-select { margin-left: 0; order: 4; }
  #emailFilter { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #emailFilter button { padding: 0 3px; font-size: 11px; }
  #proxyFilter { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  #proxyFilter button { padding: 0 6px; font-size: 12px; }
  .bulk-actions { width: 100%; justify-content: flex-start; }
  .segmented { max-width: 100%; overflow-x: auto; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-actions .button:last-child { grid-column: 1 / -1; }
  .preview-row { grid-template-columns: 34px minmax(0, 1fr); }
  .preview-row > :last-child { grid-column: 2; }
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
}
